/* WARNING: Heritage AFTER dead removal. Example location: r0x0041f090 : 0x00407478 */
/* WARNING: Restarted to delay deadcode elimination for space: ram */

undefined4 state_process_packet(void)

{
  bool bVar1;
  int iVar2;
  undefined4 uVar3;
  int *piVar4;
  int *piVar5;
  
  DAT_0042af54 = 0;
  DAT_0042af5c = 0;
  for (piVar4 = &g_sessions;
      ((((*piVar4 == 0 || (*(char *)((int)piVar4 + 0xe) != *(char *)(g_base_hdr + 10))) ||
        (*(char *)((int)piVar4 + 0xf) != *(char *)(g_base_hdr + 0xb))) ||
       (((char)piVar4[4] != *(char *)(g_base_hdr + 0xc) ||
        (*(char *)((int)piVar4 + 0x11) != *(char *)(g_base_hdr + 0xd))))) ||
      ((*(char *)((int)piVar4 + 0x12) != *(char *)(g_base_hdr + 0xe) ||
       (*(char *)((int)piVar4 + 0x13) != *(char *)(g_base_hdr + 0xf))))); piVar4 = piVar4 + 10) {
    if (piVar4 == (int *)&DAT_0042ce30) goto LAB_00407378;
  }
  if (piVar4 != (int *)0x0) goto LAB_004074b4;
LAB_00407378:
  piVar5 = (int *)0x0;
  if (g_opcode == 0) {
    piVar5 = &g_sessions;
    do {
      if (*piVar5 == 0) {
        *piVar5 = 1;
        piVar5[2] = 4;
        *(undefined2 *)(piVar5 + 3) = 0;
        *(undefined2 *)((int)piVar5 + 0xe) = 0;
        *(undefined2 *)(piVar5 + 4) = 0;
        *(undefined2 *)((int)piVar5 + 0x12) = 0;
        piVar5[5] = 0;
        *(undefined2 *)(piVar5 + 6) = 0;
        *(undefined1 *)(piVar5 + 8) = 4;
        piVar5[7] = 1;
        piVar5[9] = 0;
        iVar2 = g_base_hdr;
        if (piVar5 != (int *)0x0) {
          DAT_0042af54 = 1;
          *(undefined2 *)(piVar5 + 3) = g_sequencenum;
          memcpy((void *)((int)piVar5 + 0xe),(void *)(iVar2 + 10),6)   //possible issue identified - semgrep
          memcpy(piVar5 + 5,(void *)(g_ethernet_hdr + 6),6)   //possible issue identified - semgrep
          *(undefined1 *)(piVar5 + 8) = *(undefined1 *)(iVar2 + 1);
          goto LAB_00407470;
        }
        break;
      }
      bVar1 = piVar5 != (int *)&DAT_0042ce30;
      piVar5 = piVar5 + 10;
    } while (bVar1);
    warn("state_process_packet: no room to create new session. Packet dropped.\n");
    uVar3 = 0xffffffff;
  }
  else {
LAB_00407470:
    piVar4 = piVar5;
    if ((g_opcode == 4) &&
       ((g_topo_session == (int *)0x0 || (piVar4 = g_topo_session, *g_topo_session == 0)))) {
      piVar4 = piVar5;
    }
LAB_004074b4:
    DAT_0042af50 = piVar4;
    iVar2 = smS_process_event(&g_this_event);
    if ((iVar2 != 2) && (iVar2 = smE_process_event(&g_this_event), iVar2 != 2)) {
      smT_process_event(&g_this_event);
    }
    uVar3 = 0;
    DAT_0042af54 = 0;
  }
  return uVar3;
}