#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 scalar_t__ time_t;

/* Variables and functions */
int SHA_DIGEST_LENGTH;
int atoi(char *);
int /*<<< orphan*/ convertHash(char *, unsigned char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int strlen(char *);
scalar_t__ time(int /*<<< orphan*/ *);
int tryLength(int, unsigned char *, char *);
int main(int argc, char *argv[]) {
  if (argc < 2 || argc > 3) {
    printf("Usage: %s HASH [maxlen]\n", argv[0]);
    return 0;
  }
  if (strlen(argv[1]) != SHA_DIGEST_LENGTH * 2) {
    printf("Error: Malformed hash!\n");
    printf("Usage: %s HASH [maxlen]\n", argv[0]);
    return 1;
  }
  int maxlen = 16 + 1;
  if (argc == 3) {
    maxlen = atoi(argv[2]) + 1;
  }
  unsigned char target[SHA_DIGEST_LENGTH];
  convertHash(argv[1], target);
  time_t start, end;
  start = time(NULL);
  int i;
  for (i = 1; i < maxlen; i++) {
    printf("Trying length %d\n", i);
    fflush(stdout);
    char *plain = malloc(i);
    if (tryLength(i, target, plain) == 1) {
      end = time(NULL);
      printf("Success: %s (after %ld seconds)\n", plain, end - start);
      return 0;
    }
    free(plain);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11ba <main+0x2a>
cmpl   $0x3,-0x8(%rbp)
jle    11db <main+0x4b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    134b <main+0x1bb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    0x2df9(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
je     122b <main+0x9b>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    134b <main+0x1bb>
movl   $0x11,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    124f <main+0xbf>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x58(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <convertHash@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    133d <main+0x1ad>
mov    -0x3c(%rbp),%esi
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
mov    -0x3c(%rbp),%edi
call   1090 <malloc@plt>
mov    -0x58(%rbp),%rsi
mov    %rax,-0x48(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x48(%rbp),%rdx
call   1080 <tryLength@plt>
cmp    $0x1,%eax
jne    1326 <main+0x196>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %rax,-0x38(%rbp)
mov    -0x48(%rbp),%rsi
mov    -0x38(%rbp),%rdx
sub    -0x30(%rbp),%rdx
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1344 <main+0x1b4>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    129c <main+0x10c>
movl   $0x0,-0x4c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    -0x4(%rbx),%eax
cmp    $0xfffffffd,%eax
ja     11d7 <main+0x37>
mov    (%r14),%rsi
lea    0xe38(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12e4 <main+0x144>
mov    0x8(%r14),%rdi
call   1050 <strlen@plt>
mov    0x2e01(%rip),%rcx
mov    (%rcx),%r12d
lea    (%r12,%r12,1),%ecx
cmp    %ecx,%eax
jne    129c <main+0xfc>
mov    $0x11,%r15d
cmp    $0x3,%ebx
jne    1211 <main+0x71>
mov    0x10(%r14),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r15d
add    $0x1,%r15d
mov    %rsp,-0x38(%rbp)
mov    %rsp,%r13
add    $0xf,%r12
and    $0xfffffffffffffff0,%r12
sub    %r12,%r13
mov    %r13,%rsp
mov    0x8(%r14),%rdi
mov    %r13,%rsi
call   1070 <convertHash@plt>
xor    %r14d,%r14d
xor    %edi,%edi
call   1080 <time@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x2,%r15d
jl     12e0 <main+0x140>
mov    $0x1,%ebx
nop
lea    0xdc2(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
mov    %ebx,%edi
call   10a0 <malloc@plt>
mov    %rax,%r12
mov    %ebx,%edi
mov    %r13,%rsi
mov    %rax,%rdx
call   1090 <tryLength@plt>
cmp    $0x1,%eax
je     12c1 <main+0x121>
mov    %r12,%rdi
call   1030 <free@plt>
add    $0x1,%ebx
cmp    %ebx,%r15d
jne    1250 <main+0xb0>
jmp    12e0 <main+0x140>
lea    0xda9(%rip),%rdi
call   1040 <puts@plt>
mov    (%r14),%rsi
lea    0xd4e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%r14d
jmp    12e4 <main+0x144>
xor    %edi,%edi
call   1080 <time@plt>
sub    -0x30(%rbp),%rax
lea    0xd58(%rip),%rdi
mov    %r12,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x38(%rbp),%rsp
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Usage: %s HASH [maxlen]\0A\00"
@SHA_DIGEST_LENGTH = global i32 0
@.str.1 = [24 x i8] c"Error: Malformed hash!\0A\00"
@.str.2 = [18 x i8] c"Trying length %d\0A\00"
@stdout = global i32 0
@.str.3 = [33 x i8] c"Success: %s (after %ld seconds)\0A\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 i64
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
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 %19, label %16
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 3
br i1 %18, label %19, label %24
19: ; preds = %16, %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %22)
store i32 0, i32* %3
br label %89
24: ; preds = %16
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @strlen(i8* %27)
%29 = load i32, i32* @SHA_DIGEST_LENGTH
%30 = mul nsw i32 %29, 2
%31 = icmp ne i32 %28, %30
br i1 %31, label %32, label %38
32: ; preds = %24
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %36)
store i32 1, i32* %3
br label %89
38: ; preds = %24
store i32 17, i32* %6
%39 = load i32, i32* %4
%40 = icmp eq i32 %39, 3
br i1 %40, label %41, label %47
41: ; preds = %38
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32 @atoi(i8* %44)
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
br label %47
47: ; preds = %41, %38
%48 = load i32, i32* @SHA_DIGEST_LENGTH
%49 = zext i32 %48 to i64
%50 = call i8* @llvm.stacksave()
store i8* %50, i8** %7
%51 = alloca i8, i64 %49
store i64 %49, i64* %8
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = call i32 @convertHash(i8* %54, i8* %51)
%56 = call i64 @time(i32* null)
store i64 %56, i64* %9
store i32 1, i32* %11
br label %57
57: ; preds = %82, %47
%58 = load i32, i32* %11
%59 = load i32, i32* %6
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %85
61: ; preds = %57
%62 = load i32, i32* %11
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %62)
%64 = load i32, i32* @stdout
%65 = call i32 @fflush(i32 %64)
%66 = load i32, i32* %11
%67 = call i8* @malloc(i32 %66)
store i8* %67, i8** %12
%68 = load i32, i32* %11
%69 = load i8*, i8** %12
%70 = call i32 @tryLength(i32 %68, i8* %51, i8* %69)
%71 = icmp eq i32 %70, 1
br i1 %71, label %72, label %79
72: ; preds = %61
%73 = call i64 @time(i32* null)
store i64 %73, i64* %10
%74 = load i8*, i8** %12
%75 = load i64, i64* %10
%76 = load i64, i64* %9
%77 = sub nsw i64 %75, %76
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %74, i64 %77)
store i32 0, i32* %3
store i32 1, i32* %13
br label %86
79: ; preds = %61
%80 = load i8*, i8** %12
%81 = call i32 @free(i8* %80)
br label %82
82: ; preds = %79
%83 = load i32, i32* %11
%84 = add nsw i32 %83, 1
store i32 %84, i32* %11
br label %57
85: ; preds = %57
store i32 0, i32* %13
br label %86
86: ; preds = %85, %72
%87 = load i8*, i8** %7
%88 = load i32, i32* %13
switch i32 %88, label %91 [
i32 0, label %89
i32 1, label %89
]
89: ; preds = %19, %32, %86, %86
%90 = load i32, i32* %3
ret i32 %90
91: ; preds = %86
unreachable
}

LLVM IR (-O2):
@.str = [25 x i8] c"Usage: %s HASH [maxlen]\0A\00"
@SHA_DIGEST_LENGTH = global i32 0
@.str.2 = [18 x i8] c"Trying length %d\0A\00"
@stdout = global i32 0
@.str.3 = [33 x i8] c"Success: %s (after %ld seconds)\0A\00"
@str = [23 x i8] c"Error: Malformed hash!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add i32 %0, -4
%4 = icmp ult i32 %3, -2
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %52
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @strlen(i8* %10)
%12 = load i32, i32* @SHA_DIGEST_LENGTH
%13 = shl nsw i32 %12, 1
%14 = icmp eq i32 %11, %13
br i1 %14, label %19, label %15
15: ; preds = %8
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%17 = load i8*, i8** %1
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %52
19: ; preds = %8
%20 = icmp eq i32 %0, 3
br i1 %20, label %21, label %26
21: ; preds = %19
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32 @atoi(i8* %23)
%25 = add nsw i32 %24, 1
br label %26
26: ; preds = %21, %19
%27 = phi i32 [ %25, %21 ], [ 17, %19 ]
%28 = zext i32 %12 to i64
%29 = tail call i8* @llvm.stacksave()
%30 = alloca i8, i64 %28
%31 = load i8*, i8** %9
%32 = call i32 @convertHash(i8* %31, i8* %30)
%33 = call i64 @time(i32* null)
%34 = icmp sgt i32 %27, 1
br i1 %34, label %35, label %51
35: ; preds = %26, %47
%36 = phi i32 [ %49, %47 ], [ 1, %26 ]
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = load i32, i32* @stdout
%39 = call i32 @fflush(i32 %38)
%40 = call i8* @malloc(i32 %36)
%41 = call i32 @tryLength(i32 %36, i8* %30, i8* %40)
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %47
43: ; preds = %35
%44 = call i64 @time(i32* null)
%45 = sub nsw i64 %44, %33
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %40, i64 %45)
br label %51
47: ; preds = %35
%48 = call i32 @free(i8* %40)
%49 = add nuw nsw i32 %36, 1
%50 = icmp eq i32 %49, %27
br i1 %50, label %51, label %35
51: ; preds = %47, %26, %43
br label %52
52: ; preds = %51, %5, %15
%53 = phi i32 [ 0, %5 ], [ 1, %15 ], [ 0, %51 ]
ret i32 %53
}