void * create_dynamic_hostconf(undefined4 param_1,undefined4 *param_2)

{
  int *piVar1;
  void *__s;
  char *pcVar2;
  undefined4 uVar3;
  int iVar4;
  int *piVar5;
  int iVar6;
  int *__ptr;
  
  if (DAT_004388c0 == 0) {
    if (DAT_0043cd94 < 0x400) goto LAB_00412efc;
    dprintf(7,"create_dynamic_hostconf","reached to the max count (count=%lu)");
    piVar5 = *(int **)DAT_0043cd90[1];
    if ((piVar5 == (int *)0x0) || (__ptr = piVar5, *(int *)(piVar5[2] + 0x30) == 0)) {
LAB_00412d4c:
      iVar4 = piVar5[2];
      __ptr = piVar5;
    }
    else {
      do {
        __ptr = (int *)**(undefined4 **)(__ptr[1] + 4);
        if (__ptr == (int *)0x0) goto LAB_00412d4c;
        iVar4 = __ptr[2];
      } while (*(int *)(iVar4 + 0x30) != 0);
    }
    iVar6 = *__ptr;
    if (iVar6 == 0) {
      DAT_0043cd90 = (int *)__ptr[1];
    }
    else {
      *(int *)(iVar6 + 4) = __ptr[1];
    }
    DAT_0043cd94 = DAT_0043cd94 - 1;
    *(int *)__ptr[1] = iVar6;
    FUN_00412b00(iVar4);
  }
  else {
    DAT_0043cd94 = 0;
    DAT_0043cd8c = (int *)0x0;
    DAT_0043cd90 = (int *)&DAT_0043cd8c;
    DAT_004388c0 = 0;
LAB_00412efc:
    __ptr = (int *)malloc(0xc)   //possible issue identified - semgrep
    if (__ptr == (int *)0x0) {
      dprintf(3,"create_dynamic_hostconf","memory allocation failed");
      return (void *)0x0;
    }
  }
  *__ptr = 0;
  __ptr[1] = 0;
  __ptr[2] = 0;
  __s = malloc(0x40)   //possible issue identified - semgrep
  if (__s == (void *)0x0) {
    dprintf(3,"create_dynamic_hostconf","memory allocation failed");
    goto LAB_00412f6c;
  }
  memset(__s,0,0x40)   //possible issue identified - semgrep
  *(int *)((int)__s + 0x14) = (int)__s + 0x10;
  *(int *)((int)__s + 0x20) = (int)__s + 0x1c;
  *(undefined4 *)((int)__s + 0x10) = 0;
  *(undefined4 *)((int)__s + 0x1c) = 0;
  pcVar2 = (char *)duidstr(param_1);
  if (pcVar2 == (char *)0x0) {
    pcVar2 = "???";
  }
  pcVar2 = strdup(pcVar2);
  *(char **)((int)__s + 4) = pcVar2;
  if (pcVar2 == (char *)0x0) {
LAB_00412f40:
    dprintf(3,"create_dynamic_hostconf","memory allocation failed");
  }
  else {
    iVar4 = duidcpy((int)__s + 8,param_1);
    if (iVar4 == 0) {
      if ((char *)*param_2 == (char *)0x0) {
LAB_00412e68:
        piVar5 = DAT_0043cd8c;
        uVar3 = param_2[2];
        *(undefined4 *)((int)__s + 0x28) = param_2[1];
        *(undefined4 *)((int)__s + 0x2c) = uVar3;
        __ptr[2] = (int)__s;
        *__ptr = (int)piVar5;
        piVar1 = __ptr;
        if (piVar5 != (int *)0x0) {
          DAT_0043cd8c[1] = (int)__ptr;
          piVar1 = DAT_0043cd90;
        }
        DAT_0043cd90 = piVar1;
        DAT_0043cd94 = DAT_0043cd94 + 1;
        uVar3 = *(undefined4 *)((int)__s + 4);
        DAT_0043cd8c = __ptr;
        __ptr[1] = (int)&DAT_0043cd8c;
        dprintf(7,"create_dynamic_hostconf","created host_conf (name=%s)",uVar3);
        return __s;
      }
      pcVar2 = strdup((char *)*param_2);
      *(char **)((int)__s + 0x24) = pcVar2;
      if (pcVar2 != (char *)0x0) goto LAB_00412e68;
      goto LAB_00412f40;
    }
  }
  FUN_00412b00(__s);
LAB_00412f6c:
  free(__ptr);
  return (void *)0x0;
}