void * FUN_0040f538(undefined4 param_1,undefined4 *param_2)

{
  int *piVar1;
  void *__s;
  char *pcVar2;
  undefined4 uVar3;
  int iVar4;
  int *piVar5;
  int iVar6;
  int *__ptr;
  
  if (DAT_0043e320 == 0) {
    if (DAT_004410c4 < 0x400) goto LAB_0040f7dc;
    dprintf(7,"create_dynamic_hostconf","reached to the max count (count=%lu)");
    piVar5 = *(int **)DAT_004410c0[1];
    if ((piVar5 == (int *)0x0) || (__ptr = piVar5, *(int *)(piVar5[2] + 0x30) == 0)) {
LAB_0040f62c:
      iVar4 = piVar5[2];
      __ptr = piVar5;
    }
    else {
      do {
        __ptr = (int *)**(undefined4 **)(__ptr[1] + 4);
        if (__ptr == (int *)0x0) goto LAB_0040f62c;
        iVar4 = __ptr[2];
      } while (*(int *)(iVar4 + 0x30) != 0);
    }
    iVar6 = *__ptr;
    if (iVar6 == 0) {
      DAT_004410c0 = (int *)__ptr[1];
    }
    else {
      *(int *)(iVar6 + 4) = __ptr[1];
    }
    DAT_004410c4 = DAT_004410c4 - 1;
    *(int *)__ptr[1] = iVar6;
    FUN_0040f3e0(iVar4);
  }
  else {
    DAT_004410c4 = 0;
    DAT_004410bc = (int *)0x0;
    DAT_004410c0 = (int *)&DAT_004410bc;
    DAT_0043e320 = 0;
LAB_0040f7dc:
    __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_0040f84c;
  }
  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_0040f820:
    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_0040f748:
        piVar5 = DAT_004410bc;
        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_004410bc[1] = (int)__ptr;
          piVar1 = DAT_004410c0;
        }
        DAT_004410c0 = piVar1;
        DAT_004410c4 = DAT_004410c4 + 1;
        uVar3 = *(undefined4 *)((int)__s + 4);
        DAT_004410bc = __ptr;
        __ptr[1] = (int)&DAT_004410bc;
        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_0040f748;
      goto LAB_0040f820;
    }
  }
  FUN_0040f3e0(__s);
LAB_0040f84c:
  free(__ptr);
  return (void *)0x0;
}