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

undefined4 login_main(int param_1,undefined4 *param_2)

{
  char cVar1;
  int iVar2;
  char *pcVar3;
  int iVar4;
  uint uVar5;
  size_t sVar6;
  char *pcVar7;
  int iVar8;
  undefined4 uVar9;
  undefined1 local_180 [4];
  char acStack_17c [80];
  char local_12c [80];
  char local_dc [80];
  char local_8c [84];
  char *local_38;
  char *local_34;
  char *local_30;
  
  uVar9 = *param_2;
  memset(acStack_17c,0,0x50)   //possible issue identified - semgrep
  memset(local_12c,0,0x50)   //possible issue identified - semgrep
  memset(local_dc,0,0x50)   //possible issue identified - semgrep
  memset(local_8c,0,0x50)   //possible issue identified - semgrep
  if (param_1 < 3) {
LAB_004040a4:
    FUN_00403e90(uVar9);
LAB_00404500:
    uVar9 = 0;
  }
  else {
    strncpy(acStack_17c,(char *)param_2[1],0x50)   //possible issue identified - semgrep
    strncpy(local_12c,(char *)param_2[2],0x50)   //possible issue identified - semgrep
    if (param_1 != 3) {
      local_34 = acStack_17c;
      local_30 = local_12c;
      while (iVar2 = getopt(param_1 + -2,(char **)(param_2 + 2),"l:t:h:c:"), iVar2 != -1) {   //possible issue identified - semgrep
        if (iVar2 == 0x6c) {
          PTR_s__bin_sh_00422130 = _optarg;
        }
        else if (iVar2 == 0x74) {
          DAT_00422120 = atoi(_optarg);
          if ((int)DAT_00422120 < 0) {
            DAT_00422120 = 0x3c;
          }
        }
        else {
          if (iVar2 != 99) goto LAB_004040a4;
          xmldbc_get_wb(0,0,"/sys/user:1/name",local_34,0x4f);
          xmldbc_get_wb(0,0,"/sys/user:1/password",local_30,0x4f);
        }
      }
    }
    iVar2 = access(PTR_s__bin_sh_00422130,1)   //possible issue identified - semgrep
    if (iVar2 < 0) {
      printf("login shell \'%s\' unavailable.\n",PTR_s__bin_sh_00422130);
      uVar9 = 0xffffffff;
    }
    else {
      signal(0xe,FUN_004045b8)   //possible issue identified - semgrep
      iVar2 = 0;
      alarm(DAT_00422120);
      local_38 = acStack_17c;
      do {
        iVar8 = 0;
        if (local_dc[0] == '\0') {
          local_180[0] = 0;
          while( true ) {
            printf("login: ");
            pcVar3 = fgets(local_dc,0x4f,_stdin)   //possible issue identified - semgrep
            if (pcVar3 == (char *)0x0) {
              return 0xffffffff;
            }
            iVar4 = fileno(_stdin);
            uVar5 = fcntl(iVar4,3);
            iVar4 = fileno(_stdin);
            fcntl(iVar4,4,uVar5 | 0x80);
            do {
              sVar6 = fread(local_180,1,1,_stdin)   //possible issue identified - semgrep
            } while (sVar6 != 0);
            iVar4 = fileno(_stdin);
            fcntl(iVar4,4,uVar5 & 0xffffff7f);
            pcVar7 = strchr(local_dc,10);
            pcVar3 = local_dc;
            if (pcVar7 == (char *)0x0) goto LAB_00404584;
            do {
              cVar1 = *pcVar3;
              pcVar7 = pcVar3;
              pcVar3 = pcVar3 + 1;
            } while ((*(ushort *)(___ctype_b + cVar1 * 2) & 0x20) != 0);
            do {
              pcVar3 = pcVar7;
              pcVar7 = pcVar3 + 1;
            } while ((*(ushort *)(___ctype_b + *pcVar3 * 2) & 0x80) != 0);
            *pcVar3 = '\0';
            iVar8 = iVar8 + 1;
            if (local_dc[0] != '\0') break;
            if (iVar8 == 10) {
              return 0xffffffff;
            }
          }
        }
        iVar8 = strcmp(local_38,local_dc);
        if (iVar8 == 0) {
          printf("Password: ");
          pcVar3 = fgets(local_8c,0x4f,_stdin)   //possible issue identified - semgrep
          if (pcVar3 != (char *)0x0) {
            iVar8 = fileno(_stdin);
            uVar5 = fcntl(iVar8,3);
            iVar8 = fileno(_stdin);
            fcntl(iVar8,4,uVar5 | 0x80);
            do {
              sVar6 = fread(local_180,1,1,_stdin)   //possible issue identified - semgrep
            } while (sVar6 != 0);
            pcVar3 = local_8c;
            iVar8 = fileno(_stdin);
            fcntl(iVar8,4,uVar5 & 0xffffff7f);
            pcVar7 = strchr(pcVar3,10);
            if (pcVar7 != (char *)0x0) {
              do {
                cVar1 = *pcVar3;
                pcVar7 = pcVar3;
                pcVar3 = pcVar3 + 1;
              } while ((*(ushort *)(___ctype_b + cVar1 * 2) & 0x20) != 0);
              do {
                pcVar3 = pcVar7;
                pcVar7 = pcVar3 + 1;
              } while ((*(ushort *)(___ctype_b + *pcVar3 * 2) & 0x80) != 0);
              *pcVar3 = '\0';
            }
          }
          iVar8 = strcmp(local_12c,local_8c);
          if ((iVar8 == 0) ||
             (((local_12c[0] == '\0' && (sVar6 = strlen(local_8c), sVar6 == 1)) &&
              (local_8c[0] == '\n')))) {
            alarm(0);
            system(PTR_s__bin_sh_00422130)   //possible issue identified - semgrep
            goto LAB_00404500;
          }
        }
        sleep(3);
        printf("Login incorrect");
        iVar2 = iVar2 + 1;
        local_dc[0] = '\0';
        if (iVar2 == 3) {
          printf(" for %d times",3);
        }
        putchar(10);
      } while (iVar2 != 3);
LAB_00404584:
      uVar9 = 0xffffffff;
    }
  }
  return uVar9;
}