#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);
      password[pwd] = output[5];
      free(output);
    } while (flag);
    pwd++;
    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    132e <main+0x1ae>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1080 <memset@plt>
lea    -0x318(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
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    1327 <main+0x1a7>
jmp    1239 <main+0xb9>
lea    -0x310(%rbp),%rdi
mov    -0x320(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x320(%rbp)
lea    0xdbd(%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,-0x338(%rbp)
lea    -0x210(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x338(%rbp),%rdi
mov    %eax,%esi
call   1090 <str2md5@plt>
mov    %rax,-0x330(%rbp)
mov    -0x330(%rbp),%rdi
lea    0xd61(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
mov    %eax,-0x324(%rbp)
mov    -0x330(%rbp),%rax
mov    0x5(%rax),%cl
movsbq -0x325(%rbp),%rax
ff
mov    %cl,-0x318(%rbp,%rax,1)
mov    -0x330(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x324(%rbp)
jne    1239 <main+0xb9>
mov    -0x325(%rbp),%al
add    $0x1,%al
mov    %al,-0x325(%rbp)
mov    -0x320(%rbp),%esi
lea    -0x318(%rbp),%rdx
lea    0xd03(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1224 <main+0xa4>
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    $0x328,%rsp
cmp    $0x1,%edi
jg     11bc <main+0x2c>
lea    0xe63(%rip),%rdi
call   1060 <puts@plt>
mov    $0x2,%eax
jmp    12da <main+0x14a>
mov    %rsi,%rbp
lea    0x20(%rsp),%rbx
mov    $0x200,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <memset@plt>
movq   $0x0,0x18(%rsp)
mov    0x8(%rbp),%rsi
mov    %rbx,%rdi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbp
add    $0x20,%rbp
lea    0xdff(%rip),%r15
lea    0x220(%rsp),%r14
lea    0xdf3(%rip),%r13
xor    %eax,%eax
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rax,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edx
lea    0x1(%rdx),%eax
mov    %eax,0xc(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   10b0 <sprintf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   10a0 <str2md5@plt>
mov    %r14,%rbx
mov    %r15,%r14
mov    %rax,%r15
mov    %rax,%rdi
mov    %r13,%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
mov    %r13,%r12
mov    %eax,%r13d
movzbl 0x5(%r15),%eax
mov    0x10(%rsp),%rcx
mov    %al,0x18(%rsp,%rcx,1)
mov    %r15,%rdi
mov    %r14,%r15
mov    %rbx,%r14
call   1030 <free@plt>
test   %r13d,%r13d
mov    %r12,%r13
mov    0xc(%rsp),%ebx
jne    1230 <main+0xa0>
mov    0x10(%rsp),%r12
add    $0x1,%r12
lea    0xd4c(%rip),%rdi
mov    %ebx,%esi
lea    0x18(%rsp),%rdx
xor    %eax,%eax
call   1080 <printf@plt>
cmp    $0x8,%r12
mov    %r12,%rax
jne    1220 <main+0x90>
xor    %eax,%eax
add    $0x328,%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"
@.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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = 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 %67
18: ; preds = %2
%19 = bitcast [512 x i8]* %6 to i8*
%20 = bitcast [8 x i8]* %8 to i8*
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @strcpy(i8* %21, i8* %24)
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
store i32 %27, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i8 0, i8* %12
br label %28
28: ; preds = %60, %18
%29 = load i8, i8* %12
%30 = sext i8 %29 to i32
%31 = icmp slt i32 %30, 8
br i1 %31, label %32, label %66
32: ; preds = %28
br label %33
33: ; preds = %57, %32
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
store i32 %36, i32* %10
%37 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %39
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%42 = call i32 @strcpy(i8* %40, i8* %41)
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%45 = call i32 @strlen(i8* %44)
%46 = call i8* @str2md5(i8* %43, i32 %45)
store i8* %46, i8** %13
%47 = load i8*, i8** %13
%48 = call i32 @strncmp(i8* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
store i32 %48, i32* %11
%49 = load i8*, i8** %13
%50 = getelementptr inbounds i8, i8* %49, i64 5
%51 = load i8, i8* %50
%52 = load i8, i8* %12
%53 = sext i8 %52 to i64
%54 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 %53
store i8 %51, i8* %54
%55 = load i8*, i8** %13
%56 = call i32 @free(i8* %55)
br label %57
57: ; preds = %33
%58 = load i32, i32* %11
%59 = icmp ne i32 %58, 0
br i1 %59, label %33, label %60
60: ; preds = %57
%61 = load i8, i8* %12
%62 = add i8 %61, 1
store i8 %62, i8* %12
%63 = load i32, i32* %10
%64 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %63, i8* %64)
br label %28
66: ; preds = %28
store i32 0, i32* %3
br label %67
67: ; preds = %66, %16
%68 = load i32, i32* %3
ret i32 %68
}

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 %41
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 0, 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, %36
%21 = phi i64 [ 0, %10 ], [ %37, %36 ]
%22 = phi i32 [ 0, %10 ], [ %26, %36 ]
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 %21
br label %24
24: ; preds = %20, %24
%25 = phi i32 [ %26, %24 ], [ %22, %20 ]
%26 = add nsw i32 %25, 1
%27 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%28 = call i32 @strcpy(i8* %19, i8* %12)
%29 = call i32 @strlen(i8* %11)
%30 = call i8* @str2md5(i8* %11, i32 %29)
%31 = call i32 @strncmp(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%32 = getelementptr inbounds i8, i8* %30, i64 5
%33 = load i8, i8* %32
store i8 %33, i8* %23
%34 = call i32 @free(i8* %30)
%35 = icmp eq i32 %31, 0
br i1 %35, label %36, label %24
36: ; preds = %24
%37 = add nuw nsw i64 %21, 1
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %26, i64* %5)
%39 = icmp eq i64 %37, 8
br i1 %39, label %40, label %20
40: ; preds = %36
br label %41
41: ; preds = %40, %8
%42 = phi i32 [ 2, %8 ], [ 0, %40 ]
ret i32 %42
}