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

int hedwigcgi_main(void)

{
  char *pcVar1;
  FILE *pFVar2;
  undefined4 uVar3;
  int iVar4;
  int iVar5;
  char **ppcVar6;
  int iVar7;
  int iVar8;
  int iVar9;
  int iVar10;
  char acStack_4d0 [20];
  char *local_4bc [5];
  char acStack_4a8 [128];
  char acStack_428 [1024];
  
  memset(acStack_428,0,0x400)   //possible issue identified - semgrep
  memset(acStack_4a8,0,0x80)   //possible issue identified - semgrep
  memcpy(acStack_4d0,"/runtime/session",0x11)   //possible issue identified - semgrep
  pcVar1 = getenv("REQUEST_METHOD")   //possible issue identified - semgrep
  if (pcVar1 == (char *)0x0) {
    pcVar1 = "no REQUEST";
LAB_00409e88:
    iVar10 = 0;
    iVar8 = 0;
LAB_0040a324:
    iVar9 = -1;
  }
  else {
    iVar8 = strcasecmp(pcVar1,"POST");
    if (iVar8 != 0) {
      pcVar1 = "unsupported HTTP request";
      goto LAB_00409e88;
    }
    cgibin_parse_request(&LAB_0040a32c,0,0x20000);
    pFVar2 = fopen("/etc/config/image_sign","r")   //possible issue identified - semgrep
    pcVar1 = fgets(acStack_4a8,0x80,pFVar2)   //possible issue identified - semgrep
    if (pcVar1 == (char *)0x0) {
      pcVar1 = "unable to read signature!";
      goto LAB_00409e88;
    }
    fclose(pFVar2);
    cgibin_reatwhite(acStack_4a8);
    iVar8 = sobj_new();
    iVar10 = sobj_new();
    if ((iVar8 == 0) || (iVar10 == 0)) {
      pcVar1 = "unable to allocate string object";
      goto LAB_0040a324;
    }
    sess_get_uid(iVar8);
    uVar3 = sobj_get_string(iVar8);
    sprintf(acStack_428,"%s/%s/postxml","/runtime/session",uVar3)   //possible issue identified - semgrep
    xmldbc_del(0,0,acStack_428);
    pFVar2 = fopen("/var/tmp/temp.xml","w")   //possible issue identified - semgrep
    if (pFVar2 == (FILE *)0x0) {
      pcVar1 = "unable to open temp file.";
      goto LAB_0040a324;
    }
    if (DAT_00430e80 == (char *)0x0) {
      pcVar1 = "no xml data.";
      goto LAB_0040a324;
    }
    iVar9 = fileno(pFVar2);
    iVar9 = lockf(iVar9,3,0);
    if (iVar9 < 0) {
      printf("HTTP/1.1 200 OK\r\nContent-Type: text/xml\r\n\r\n<hedwig><result>BUSY</result><essage>%s</message></hedwig>"
             ,0);
      iVar9 = 0;
      goto LAB_0040a28c;
    }
    iVar4 = fileno(pFVar2);
    lockf(iVar4,1,0);
    local_4bc[1] = (char *)0x0;
    local_4bc[2] = (char *)0x0;
    local_4bc[3] = (char *)0x0;
    local_4bc[4] = (char *)0x0;
    local_4bc[0] = acStack_4a8;
    local_4bc[1] = strtok(acStack_4d0,"/")   //possible issue identified - semgrep
    ppcVar6 = local_4bc + 2;
    iVar4 = 2;
    do {
      iVar7 = iVar4;
      pcVar1 = strtok((char *)0x0,"/")   //possible issue identified - semgrep
      *ppcVar6 = pcVar1;
      ppcVar6 = ppcVar6 + 1;
      iVar4 = iVar7 + 1;
    } while (pcVar1 != (char *)0x0);
    pcVar1 = (char *)sobj_get_string(iVar8);
    local_4bc[iVar7] = pcVar1;
    fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",pFVar2);
    ppcVar6 = local_4bc;
    iVar5 = 0;
    do {
      iVar5 = iVar5 + 1;
      fprintf(pFVar2,"<%s>\n",*ppcVar6);
      ppcVar6 = ppcVar6 + 1;
    } while (iVar5 < iVar4);
    pcVar1 = strstr(DAT_00430e80,"<postxml>");
    fprintf(pFVar2,"%s\n",pcVar1);
    ppcVar6 = local_4bc + iVar7;
    do {
      iVar4 = iVar4 + -1;
      fprintf(pFVar2,"</%s>\n",*ppcVar6);
      ppcVar6 = ppcVar6 + -1;
    } while (0 < iVar4);
    fflush(pFVar2);
    xmldbc_read(0,2,"/var/tmp/temp.xml")   //possible issue identified - semgrep
    iVar4 = fileno(pFVar2);
    lockf(iVar4,0,0);
    fclose(pFVar2);
    remove("/var/tmp/temp.xml");
    uVar3 = sobj_get_string(iVar8);
    sprintf(acStack_428,"/htdocs/webinc/fatlady.php\nprefix=%s/%s","/runtime/session",uVar3)   //possible issue identified - semgrep
    xmldbc_ephp(0,0,acStack_428,_stdout);
    if (iVar9 == 0) goto LAB_0040a28c;
    pcVar1 = (char *)0x0;
  }
  printf("HTTP/1.1 200 OK\r\nContent-Type: text/xml\r\n\r\n<hedwig><result>FAILED</result><essage>%s</message></hedwig>"
         ,pcVar1);
LAB_0040a28c:
  if (DAT_00430e80 != (char *)0x0) {
    free(DAT_00430e80);
  }
  if (iVar10 != 0) {
    sobj_del(iVar10);
  }
  if (iVar8 != 0) {
    sobj_del(iVar8);
  }
  return iVar9;
}