#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
char *str2md5(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int strncmp(char *, char *, int);
int main(int argc, char **argv) {
  if (argc < 2) {
    printf("Hey -- gimme a code\n");
    return 2;
  }
  char doorid[512] = "";
  char buffer[256];
  char password[8] = "--------";
  strcpy(doorid, argv[1]);
  int initial = strlen(doorid);
  int i = 0;
  int flag = 0;
  char pwd = 0;
  while (pwd < 8) {
    do {
      sprintf(buffer, "%d", i++);
      strcpy(&doorid[initial], buffer);
      char *output = str2md5(doorid, strlen(doorid));
      flag = strncmp(output, "00000", 5);
      int position = output[5] - '0';
      if (!flag && position >= 0 && position < 8 && password[position] == '-') {
        password[position] = output[6];
        pwd++;
        free(output);
        break;
      }
      free(output);
    } while (1);
    printf("%d %s\n", i, password);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11bd <main+0x3d>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    138e <main+0x20e>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1080 <memset@plt>
mov    0xe4e(%rip),%rax
mov    %rax,-0x318(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1050 <strcpy@plt>
lea    -0x210(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x31c(%rbp)
movl   $0x0,-0x320(%rbp)
movl   $0x0,-0x324(%rbp)
movb   $0x0,-0x325(%rbp)
movsbl -0x325(%rbp),%eax
cmp    $0x8,%eax
jge    1387 <main+0x207>
jmp    1234 <main+0xb4>
lea    -0x310(%rbp),%rdi
mov    -0x320(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x320(%rbp)
lea    0xdc2(%rip),%rsi
call   10a0 <sprintf@plt>
movslq -0x31c(%rbp),%rax
lea    -0x210(%rbp),%rdi
add    %rax,%rdi
lea    -0x310(%rbp),%rsi
call   1050 <strcpy@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x340(%rbp)
lea    -0x210(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x340(%rbp),%rdi
mov    %eax,%esi
call   1090 <str2md5@plt>
mov    %rax,-0x330(%rbp)
mov    -0x330(%rbp),%rdi
lea    0xd66(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
mov    %eax,-0x324(%rbp)
mov    -0x330(%rbp),%rax
movsbl 0x5(%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x334(%rbp)
cmpl   $0x0,-0x324(%rbp)
jne    134c <main+0x1cc>
cmpl   $0x0,-0x334(%rbp)
jl     134c <main+0x1cc>
cmpl   $0x8,-0x334(%rbp)
jge    134c <main+0x1cc>
movslq -0x334(%rbp),%rax
movsbl -0x318(%rbp,%rax,1),%eax
ff
cmp    $0x2d,%eax
jne    134c <main+0x1cc>
mov    -0x330(%rbp),%rax
mov    0x6(%rax),%cl
movslq -0x334(%rbp),%rax
mov    %cl,-0x318(%rbp,%rax,1)
mov    -0x325(%rbp),%al
add    $0x1,%al
mov    %al,-0x325(%rbp)
mov    -0x330(%rbp),%rdi
call   1030 <free@plt>
jmp    1367 <main+0x1e7>
mov    -0x330(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%al
test   $0x1,%al
jne    1234 <main+0xb4>
jmp    1367 <main+0x1e7>
mov    -0x320(%rbp),%esi
lea    -0x318(%rbp),%rdx
lea    0xca3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    121f <main+0x9f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x318,%rsp
cmp    $0x1,%edi
jg     11bc <main+0x2c>
lea    0xe63(%rip),%rdi
call   1060 <puts@plt>
mov    $0x2,%eax
jmp    12cc <main+0x13c>
mov    %rsi,%rbx
lea    0x110(%rsp),%r14
mov    $0x200,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <memset@plt>
movabs $0x2d2d2d2d2d2d2d2d,%rax
2d 2d 2d
mov    %rax,0x8(%rsp)
mov    0x8(%rbx),%rsi
mov    %r14,%rdi
call   1050 <strcpy@plt>
mov    %r14,%rdi
call   1070 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%r12
add    $0x110,%r12
lea    0x10(%rsp),%rbx
lea    0xdf1(%rip),%r13
xor    %ebp,%ebp
movl   $0x0,0x4(%rsp)
jmp    122b <main+0x9b>
xchg   %ax,%ax
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
lea    0xdcb(%rip),%rsi
mov    %ebp,%edx
call   10b0 <sprintf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   10a0 <str2md5@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r13,%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    1220 <main+0x90>
movzbl 0x5(%r15),%eax
cmp    $0x30,%al
jl     1220 <main+0x90>
cmp    $0x37,%al
jg     1220 <main+0x90>
movzbl %al,%eax
lea    0x8(%rsp),%rcx
cmpb   $0x2d,-0x30(%rax,%rcx,1)
jne    1220 <main+0x90>
movzbl 0x6(%r15),%ecx
mov    %cl,-0x28(%rsp,%rax,1)
mov    0x4(%rsp),%eax
add    $0x1,%al
mov    %eax,0x4(%rsp)
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x1,%ebp
lea    0xd58(%rip),%rdi
mov    %ebp,%esi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1080 <printf@plt>
cmpb   $0x8,0x4(%rsp)
jne    122b <main+0x9b>
xor    %eax,%eax
add    $0x318,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Hey -- gimme a code\0A\00"
@__const.main.password = [8 x i8] c"--------"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c"00000\00"
@.str.3 = [7 x i8] c"%d %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca [256 x i8]
%8 = alloca [8 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
%13 = alloca i8*
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %3
br label %90
19: ; preds = %2
%20 = bitcast [512 x i8]* %6 to i8*
%21 = bitcast [8 x i8]* %8 to i8*
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @strcpy(i8* %22, i8* %25)
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
store i32 %28, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i8 0, i8* %12
br label %29
29: ; preds = %85, %19
%30 = load i8, i8* %12
%31 = sext i8 %30 to i32
%32 = icmp slt i32 %31, 8
br i1 %32, label %33, label %89
33: ; preds = %29
br label %34
34: ; preds = %84, %33
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
%38 = call i32 @sprintf(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %40
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%43 = call i32 @strcpy(i8* %41, i8* %42)
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%46 = call i32 @strlen(i8* %45)
%47 = call i8* @str2md5(i8* %44, i32 %46)
store i8* %47, i8** %13
%48 = load i8*, i8** %13
%49 = call i32 @strncmp(i8* %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
store i32 %49, i32* %11
%50 = load i8*, i8** %13
%51 = getelementptr inbounds i8, i8* %50, i64 5
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = sub nsw i32 %53, 48
store i32 %54, i32* %14
%55 = load i32, i32* %11
%56 = icmp ne i32 %55, 0
br i1 %56, label %81, label %57
57: ; preds = %34
%58 = load i32, i32* %14
%59 = icmp sge i32 %58, 0
br i1 %59, label %60, label %81
60: ; preds = %57
%61 = load i32, i32* %14
%62 = icmp slt i32 %61, 8
br i1 %62, label %63, label %81
63: ; preds = %60
%64 = load i32, i32* %14
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 %65
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 45
br i1 %69, label %70, label %81
70: ; preds = %63
%71 = load i8*, i8** %13
%72 = getelementptr inbounds i8, i8* %71, i64 6
%73 = load i8, i8* %72
%74 = load i32, i32* %14
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 %75
store i8 %73, i8* %76
%77 = load i8, i8* %12
%78 = add i8 %77, 1
store i8 %78, i8* %12
%79 = load i8*, i8** %13
%80 = call i32 @free(i8* %79)
br label %85
81: ; preds = %63, %60, %57, %34
%82 = load i8*, i8** %13
%83 = call i32 @free(i8* %82)
br label %84
84: ; preds = %81
br i1 true, label %34, label %85
85: ; preds = %84, %70
%86 = load i32, i32* %10
%87 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %86, i8* %87)
br label %29
89: ; preds = %29
store i32 0, i32* %3
br label %90
90: ; preds = %89, %17
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c"00000\00"
@.str.3 = [7 x i8] c"%d %s\0A\00"
@str = [20 x i8] c"Hey -- gimme a code\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = alloca [256 x i8]
%5 = alloca i64
%6 = bitcast i64* %5 to [8 x i8]*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %55
10: ; preds = %2
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%13 = bitcast i64* %5 to i8*
store i64 3255307777713450285, i64* %5
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @strcpy(i8* %11, i8* %15)
%17 = call i32 @strlen(i8* %11)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %18
br label %20
20: ; preds = %10, %46
%21 = phi i32 [ 0, %10 ], [ %25, %46 ]
%22 = phi i8 [ 0, %10 ], [ %50, %46 ]
br label %23
23: ; preds = %20, %44
%24 = phi i32 [ %25, %44 ], [ %21, %20 ]
%25 = add nsw i32 %24, 1
%26 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%27 = call i32 @strcpy(i8* %19, i8* %12)
%28 = call i32 @strlen(i8* %11)
%29 = call i8* @str2md5(i8* %11, i32 %28)
%30 = call i32 @strncmp(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%31 = getelementptr inbounds i8, i8* %29, i64 5
%32 = load i8, i8* %31
%33 = icmp eq i32 %30, 0
%34 = icmp sgt i8 %32, 47
%35 = select i1 %33, i1 %34, i1 false
%36 = icmp slt i8 %32, 56
%37 = select i1 %35, i1 %36, i1 false
br i1 %37, label %38, label %44
38: ; preds = %23
%39 = zext i8 %32 to i64
%40 = add nsw i64 %39, -48
%41 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 45
br i1 %43, label %46, label %44
44: ; preds = %23, %38
%45 = call i32 @free(i8* %29)
br label %23
46: ; preds = %38
%47 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 %40
%48 = getelementptr inbounds i8, i8* %29, i64 6
%49 = load i8, i8* %48
store i8 %49, i8* %47
%50 = add nuw nsw i8 %22, 1
%51 = call i32 @free(i8* %29)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %25, i64* %5)
%53 = icmp eq i8 %50, 8
br i1 %53, label %54, label %20
54: ; preds = %46
br label %55
55: ; preds = %54, %8
%56 = phi i32 [ 2, %8 ], [ 0, %54 ]
ret i32 %56
}