#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <sys/types.h>
#include <signal.h>


char* STR_CONGR = "Congratulations ! A right password is indeed";
char** PTR_STR_CONGR = &STR_CONGR;

char* STR_WRONG = "Wrong password ! Try again...";
char** PTR_STR_WRONG = &STR_WRONG;

char* STR_WHAT = "What I need is 1024 passwords passing the check";
char** PTR_STR_WHAT = &STR_WHAT;

char* STR_USAGE = "Usage:  <password>";
char** PTR_STR_USAGE = &STR_USAGE;

char* STR_CHALLENGE = "MSE-SRE Challenge A1 --- Enjoy !";
char** PTR_STR_CHALLENGE = &STR_CHALLENGE;

uint8_t DAT_00154450[24];

void FUN_00107c80(void);
long FUN_00122620(void* param_1,uint8_t* param_2,long param_3,char** param_4,uint8_t param_5)

uint64_t main(int param_1, char** param_2) {
  void* local_8 = FUN_00107c80;
  return FUN_00122620(&local_8, DAT_00154450, (long)param_1, param_2,0);
}

void FUN_00107c80(void) {
  uint8_t bVar1;
  uint8_t bVar2;
  uint8_t bVar3;
  undefined1 auVar4 [16];
  long lVar5;
  ulong uVar6;
  long *plVar7;
  int iVar8;
  undefined1 *puVar9;
  uint8_t *pbVar10;
  uint8_t *pbVar11;
  undefined8 uVar12;
  long lVar13;
  long *plVar14;
  undefined8 *puVar15;
  char** tmp_string;
  undefined8 uStack_e0;
  long **local_d8;
  long lStack_d0;
  undefined8 uStack_c8;
  code *local_b0;
  undefined4 local_a8;
  undefined4 uStack_a4;
  undefined4 uStack_a0;
  undefined4 uStack_9c;
  uint8_t *local_98;
  undefined8 local_90;
  undefined8 uStack_88;
  uint8_t *local_80;
  long *local_78;
  code *local_70;
  long local_68;
  undefined4 local_60;
  undefined4 uStack_5c;
  undefined4 uStack_58;
  undefined4 uStack_54;
  long local_50;
  long lStack_48;
  ulong local_40;
  ulong local_38;

  FUN_001234c0(&local_60);
                    /* try { // try from 00107ca2 to 00107cb5 has its CatchHandler @ 001082b2 */
  FUN_00123700(&local_78,&local_60);
  plVar14 = local_78;
  local_b0 = local_70;
                    /* try { // try from 00107d68 to 00107d7a has its CatchHandler @ 001082ca */
  FUN_001237e0(&tmp_string,&local_60);
  pbVar11 = (uint8_t *)0xffffffffffffffff; // 0x ff ff ff ff ff ff ff ff
  if ((uint8_t *)((long)tmp_string + 1) != (uint8_t *)0x0) {
    pbVar11 = (uint8_t *)((long)tmp_string + 1);
  }
  pbVar10 = (uint8_t *)0x4;
  if ((uint8_t *)0x4 < pbVar11) {
    pbVar10 = pbVar11;
  }
  uVar12 = 0;
  auVar4._8_8_ = 0;
  auVar4._0_8_ = pbVar10;
  uVar6 = SUB168(auVar4 * ZEXT816(0x18),0);
  if ((SUB168(auVar4 * ZEXT816(0x18),8) == 0) && (uVar6 < 0x7ffffffffffffff9)) {
    if (uVar6 == 0) {
      plVar7 = (long *)&DAT_00000008;
      pbVar10 = (uint8_t *)0x0;
    } else {
      uVar12 = 8;
      plVar7 = (long *)thunk_FUN_00127f80(uVar6,8);
      if (plVar7 == (long *)0x0) goto LAB_00108291;
    }
    *plVar7 = (long)plVar14;
    plVar7[1] = (long)local_b0;
    plVar7[2] = local_68;
    local_80 = &DAT_00000001;
    local_d8 = (long **)local_50;
    lStack_d0 = lStack_48;
    tmp_string = (undefined **)CONCAT44(uStack_5c,local_60);
    uStack_e0 = CONCAT44(uStack_54,uStack_58);
    lVar13 = 0x28;
    local_90 = pbVar10;
    uStack_88 = plVar7;

    while( true ) {
                    /* try { // try from 00107e9f to 00107eae has its CatchHandler @ 0010832a */
      pbVar10 = local_80;
      FUN_00123700(&local_a8,&tmp_string);
      pbVar11 = local_98;
      lVar5 = CONCAT44(uStack_a4,local_a8);
      if (lVar5 == -0x8000000000000000) break;
      uVar12 = CONCAT44(uStack_9c,uStack_a0);
      if (pbVar10 == local_90) {
                    /* try { // try from 00107ed4 to 00107f09 has its CatchHandler @ 0010830f */
        FUN_001237e0(&local_78,&tmp_string);
        puVar9 = (undefined1 *)((long)local_78 + 1);
        if (puVar9 == (undefined1 *)0x0) {
          puVar9 = (undefined1 *)0xffffffffffffffff;
        }
        FUN_00106090(&local_90,pbVar10,puVar9);
        plVar7 = uStack_88;
      }
      *(long *)((long)plVar7 + lVar13 + -0x10) = lVar5;
      *(undefined8 *)((long)plVar7 + lVar13 + -8) = uVar12;
      *(uint8_t **)((long)plVar7 + lVar13) = pbVar11;
      local_80 = pbVar10 + 1;
      lVar13 = lVar13 + 0x18;
    }

    if (lStack_d0 != uStack_e0) {
      uVar6 = (ulong)(lStack_d0 - uStack_e0) / 0x18;
      puVar15 = (undefined8 *)(uStack_e0 + 8);
      do {
        if (puVar15[-1] != 0) {
          thunk_FUN_00127fe0(*puVar15,puVar15[-1],1);
        }
        puVar15 = puVar15 + 3;
        uVar6 = uVar6 - 1;
      } while (uVar6 != 0);
    }
    if (local_d8 != (long **)0x0) {
      thunk_FUN_00127fe0(tmp_string,(long)local_d8 * 0x18,8);
    }
    pbVar11 = local_80;
    plVar14 = uStack_88;
    local_a8 = (undefined4)local_90;
    uStack_a4 = local_90._4_4_;
    uStack_a0 = (undefined4)uStack_88;
    uStack_9c = uStack_88._4_4_;
    local_98 = local_80;
    if (local_80 == (uint8_t *)0x2) {
      if (uStack_88[5] == 0xc) {
        local_90 = (uint8_t *)uStack_88[4];
        bVar1 = local_90[3];
        local_38 = (ulong)bVar1;
        bVar2 = local_90[5];
        local_40 = (ulong)bVar2;
        bVar3 = local_90[11];
        local_b0 = (code *)CONCAT71(local_b0._1_7_,bVar3);
        uStack_88 = (long *)12;
        iVar8 = (uint)(uint8_t)(local_90[7] ^ local_90[8] ^ local_90[9] ^ local_90[10] ^ local_90[4] ^ bVar2 ^ local_90[6] ^ local_90[2] ^ bVar1 ^ local_90[0] ^ local_90[1] ^ bVar3 ^ 0xd6) +
                (uint)(uint8_t)((local_90[7] + local_90[8] + local_90[9] + local_90[10] +
                              local_90[4] + bVar2 + local_90[6] +
                              local_90[2] + bVar1 + *local_90 + local_90[1] + bVar3) - 0x3a) * 0x73;
        if ((char)((char)iVar8 - (char)((uint)(iVar8 * 0x7f81) >> 0x17)) == -0x4b) {
          local_78 = &local_90;
          local_70 = FUN_00107a80;
          tmp_string = &PTR_STR_CONGR; // Congratulations ! A right password is indeed
          uStack_e0 = 2;
          uStack_c8 = 0;
          local_d8 = &local_78;
          lStack_d0 = 1;
                    /* try { // try from 001080f5 to 00108228 has its CatchHandler @ 001082fa */
          FUN_00124d60(&tmp_string);
        } else { // Wrong password
          tmp_string = &PTR_STR_WRONG; // Wrong password ! Try again...
          uStack_e0 = 1;
          local_d8 = (long **)&DAT_00000008;
          lStack_d0 = 0;
          uStack_c8 = 0;
          printf(&tmp_string);
        }
      } else { // Wrong password
        tmp_string = &PTR_STR_WRONG; // Wrong password ! Try again...
        uStack_e0 = 1;
        local_d8 = (long **)&DAT_00000008;
        lStack_d0 = 0;
        uStack_c8 = 0;
        printf(&tmp_string);
      }
      pbVar11 = (uint8_t *)0x2;
    } else {
      tmp_string = &PTR_STR_CHALLENGE; // MSE-SRE Challenge A1 --- Enjoy !
      uStack_e0 = 1;
      local_d8 = (long **)0x8;
      lStack_d0 = 0;
      uStack_c8 = 0;
      printf(&tmp_string);
      tmp_string = &PTR_STR_WHAT; // What I need is 1024 passwords passing the check
      uStack_e0 = 1;
      local_d8 = (long **)0x8;
      lStack_d0 = 0;
      uStack_c8 = 0;
      printf(&tmp_string);
      if (pbVar11 == (uint8_t *)0x0) {
                    /* try { // try from 0010829f to 001082af has its CatchHandler @ 001082fa */
                    /* WARNING: Subroutine does not return */
        FUN_00107435(0,0,&PTR_DAT_001544d0);
      }
      plVar14 = (long *)CONCAT44(uStack_9c,uStack_a0);
      local_70 = FUN_00107c60;
      tmp_string = &PTR_STR_USAGE; // Usage:  <password>
      uStack_e0 = 2;
      uStack_c8 = 0;
      lStack_d0 = 1;
      local_d8 = &local_78;
      local_78 = plVar14;
      printf(&tmp_string);
    }
    plVar7 = plVar14 + 1;
    do {
      if (plVar7[-1] != 0) {
        thunk_FUN_00127fe0(*plVar7,plVar7[-1],1);
      }
      plVar7 = plVar7 + 3;
      pbVar11 = pbVar11 + -1;
    } while (pbVar11 != (uint8_t *)0x0);
    if (CONCAT44(uStack_a4,local_a8) != 0) {
      thunk_FUN_00127fe0(plVar14,CONCAT44(uStack_a4,local_a8) * 0x18,8);
    }
    return;
  }
LAB_00108291:
                    /* try { // try from 00108291 to 0010829c has its CatchHandler @ 001082ca */
                    /* WARNING: Subroutine does not return */
  FUN_001071d7(uVar12,uVar6);
}
