undefined4 NEAP_ListenAdapter(uint *param_1,undefined4 param_2,code *param_3,undefined4 param_4)

{
  char cVar1;
  undefined1 uVar2;
  int iVar3;
  uint uVar4;
  undefined4 uVar5;
  uint uVar6;
  char *pcVar7;
  __fd_mask *p_Var8;
  __fd_mask *p_Var9;
  socklen_t local_1098;
  undefined1 auStack_1094 [16];
  undefined1 auStack_1084 [16];
  sockaddr sStack_1074;
  fd_set local_1064;
  uint auStack_fe4 [3];
  undefined1 auStack_fd8 [16];
  undefined1 auStack_fc8 [3976];
  undefined1 *local_40;
  undefined1 *local_3c;
  fd_set *local_38;
  sockaddr *local_34;
  socklen_t *local_30;
  
  p_Var9 = local_1064.fds_bits;
  if (param_3 == (code *)0x0) {
    return 0;
  }
  do {
    p_Var8 = p_Var9;
    *p_Var8 = 0;
    p_Var9 = p_Var8 + 1;
    local_30 = &local_1098;
  } while ((uint *)p_Var9 != auStack_fe4);
  uVar6 = *param_1 >> 5;
  local_1064.fds_bits[uVar6] = local_1064.fds_bits[uVar6] | 1 << (*param_1 & 0x1f);
  local_1098 = 0x10;
  local_3c = auStack_fc8;
  local_40 = auStack_fd8;
  local_38 = &local_1064;
  local_34 = &sStack_1074;
LAB_00403974:
  do {
    do {
      do {
        iVar3 = select(*param_1 + 1,local_38,(fd_set *)0x0,(fd_set *)0x0,(timeval *)0x0);
      } while (iVar3 < 1);
      uVar6 = recvfrom(*param_1,auStack_fe4,4000,0,local_34,local_30)   //possible issue identified - semgrep
    } while (((((int)uVar6 < 0) ||
              (uVar4 = *p_Var9,
              (uVar4 << 0x18 | uVar4 >> 0x18 | (uVar4 & 0xff0000) >> 8 | (uVar4 & 0xff00) << 8) !=
              0x92b1338)) || (*(char *)((int)p_Var8 + 0x26) != '\x02')) ||
            (((*(ushort *)((int)p_Var8 + 10) & 0xff) << 8 |
             (uint)(*(ushort *)((int)p_Var8 + 10) >> 8)) != uVar6));
    cVar1 = (char)p_Var8[2]   //possible issue identified - semgrep
    if ((cVar1 != '\x03') && (cVar1 != '\x05')) goto LAB_00403a7c;
    iVar3 = memcmp(local_3c,param_1 + 4,6);
  } while ((iVar3 != 0) ||
          (((cVar1 == '\x03' || (cVar1 == '\x05')) && ((*(byte *)((int)p_Var8 + 0xe) & 0x70) == 0)))
          );
  goto LAB_00403ab0;
LAB_00403a7c:
  if (cVar1 == '\x01') {
LAB_00403ab0:
    if ((*(byte *)((int)p_Var8 + 0xe) & 0x70) == 0x10) {
      memcpy(auStack_1084,local_40,0x10)   //possible issue identified - semgrep
      memset(local_40,0,0x10)   //possible issue identified - semgrep
      pcVar7 = (char *)param_1[6];
      if ((pcVar7 == (char *)0x0) || (uVar4 = param_1[7], (int)uVar4 < 1)) {
        pcVar7 = "";
        uVar4 = 0;
      }
      hmac_md5(auStack_fe4,uVar6,pcVar7,uVar4,auStack_1094);
      iVar3 = memcmp(auStack_1094,auStack_1084,0x10);
      if (iVar3 != 0) goto LAB_00403974;
    }
    uVar2 = *(undefined1 *)((int)p_Var8 + 0x26);
    *(ushort *)(param_1 + 1) =
         sStack_1074.sa_data._0_2_ << 8 | (ushort)sStack_1074.sa_data._0_2_ >> 8;
    uVar5 = FUN_00402c14(uVar2,0);
    iVar3 = FUN_00403270(uVar5,auStack_fe4,uVar6);
    if (iVar3 == 0) {
      (*param_3)(param_1,param_4,(char)p_Var8[2],uVar5);
    }
    FUN_00402aa8(uVar5);
  }
  goto LAB_00403974;
}