void FUN_00403168(int *param_1,int *param_2)

{
  ushort uVar1;
  ushort uVar2;
  bool bVar3;
  undefined2 uVar4;
  undefined1 *__s;
  int iVar5;
  uint uVar6;
  uint uVar7;
  int *piVar8;
  int iVar9;
  undefined1 *puVar10;
  undefined1 *__s2;
  undefined1 *puVar11;
  int *__src;
  undefined4 *local_48;
  undefined4 *local_44;
  undefined4 *local_40;
  
  uVar7 = param_1[6];
  if (uVar7 < 0x38) {
    dolog(4,"MTU too small for packet while sending MLDv2 report on interface %s/%u mtu=%u!?\n",
          param_1 + 1,*param_1,uVar7);
    return;
  }
  __s = (undefined1 *)malloc(uVar7)   //possible issue identified - semgrep
  if (__s == (undefined1 *)0x0) {
    dolog(3,"Couldn\'t allocate memory for MLD2 Report packet, aborting\n");
                    /* WARNING: Subroutine does not return */
    exit(-1);
  }
  memset(__s,0,param_1[6]);
  *__s = 0x60;
  *(undefined2 *)(__s + 4) = 0x1000;
  __s[6] = 0;
  __s[7] = 1;
  memcpy(__s + 8,param_1 + 0xd,0x10)   //possible issue identified - semgrep
  iVar9 = g_conf;
  __s[0x18] = 0xff;
  __s[0x27] = 0x16;
  __s[0x28] = 0x3a;
  __s[0x2a] = 5;
  __s[0x2b] = 2;
  __s[0x19] = 2;
  __s[0x2e] = 1;
  __s[0x30] = 0x8f;
  __s[0x29] = 0;
  __s[0x2f] = 0;
  local_40 = (undefined4 *)**(undefined4 **)(iVar9 + 0xc);
  *(undefined2 *)(__s + 0x2c) = 0;
  *(undefined2 *)(__s + 0x36) = 0;
  puVar10 = (undefined1 *)0x0;
  bVar3 = false;
  do {
    if (local_40 == (undefined4 *)0x0) {
      uVar1 = *(ushort *)(__s + 0x36);
      if (uVar1 != 0) {
        uVar2 = *(ushort *)(puVar10 + 2);
        *(ushort *)(__s + 0x36) = uVar1 << 8 | uVar1 >> 8;
        uVar7 = (uint)(puVar10 + (((uint)uVar2 * 0x10 + -0x14) - (int)__s)) & 0xffff;
        *(ushort *)(puVar10 + 2) = *(ushort *)(puVar10 + 2) << 8 | *(ushort *)(puVar10 + 2) >> 8;
        *(ushort *)(__s + 4) = (ushort)(uVar7 << 8) | (ushort)(uVar7 >> 8);
        *(undefined2 *)(__s + 0x32) = 0;
        uVar4 = FUN_004011e0(__s,0x3a,__s + 0x30,uVar7 - 8 & 0xffff);
        *(undefined2 *)(__s + 0x32) = uVar4;
        dolog(7,"Sending2 MLDv2 Report on %s/%u, ngrec=%u, length=%u sources=%u (in last grec)\n",
              param_1 + 1,*param_1,
              (*(ushort *)(__s + 0x36) & 0xff) << 8 | (uint)(*(ushort *)(__s + 0x36) >> 8),
              puVar10 + (((uint)uVar2 * 0x10 + -0x14) - (int)__s),
              (*(ushort *)(puVar10 + 2) & 0xff) << 8 | (uint)(*(ushort *)(puVar10 + 2) >> 8));
        FUN_00402b0c(0,param_1,__s,uVar7 + 0x28 & 0xffff);
        iVar9 = g_conf;
        uVar7 = *(uint *)(g_conf + 0x78) + 1;
        *(uint *)(g_conf + 0x7c) =
             (uint)(uVar7 < *(uint *)(g_conf + 0x78)) + *(int *)(g_conf + 0x7c);
        *(uint *)(iVar9 + 0x78) = uVar7;
        uVar7 = param_1[0x20] + 1;
        param_1[0x21] = (uint)(uVar7 < (uint)param_1[0x20]) + param_1[0x21];
        param_1[0x20] = uVar7;
      }
LAB_004039b0:
      (*(code *)(undefined *)0x0)(__s);
      (*(code *)(undefined *)0x0)();
      (*(code *)(undefined *)0x0)();
      (*(code *)(undefined *)0x0)();
      (*(code *)(undefined *)0x0)();
      (*(code *)(undefined *)0x0)();
      (*(code *)(undefined *)0x0)();
      (*(code *)(undefined *)0x0)();
      (*(code *)(undefined *)0x0)();
      (*(code *)(undefined *)0x0)();
      (*(code *)(undefined *)0x0)();
      (*(code *)(undefined *)0x0)();
      FUN_00401040();
      return;
    }
    __src = (int *)local_40[2];
    if ((__src != (int *)0x0) &&
       (((param_2 == (int *)0x0 ||
         ((((*param_2 == *__src && (param_2[1] == __src[1])) && (param_2[2] == __src[2])) &&
          (param_2[3] == __src[3])))) && (((undefined4 *)__src[4])[2] != 0)))) {
      __s2 = (undefined1 *)0x0;
      for (local_44 = *(undefined4 **)__src[4]; local_44 != (undefined4 *)0x0;
          local_44 = (undefined4 *)*local_44) {
        piVar8 = (int *)local_44[2];
        if ((piVar8 != (int *)0x0) && (*piVar8 != *param_1)) {
          for (local_48 = *(undefined4 **)piVar8[1]; local_48 != (undefined4 *)0x0;
              local_48 = (undefined4 *)*local_48) {
            piVar8 = (int *)local_48[2];
            if ((piVar8 == (int *)0x0) || (piVar8[4] == 2)) goto LAB_00403804;
            if (__s2 == (undefined1 *)0x0) {
              iVar9 = 0x14;
              if (puVar10 == (undefined1 *)0x0) {
                puVar11 = (undefined1 *)0x38;
              }
              else {
LAB_00403538:
                puVar11 = puVar10 + (((uint)*(ushort *)(puVar10 + 2) * 0x10 + -0x14) - (int)__s);
                iVar9 = 0;
              }
              iVar5 = 0;
              if (((!bVar3) && (iVar5 = 0x10, *piVar8 == 0)) &&
                 ((piVar8[1] == 0 && ((piVar8[2] == 0 && (piVar8[3] == 0)))))) {
                iVar5 = 0;
              }
              if ((undefined1 *)param_1[6] < puVar11 + iVar5 + 0x28 + iVar9) {
                uVar7 = (uint)puVar11 & 0xffff;
                if (puVar10 == (undefined1 *)0x0) {
                  dolog(4,
                        "No grec and MTU too small for packet while sending MLDv2 report on interface %s/%u mtu=%u!?\n"
                        ,param_1 + 1,*param_1,(undefined1 *)param_1[6]);
                  goto LAB_004039b0;
                }
                *(ushort *)(__s + 0x36) =
                     *(ushort *)(__s + 0x36) << 8 | *(ushort *)(__s + 0x36) >> 8;
                *(ushort *)(puVar10 + 2) =
                     *(ushort *)(puVar10 + 2) << 8 | *(ushort *)(puVar10 + 2) >> 8;
                *(ushort *)(__s + 4) = (ushort)(uVar7 << 8) | (ushort)(uVar7 >> 8);
                *(undefined2 *)(__s + 0x32) = 0;
                uVar4 = FUN_004011e0(__s,0x3a,__s + 0x30,uVar7 - 8 & 0xffff);
                *(undefined2 *)(__s + 0x32) = uVar4;
                dolog(7,
                      "Sending2 MLDv2 Report on %s/%u, ngrec=%u, length=%u sources=%u (in last grec)\n"
                      ,param_1 + 1,*param_1,
                      (*(ushort *)(__s + 0x36) & 0xff) << 8 | (uint)(*(ushort *)(__s + 0x36) >> 8),
                      puVar11,(*(ushort *)(puVar10 + 2) & 0xff) << 8 |
                              (uint)(*(ushort *)(puVar10 + 2) >> 8));
                FUN_00402b0c(0,param_1,__s,uVar7 + 0x28 & 0xffff);
                *(undefined2 *)(__s + 0x36) = 0;
                iVar9 = g_conf;
                uVar7 = *(uint *)(g_conf + 0x78) + 1;
                *(uint *)(g_conf + 0x7c) =
                     (uint)(uVar7 < *(uint *)(g_conf + 0x78)) + *(int *)(g_conf + 0x7c);
                *(uint *)(iVar9 + 0x78) = uVar7;
                uVar7 = param_1[0x20];
                uVar6 = uVar7 + 1;
                param_1[0x20] = uVar6;
                param_1[0x21] = (uint)(uVar6 < uVar7) + param_1[0x21];
                puVar11 = (undefined1 *)0x0;
LAB_00403714:
                *(short *)(__s + 0x36) = *(short *)(__s + 0x36) + 1;
                puVar10 = __s + 0x38;
                if (puVar11 != (undefined1 *)0x0) {
                  uVar7 = (*(ushort *)(puVar11 + 2) & 0xff) << 8 |
                          (uint)(*(ushort *)(puVar11 + 2) >> 8);
                  *(short *)(puVar11 + 2) = (short)uVar7;
                  puVar10 = puVar11 + uVar7 * 0x10 + 0x14;
                }
                memcpy(puVar10 + 4,__src,0x10)   //possible issue identified - semgrep
                *(undefined2 *)(puVar10 + 2) = 0;
                *puVar10 = 2;
                bVar3 = false;
                __s2 = (undefined1 *)0x0;
              }
              else {
                puVar11 = puVar10;
                if (__s2 == (undefined1 *)0x0) goto LAB_00403714;
              }
              if ((((*piVar8 == 0) && (piVar8[1] == 0)) && (piVar8[2] == 0)) && (piVar8[3] == 0)) {
LAB_004037c4:
                bVar3 = true;
              }
              else {
                __s2 = puVar10 + (uint)*(ushort *)(puVar10 + 2) * 0x10 + 0x14;
                *(ushort *)(puVar10 + 2) = *(ushort *)(puVar10 + 2) + 1;
                *puVar10 = 1;
                memcpy(__s2,piVar8,0x10)   //possible issue identified - semgrep
              }
            }
            else if (puVar10 == (undefined1 *)0x0) {
              dolog(4,"No grec but we do have a source!\n");
            }
            else {
              if ((((*piVar8 == 0) && (piVar8[1] == 0)) && (piVar8[2] == 0)) && (piVar8[3] == 0)) {
                *(undefined2 *)(puVar10 + 2) = 0;
                *puVar10 = 2;
                __s2 = (undefined1 *)0x0;
                goto LAB_004037c4;
              }
              uVar7 = 0;
              if (bVar3) goto LAB_00403538;
              do {
                if (*(ushort *)(puVar10 + 2) <= uVar7) goto LAB_00403538;
                __s2 = puVar10 + (uint)*(ushort *)(puVar10 + 2) * 0x100 + 0x140;
                iVar9 = memcmp(piVar8,__s2,0x10);
                if (iVar9 == 0) {
                  dolog(7,"Not adding source address as we have ANY already added\n");
                  __s2 = (undefined1 *)0x0;
                  goto LAB_00403804;
                }
                uVar7 = uVar7 + 1;
              } while (__s2 != (undefined1 *)0x0);
              __s2 = (undefined1 *)0x0;
            }
LAB_00403804:
          }
        }
      }
    }
    local_40 = (undefined4 *)*local_40;
  } while( true );
}