#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ calculate_md5(char *, char *);
char *concat(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, long);
int /*<<< orphan*/ sprintf(char *, char *, long);
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char *, size_t);
int main(int argc, char **argv) {
  FILE *fp;
  char *text = NULL;
  size_t len = 0;
  long number = 0;
  char str_number[256];
  char *answer = NULL;
  char md5hash[33];
  const char *zeroes = "00000";
  fp = fopen("./input.txt", "r");
  getline(&text, &len, fp);
  fclose(fp);
  len = strlen(text);
  if (text[len - 1] == 10) {
    text[len - 1] = '\0';
  }
  while (number >= 0) {
    sprintf(str_number, "%ld", number);
    answer = concat(text, str_number);
    calculate_md5(answer, md5hash);
    if (strncmp(zeroes, md5hash, strlen(zeroes)) == 0) {
      break;
    }
    free(answer);
    number += 1;
  }
  printf("%ld", number);
  if (text) {
    free(text);
  }
  if (answer) {
    free(answer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x138(%rbp)
lea    0xe1d(%rip),%rax
mov    %rax,-0x168(%rbp)
lea    0xe15(%rip),%rdi
lea    0xe1a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10b0 <getline@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1251 <main+0xb1>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1256 <main+0xb6>
cmpq   $0x0,-0x30(%rbp)
jl     130c <main+0x16c>
lea    -0x130(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xda1(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x130(%rbp),%rsi
call   1080 <concat@plt>
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rdi
lea    -0x160(%rbp),%rsi
call   10a0 <calculate_md5@plt>
mov    -0x168(%rbp),%rax
mov    %rax,-0x178(%rbp)
lea    -0x160(%rbp),%rax
mov    %rax,-0x170(%rbp)
mov    -0x168(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x178(%rbp),%rdi
mov    -0x170(%rbp),%rsi
mov    %rax,%rdx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12ef <main+0x14f>
jmp    130c <main+0x16c>
mov    -0x138(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1256 <main+0xb6>
mov    -0x30(%rbp),%rsi
lea    0xcfd(%rip),%rdi
call   1070 <printf@plt>
cmpq   $0x0,-0x20(%rbp)
je     1330 <main+0x190>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x138(%rbp)
je     134a <main+0x1aa>
mov    -0x138(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe3d(%rip),%rdi
lea    0xe42(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   10b0 <getline@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    (%rsp),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %rax,0x8(%rsp)
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    120d <main+0x6d>
movb   $0x0,-0x1(%rbx,%rax,1)
xor    %ebx,%ebx
lea    0xdfe(%rip),%r14
lea    0x40(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xdd9(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   10c0 <sprintf@plt>
mov    (%rsp),%rdi
mov    %r15,%rsi
call   1080 <concat@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r12,%rsi
call   10a0 <calculate_md5@plt>
mov    $0x5,%edx
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <strncmp@plt>
test   %rax,%rax
je     127b <main+0xdb>
mov    %rbp,%rdi
call   1030 <free@plt>
add    $0x1,%rbx
jmp    1230 <main+0x90>
lea    0xd92(%rip),%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     1298 <main+0xf8>
call   1030 <free@plt>
test   %rbp,%rbp
je     12a5 <main+0x105>
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"00000\00"
@.str.1 = [12 x i8] c"./input.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%ld\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca [256 x i8]
%11 = alloca i8*
%12 = alloca [33 x i8]
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
store i64 0, i64* %8
store i64 0, i64* %9
store i8* null, i8** %11
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %13
%14 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = call i32 @getline(i8** %7, i64* %8, i32* %15)
%17 = load i32*, i32** %6
%18 = call i32 @fclose(i32* %17)
%19 = load i8*, i8** %7
%20 = call i64 @strlen(i8* %19)
store i64 %20, i64* %8
%21 = load i8*, i8** %7
%22 = load i64, i64* %8
%23 = sub i64 %22, 1
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %33
28: ; preds = %2
%29 = load i8*, i8** %7
%30 = load i64, i64* %8
%31 = sub i64 %30, 1
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %28, %2
br label %34
34: ; preds = %54, %33
%35 = load i64, i64* %9
%36 = icmp sge i64 %35, 0
br i1 %36, label %37, label %59
37: ; preds = %34
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%39 = load i64, i64* %9
%40 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %39)
%41 = load i8*, i8** %7
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%43 = call i8* @concat(i8* %41, i8* %42)
store i8* %43, i8** %11
%44 = load i8*, i8** %11
%45 = getelementptr inbounds [33 x i8], [33 x i8]* %12, i64 0, i64 0
%46 = call i32 @calculate_md5(i8* %44, i8* %45)
%47 = load i8*, i8** %13
%48 = getelementptr inbounds [33 x i8], [33 x i8]* %12, i64 0, i64 0
%49 = load i8*, i8** %13
%50 = call i64 @strlen(i8* %49)
%51 = call i64 @strncmp(i8* %47, i8* %48, i64 %50)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %37
br label %59
54: ; preds = %37
%55 = load i8*, i8** %11
%56 = call i32 @free(i8* %55)
%57 = load i64, i64* %9
%58 = add nsw i64 %57, 1
store i64 %58, i64* %9
br label %34
59: ; preds = %53, %34
%60 = load i64, i64* %9
%61 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %60)
%62 = load i8*, i8** %7
%63 = icmp ne i8* %62, null
br i1 %63, label %64, label %67
64: ; preds = %59
%65 = load i8*, i8** %7
%66 = call i32 @free(i8* %65)
br label %67
67: ; preds = %64, %59
%68 = load i8*, i8** %11
%69 = icmp ne i8* %68, null
br i1 %69, label %70, label %73
70: ; preds = %67
%71 = load i8*, i8** %11
%72 = call i32 @free(i8* %71)
br label %73
73: ; preds = %70, %67
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"00000\00"
@.str.1 = [12 x i8] c"./input.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%ld\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [256 x i8]
%6 = alloca [33 x i8]
%7 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%8 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [33 x i8], [33 x i8]* %6, i64 0, i64 0
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @getline(i8** %3, i64* %4, i32* %11)
%13 = call i32 @fclose(i32* %11)
%14 = load i8*, i8** %3
%15 = call i64 @strlen(i8* dereferenceable(1) %14)
store i64 %15, i64* %4
%16 = add i64 %15, -1
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 10
br i1 %19, label %20, label %21
20: ; preds = %2
store i8 0, i8* %17
br label %21
21: ; preds = %20, %2
br label %22
22: ; preds = %21, %30
%23 = phi i64 [ %32, %30 ], [ 0, %21 ]
%24 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %23)
%25 = load i8*, i8** %3
%26 = call i8* @concat(i8* %25, i8* %9)
%27 = call i32 @calculate_md5(i8* %26, i8* %10)
%28 = call i64 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %10, i64 5)
%29 = icmp eq i64 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %22
%31 = call i32 @free(i8* %26)
%32 = add nuw nsw i64 %23, 1
br label %22
33: ; preds = %22
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %23)
%35 = load i8*, i8** %3
%36 = icmp eq i8* %35, null
br i1 %36, label %39, label %37
37: ; preds = %33
%38 = call i32 @free(i8* %35)
br label %39
39: ; preds = %37, %33
%40 = icmp eq i8* %26, null
br i1 %40, label %43, label %41
41: ; preds = %39
%42 = call i32 @free(i8* %26)
br label %43
43: ; preds = %41, %39
ret i32 0
}