#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ password;
typedef int /*<<< orphan*/ input;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ MD5(char *, int *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char **argv) {
  char input[32];
  char numStr[32];
  char password[8 + 1];
  uint8_t md5sum[16];
  int num = 0, digitsFound = 0;
  memset(password, '\0', sizeof(password));
  if (argc != 2) {
    fprintf(stderr, "Usage:\n\tDay5 <input string>\n\n");
    return EXIT_FAILURE;
  }
  while (digitsFound < 8) {
    memset(input, '\0', sizeof(input));
    strncpy(input, argv[1], 32 - 1);
    sprintf(numStr, "%d", num);
    strcat(input, numStr);
    MD5(input, md5sum);
    if (md5sum[0] == 0 && md5sum[1] == 0 && md5sum[2] < 0x10) {
      sprintf(password + digitsFound, "%x", md5sum[2]);
      digitsFound++;
    }
    num++;
  }
  printf("%s\n", password);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xa4(%rbp)
movl   $0x0,-0xa8(%rbp)
lea    -0x59(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1050 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
je     11dd <main+0x6d>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12ce <main+0x15e>
jmp    11e2 <main+0x72>
cmpl   $0x8,-0xa8(%rbp)
jge    12b2 <main+0x142>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x1f,%edx
call   1030 <strncpy@plt>
lea    -0x50(%rbp),%rdi
mov    -0xa4(%rbp),%edx
lea    0xdf8(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1080 <strcat@plt>
lea    -0x30(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1070 <MD5@plt>
cmpl   $0x0,-0xa0(%rbp)
jne    129e <main+0x12e>
cmpl   $0x0,-0x9c(%rbp)
jne    129e <main+0x12e>
cmpl   $0x10,-0x98(%rbp)
jge    129e <main+0x12e>
lea    -0x59(%rbp),%rdi
movslq -0xa8(%rbp),%rax
add    %rax,%rdi
mov    -0x98(%rbp),%edx
lea    0xd97(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0xa8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa8(%rbp)
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
jmp    11e2 <main+0x72>
lea    -0x59(%rbp),%rsi
lea    0xd67(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0x7(%rsp),%rdi
xor    %r15d,%r15d
xor    %esi,%esi
mov    $0x9,%edx
call   1050 <memset@plt>
cmp    $0x2,%ebx
jne    124b <main+0xdb>
lea    0x70(%rsp),%rbx
lea    0x50(%rsp),%r12
lea    0x10(%rsp),%r13
xor    %ebp,%ebp
jmp    11cd <main+0x5d>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0x8,%r15d
jge    1269 <main+0xf9>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
mov    $0x1f,%edx
call   1030 <strncpy@plt>
mov    %r12,%rdi
lea    0xe27(%rip),%rsi
mov    %ebp,%edx
call   1090 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <MD5@plt>
cmpl   $0x0,0x10(%rsp)
jne    11c0 <main+0x50>
cmpl   $0x0,0x14(%rsp)
jne    11c0 <main+0x50>
mov    0x18(%rsp),%edx
cmp    $0xf,%edx
jg     11c0 <main+0x50>
movslq %r15d,%r15
lea    (%rsp,%r15,1),%rdi
add    $0x7,%rdi
lea    0xde4(%rip),%rsi
call   1090 <sprintf@plt>
add    $0x1,%r15d
jmp    11c0 <main+0x50>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xda5(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d71(%rip),%rax
jmp    1281 <main+0x111>
lea    0xdb4(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1040 <printf@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Usage:\0A\09Day5 <input string>\0A\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [32 x i8]
%7 = alloca [32 x i8]
%8 = alloca [9 x i8]
%9 = alloca [16 x i32]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
store i32 0, i32* %11
%12 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i8 signext 0, i32 9)
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %3
br label %69
20: ; preds = %2
br label %21
21: ; preds = %62, %20
%22 = load i32, i32* %11
%23 = icmp slt i32 %22, 8
br i1 %23, label %24, label %65
24: ; preds = %21
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%26 = call i32 @memset(i8* %25, i8 signext 0, i32 32)
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @strncpy(i8* %27, i8* %30, i32 31)
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%33 = load i32, i32* %10
%34 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%37 = call i32 @strcat(i8* %35, i8* %36)
%38 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%39 = getelementptr inbounds [16 x i32], [16 x i32]* %9, i64 0, i64 0
%40 = call i32 @MD5(i8* %38, i32* %39)
%41 = getelementptr inbounds [16 x i32], [16 x i32]* %9, i64 0, i64 0
%42 = load i32, i32* %41
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %62
44: ; preds = %24
%45 = getelementptr inbounds [16 x i32], [16 x i32]* %9, i64 0, i64 1
%46 = load i32, i32* %45
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %62
48: ; preds = %44
%49 = getelementptr inbounds [16 x i32], [16 x i32]* %9, i64 0, i64 2
%50 = load i32, i32* %49
%51 = icmp slt i32 %50, 16
br i1 %51, label %52, label %62
52: ; preds = %48
%53 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%54 = load i32, i32* %11
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = getelementptr inbounds [16 x i32], [16 x i32]* %9, i64 0, i64 2
%58 = load i32, i32* %57
%59 = call i32 @sprintf(i8* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %58)
%60 = load i32, i32* %11
%61 = add nsw i32 %60, 1
store i32 %61, i32* %11
br label %62
62: ; preds = %52, %48, %44, %24
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 1
store i32 %64, i32* %10
br label %21
65: ; preds = %21
%66 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%67 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %66)
%68 = load i32, i32* @EXIT_SUCCESS
store i32 %68, i32* %3
br label %69
69: ; preds = %65, %16
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Usage:\0A\09Day5 <input string>\0A\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [32 x i8]
%4 = alloca [32 x i8]
%5 = alloca [9 x i8]
%6 = alloca [16 x i32]
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%10 = bitcast [16 x i32]* %6 to i8*
%11 = call i32 @memset(i8* %9, i8 signext 0, i32 9)
%12 = icmp eq i32 %0, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 0
%16 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 1
%17 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 2
br label %21
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %49
21: ; preds = %13, %43
%22 = phi i32 [ 0, %13 ], [ %44, %43 ]
%23 = phi i32 [ 0, %13 ], [ %45, %43 ]
%24 = call i32 @memset(i8* %7, i8 signext 0, i32 32)
%25 = load i8*, i8** %14
%26 = call i32 @strncpy(i8* %7, i8* %25, i32 31)
%27 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%28 = call i32 @strcat(i8* %7, i8* %8)
%29 = call i32 @MD5(i8* %7, i32* %15)
%30 = load i32, i32* %15
%31 = icmp eq i32 %30, 0
%32 = load i32, i32* %16
%33 = icmp eq i32 %32, 0
%34 = select i1 %31, i1 %33, i1 false
%35 = load i32, i32* %17
%36 = icmp slt i32 %35, 16
%37 = select i1 %34, i1 %36, i1 false
br i1 %37, label %38, label %43
38: ; preds = %21
%39 = sext i32 %22 to i64
%40 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 %39
%41 = call i32 @sprintf(i8* %40, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%42 = add nsw i32 %22, 1
br label %43
43: ; preds = %38, %21
%44 = phi i32 [ %42, %38 ], [ %22, %21 ]
%45 = add nuw nsw i32 %23, 1
%46 = icmp slt i32 %44, 8
br i1 %46, label %21, label %47
47: ; preds = %43
%48 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %9)
br label %49
49: ; preds = %47, %18
%50 = phi i32* [ @EXIT_FAILURE, %18 ], [ @EXIT_SUCCESS, %47 ]
%51 = load i32, i32* %50
ret i32 %51
}