#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*/ assert(int);
int atoi(char *);
scalar_t__ extract_keyimg(char *, char const *);
scalar_t__ make_keyimg(char *, char const *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ random_key(char *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  if (argc < 2 || argc > 3) {
    printf("Usage: [num tests] (-m to mute)\n");
    return -1;
  }
  bool mute = false;
  if (argc == 3 && strcmp(argv[2], "-m") == 0)
    mute = true;
  int n = atoi(argv[1]);
  int i;
  for (i = 0; i < n; ++i) {
    if (!mute)
      printf("* Test %d\n", i + 1);
    const char *outpath = "testkeyimg.tox";
    char key_in[80] = {'\0'};
    random_key(key_in);
    assert(make_keyimg(key_in, outpath) == 0);
    char key_out[80] = {'\0'};
    assert(extract_keyimg(key_out, outpath) == 0);
    if (!mute) {
      printf("IN :%s\n", key_in);
      printf("OUT:%s\n\n", key_out);
    }
    assert(strcmp(key_in, key_out) == 0);
  }
  printf("Tests passed!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11ad <main+0x2d>
cmpl   $0x3,-0x8(%rbp)
jle    11c7 <main+0x47>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1329 <main+0x1a9>
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    11fd <main+0x7d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11fd <main+0x7d>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1314 <main+0x194>
cmpl   $0x0,-0x14(%rbp)
jne    123e <main+0xbe>
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdea(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
lea    -0x80(%rbp),%rdi
call   1080 <random_key@plt>
lea    -0x80(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10a0 <make_keyimg@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    -0xd0(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
lea    -0xd0(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <extract_keyimg@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpl   $0x0,-0x14(%rbp)
jne    12e5 <main+0x165>
lea    -0x80(%rbp),%rsi
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xd0(%rbp),%rsi
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
lea    -0xd0(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1214 <main+0x94>
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
lea    -0x4(%rdi),%eax
cmp    $0xfffffffd,%eax
ja     11af <main+0x2f>
lea    0xe9c(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
jmp    12fa <main+0x17a>
mov    %rsi,%rbx
mov    $0x1,%r14b
cmp    $0x3,%edi
jne    11d1 <main+0x51>
mov    0x10(%rbx),%rdi
lea    0xe3b(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
setne  %r14b
mov    0x8(%rbx),%rdi
call   1090 <atoi@plt>
test   %eax,%eax
jle    12ec <main+0x16c>
mov    %eax,%r15d
neg    %r15d
mov    $0x1,%ebx
lea    0x50(%rsp),%r12
lea    0xe15(%rip),%r13
mov    %rsp,%rbp
jmp    1230 <main+0xb0>
xchg   %ax,%ax
mov    %r12,%rdi
mov    %rbp,%rsi
call   1060 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
lea    (%r15,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
je     12ec <main+0x16c>
test   %r14b,%r14b
je     1245 <main+0xc5>
lea    0xdc7(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
mov    %r12,%rdi
call   1080 <random_key@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   10a0 <make_keyimg@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rbp,%rdi
mov    %r13,%rsi
call   1030 <extract_keyimg@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
test   %r14b,%r14b
je     1200 <main+0x80>
lea    0xd51(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd48(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1200 <main+0x80>
lea    0xd3b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Usage: [num tests] (-m to mute)\0A\00"
@.str.1 = [3 x i8] c"-m\00"
@.str.2 = [11 x i8] c"* Test %d\0A\00"
@.str.3 = [15 x i8] c"testkeyimg.tox\00"
@.str.4 = [8 x i8] c"IN :%s\0A\00"
@.str.5 = [9 x i8] c"OUT:%s\0A\0A\00"
@.str.6 = [15 x i8] c"Tests passed!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [80 x i8]
%11 = alloca [80 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 3
br i1 %16, label %17, label %19
17: ; preds = %14, %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %81
19: ; preds = %14
store i32 0, i32* %6
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 3
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 1, i32* %6
br label %29
29: ; preds = %28, %22, %19
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %7
store i32 0, i32* %8
br label %34
34: ; preds = %76, %29
%35 = load i32, i32* %8
%36 = load i32, i32* %7
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %79
38: ; preds = %34
%39 = load i32, i32* %6
%40 = icmp ne i32 %39, 0
br i1 %40, label %45, label %41
41: ; preds = %38
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %41, %38
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8** %9
%46 = bitcast [80 x i8]* %10 to i8*
%47 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%48 = call i32 @random_key(i8* %47)
%49 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%50 = load i8*, i8** %9
%51 = call i64 @make_keyimg(i8* %49, i8* %50)
%52 = icmp eq i64 %51, 0
%53 = zext i1 %52 to i32
%54 = call i32 @assert(i32 %53)
%55 = bitcast [80 x i8]* %11 to i8*
%56 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%57 = load i8*, i8** %9
%58 = call i64 @extract_keyimg(i8* %56, i8* %57)
%59 = icmp eq i64 %58, 0
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
%62 = load i32, i32* %6
%63 = icmp ne i32 %62, 0
br i1 %63, label %69, label %64
64: ; preds = %45
%65 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %65)
%67 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %67)
br label %69
69: ; preds = %64, %45
%70 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%71 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%72 = call i64 @strcmp(i8* %70, i8* %71)
%73 = icmp eq i64 %72, 0
%74 = zext i1 %73 to i32
%75 = call i32 @assert(i32 %74)
br label %76
76: ; preds = %69
%77 = load i32, i32* %8
%78 = add nsw i32 %77, 1
store i32 %78, i32* %8
br label %34
79: ; preds = %34
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %3
br label %81
81: ; preds = %79, %17
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"-m\00"
@.str.2 = [11 x i8] c"* Test %d\0A\00"
@.str.3 = [15 x i8] c"testkeyimg.tox\00"
@.str.4 = [8 x i8] c"IN :%s\0A\00"
@.str.5 = [9 x i8] c"OUT:%s\0A\0A\00"
@str = [14 x i8] c"Tests passed!\00"
@str.7 = [32 x i8] c"Usage: [num tests] (-m to mute)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = add i32 %0, -4
%6 = icmp ult i32 %5, -2
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.7, i64 0, i64 0))
br label %52
9: ; preds = %2
%10 = icmp eq i32 %0, 3
br i1 %10, label %11, label %16
11: ; preds = %9
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp ne i64 %14, 0
br label %16
16: ; preds = %11, %9
%17 = phi i1 [ true, %9 ], [ %15, %11 ]
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %50
22: ; preds = %16
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
br label %25
25: ; preds = %22, %43
%26 = phi i32 [ 0, %22 ], [ %48, %43 ]
br i1 %17, label %27, label %30
27: ; preds = %25
%28 = add nuw nsw i32 %26, 1
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %27, %25
%31 = call i32 @random_key(i8* %23)
%32 = call i64 @make_keyimg(i8* %23, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = call i64 @extract_keyimg(i8* %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
br i1 %17, label %40, label %43
40: ; preds = %30
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %24)
br label %43
43: ; preds = %40, %30
%44 = call i64 @strcmp(i8* %23, i8* %24)
%45 = icmp eq i64 %44, 0
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = add nuw nsw i32 %26, 1
%49 = icmp eq i32 %48, %20
br i1 %49, label %50, label %25
50: ; preds = %43, %16
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %52
52: ; preds = %50, %7
%53 = phi i32 [ -1, %7 ], [ 0, %50 ]
ret i32 %53
}