/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

undefined4 main(int param_1,int param_2)

{
  ushort uVar1;
  uint16_t uVar2;
  int iVar3;
  __pid_t _Var4;
  undefined2 extraout_var;
  __fd_mask *p_Var5;
  uint uVar6;
  undefined2 extraout_var_00;
  undefined2 extraout_var_01;
  uint32_t uVar7;
  undefined2 extraout_var_02;
  char *pcVar8;
  uint uVar9;
  size_t sVar10;
  __pid_t local_134;
  timeval local_130;
  sockaddr local_128;
  undefined4 local_118;
  char acStack_114 [16];
  undefined *local_104;
  undefined2 local_100;
  undefined4 local_f4;
  char local_f0;
  char local_e4 [2];
  undefined2 uStack_e2;
  undefined2 local_e0;
  undefined2 local_de;
  char acStack_d4 [16];
  undefined *local_c4;
  undefined2 local_c0;
  uint local_b4 [32];
  undefined4 uStack_34;
  undefined4 local_30;
  char local_2c [4];
  
  FUN_00400ae0();
  if (param_1 == 2) {
LAB_00400c50:
    FUN_00400a8c();
  }
  else {
    if (param_1 == 3) {
      iVar3 = strcmp(*(char **)(param_2 + 4),"-i");
      if (iVar3 != 0) goto LAB_00400c50;
      pcVar8 = *(char **)(param_2 + 8);
    }
    else {
      pcVar8 = "ra0";
    }
    strcpy(&DAT_00412140,pcVar8)   //possible issue identified - semgrep
    _Var4 = fork()   //possible issue identified - semgrep
    if (_Var4 == -1) {
      perror("fork/getpid");
      return 0xffffffff;
    }
    if (_Var4 != 0) {
      return 0;
    }
    uVar2 = htons(3);
    DAT_0041205c = socket(0x11,3,CONCAT22(extraout_var,uVar2));
    if ((int)DAT_0041205c < 0) {
      perror("socket");
    }
    else {
      memset(&local_f4,0,0x20)   //possible issue identified - semgrep
      local_f0 = 'i';
      local_f4 = 0x307262;
      iVar3 = ioctl(DAT_0041205c,0x8933,&local_f4);
      if (iVar3 == 0) {
        DAT_00412f58._0_1_ = local_e4[0];
        DAT_00412f58._1_1_ = local_e4[1];
        DAT_00412f58._2_1_ = (char)uStack_e2;
        DAT_00412f58._3_1_ = uStack_e2._1_1_;
        local_128.sa_family = 0x11;
        local_128.sa_data[0] = '\0';
        local_128.sa_data[1] = '\0';
        local_128.sa_data[6] = '\0';
        local_128.sa_data[7] = '\0';
        local_128.sa_data[8] = '\0';
        local_128.sa_data[9] = '\0';
        local_128.sa_data[10] = '\0';
        local_128.sa_data[0xb] = '\0';
        local_128.sa_data[0xc] = '\0';
        local_128.sa_data[0xd] = '\0';
        local_118 = 0;
        local_128.sa_data[2] = local_e4[0];
        local_128.sa_data[3] = local_e4[1];
        local_128.sa_data[4] = (char)uStack_e2;
        local_128.sa_data[5] = uStack_e2._1_1_;
        iVar3 = bind(DAT_0041205c,&local_128,0x14);
        if (iVar3 < 0) {
          pcVar8 = "bind";
        }
        else {
          iVar3 = ioctl(DAT_0041205c,0x8927,&local_f4);
          if (iVar3 == 0) {
            DAT_00412f52 = local_e0;
            DAT_00412f54 = local_de;
            DAT_00412f50 = uStack_e2;
            iVar3 = socket(2,1,0);
            if (iVar3 < 0) {
              return 0;
            }
            memset(acStack_114,0,0x20)   //possible issue identified - semgrep
            DAT_00412164 = htons(0x80);
            local_100 = 8;
            local_104 = &DAT_0041215e;
            strncpy(acStack_114,&DAT_00412140,0x10)   //possible issue identified - semgrep
            ioctl(iVar3,0x8be8,acStack_114);
            close(iVar3);
            local_30 = 0xffffffff;
            local_130.tv_sec = 1;
            local_130.tv_usec = 0;
            local_2c[0] = -1;
            local_2c[1] = -1;
            local_2c[2] = -1;
            local_2c[3] = -1;
LAB_00401438:
            do {
              while( true ) {
                do {
                  while( true ) {
                    if (DAT_00412060 == 0) {
                      iVar3 = socket(2,1,0);
                      if (iVar3 < 0) {
                        return 0;
                      }
                      memset(acStack_114,0,0x20)   //possible issue identified - semgrep
                      DAT_00412164 = htons(0x81);
                      local_104 = &DAT_0041215e;
                      local_100 = 8;
                      strncpy(acStack_114,&DAT_00412140,0x10)   //possible issue identified - semgrep
                      ioctl(iVar3,0x8be8,acStack_114);
                      close(iVar3);
                      close(DAT_0041205c);
                      return 0;
                    }
                    p_Var5 = (__fd_mask *)local_b4;
                    do {
                      *p_Var5 = 0;
                      p_Var5 = p_Var5 + 1;
                    } while (p_Var5 != &uStack_34);
                    local_b4[DAT_0041205c >> 5] =
                         local_b4[DAT_0041205c >> 5] | 1 << (DAT_0041205c & 0x1f);
                    iVar3 = select(DAT_0041205c + 1,(fd_set *)local_b4,(fd_set *)0x0,(fd_set *)0x0,
                                   &local_130);
                    if (iVar3 < 0) {
                      return 0;
                    }
                    if (iVar3 != 0) break;
                    usleep(1000);
                  }
                  uVar6 = recvfrom(DAT_0041205c,&DAT_00412750,0x800,0,(sockaddr *)0x0,
                                   (socklen_t *)0x0)   //possible issue identified - semgrep
                } while ((((((int)uVar6 < 1) ||
                           (uVar9 = (uint)_DAT_0041275c, uVar2 = ntohs(0x2880),
                           uVar9 != CONCAT22(extraout_var_00,uVar2))) || (uVar6 < 0x1a)) ||
                         (uVar6 = (uint)_DAT_0041275c, uVar2 = htons(0x2880),
                         uVar6 != CONCAT22(extraout_var_01,uVar2))) ||
                        (((iVar3 = strncmp((char *)&DAT_00412f50,&DAT_00412750,6), iVar3 != 0 &&
                          (iVar3 = strncmp((char *)&DAT_00401870,&DAT_00412750,6), iVar3 != 0)) ||
                         ((uVar7 = ntohl(DAT_0041275e), uVar7 != 0x18142880 ||
                          (uVar2 = ntohs(_DAT_00412762), (uVar2 & 0x7fff) != 8))))));
                uVar2 = ntohs(_DAT_00412764);
                uVar6 = (uint)uVar2;
                ntohs(_DAT_00412768);
                uVar2 = ntohs(_DAT_00412766);
                uVar9 = (uint)uVar2;
                if ((uVar6 - 0x80 & 0xffff) < 2) break;
                if (0x15 < uVar6) goto LAB_004011bc;
                if (*(ushort *)(&DAT_00412030 + uVar6 * 2) == 0xffff) goto LAB_004011a4;
                if (uVar9 == *(ushort *)(&DAT_00412030 + uVar6 * 2)) goto LAB_004011bc;
              }
            } while (uVar9 != 0);
            goto LAB_004011bc;
          }
          pcVar8 = "ioctl(SIOCGIFHWADDR)(eth_sock)";
        }
      }
      else {
        pcVar8 = "ioctl(SIOCGIFINDEX)(eth_sock)";
      }
      perror(pcVar8);
      close(DAT_0041205c);
      DAT_0041205c = 0xffffffff;
    }
  }
  return 0;
LAB_004011a4:
  if (((uVar6 != 0x10) || (uVar9 == 0)) || (0x27 < uVar9)) {
LAB_004011bc:
    iVar3 = socket(2,1,0);
    if (-1 < iVar3) {
      memset(acStack_d4,0,0x20)   //possible issue identified - semgrep
      memset(&DAT_00412150,0,0x600)   //possible issue identified - semgrep
      if (uVar6 == 0x81) {
        sVar10 = uVar9 + 0x10   //possible issue identified - semgrep
        local_134 = getpid();
        memcpy(&DAT_0041276a,&local_134,4)   //possible issue identified - semgrep
      }
      else {
        sVar10 = uVar9 + 0xc   //possible issue identified - semgrep
      }
      memcpy(&DAT_0041215e,&DAT_0041275e,sVar10)   //possible issue identified - semgrep
      local_c0 = (undefined2)sVar10;
      local_c4 = &DAT_0041215e;
      strncpy(acStack_d4,&DAT_00412140,0x10)   //possible issue identified - semgrep
      ioctl(iVar3,0x8be8,acStack_d4);
      close(iVar3);
      uVar1 = _DAT_00412162;
      uVar2 = htons(0x8000);
      _DAT_00412162 = uVar1 | uVar2;
      DAT_00412154 = 0xffff;
      DAT_00412150 = local_30;
      memcpy(&DAT_00412156,&DAT_00412f50,6)   //possible issue identified - semgrep
      uVar2 = htons(0x2880);
      DAT_0041215d = (undefined1)(uVar2 >> 8);
      DAT_0041215c = (undefined1)uVar2;
      uVar2 = ntohs(_DAT_00412166);
      sVar10 = CONCAT22(extraout_var_02,uVar2) + 0x1a   //possible issue identified - semgrep
      if (sVar10 < 0x3c) {
        sVar10 = 0x3c   //possible issue identified - semgrep
      }
      else if (0x5ea < sVar10) goto LAB_00401438;
      local_128.sa_family = 0x11;
      uVar2 = htons(0x2880);
      local_128.sa_data._0_2_ = uVar2;
      local_128.sa_data[6] = '\x01';
      local_128.sa_data[7] = '\0';
      local_128.sa_data[8] = '\x01';
      local_128.sa_data[9] = '\x06';
      local_118 = 0xffff;
      local_128.sa_data[10] = local_2c[0];
      local_128.sa_data[0xb] = local_2c[1];
      local_128.sa_data[0xc] = local_2c[2];
      local_128.sa_data[0xd] = local_2c[3];
      local_128.sa_data[2] = (char)DAT_00412f58;
      local_128.sa_data[3] = DAT_00412f58._1_1_;
      local_128.sa_data[4] = DAT_00412f58._2_1_;
      local_128.sa_data[5] = DAT_00412f58._3_1_;
      sendto(DAT_0041205c,&DAT_00412150,sVar10,0,&local_128,0x14);
    }
  }
  goto LAB_00401438;
}