#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 fib(int);
int fib_c(int);
int /*<<< orphan*/ printf(char *, ...);
void fib_test(void) {
  int i;
  int error_count = 0;
  for (i = 0; i <= 46; i++) {
    if (fib(i) != fib_c(i)) {
      printf("Fib Error: Input %d, Expected %d, Received %d\n", i, fib_c(i),
             fib(i));
      error_count++;
    }
  }
  if (!error_count) {
    printf("Fib Tests Passed\n");
  } else {
    printf("Fib Test: %d errors\n", error_count);
  }
}


x86 assembly (clang, -O0):
<fib_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x2e,-0x4(%rbp)
jg     11bb <fib_test+0x8b>
mov    -0x4(%rbp),%edi
call   1050 <fib@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <fib_c@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
cmp    %ecx,%eax
je     11a8 <fib_test+0x78>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <fib_c@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <fib@plt>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    %eax,%ecx
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ad <fib_test+0x7d>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1146 <fib_test+0x16>
cmpl   $0x0,-0x8(%rbp)
jne    11d8 <fib_test+0xa8>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e9 <fib_test+0xb9>
mov    -0x8(%rbp),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fib_test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeb2(%rip),%r14
xor    %r15d,%r15d
xor    %ebp,%ebp
jmp    1168 <fib_test+0x28>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
cmp    $0x2f,%ebp
je     11a2 <fib_test+0x62>
mov    %ebp,%edi
call   1060 <fib@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1050 <fib_c@plt>
cmp    %eax,%ebx
je     1160 <fib_test+0x20>
mov    %ebp,%edi
call   1050 <fib_c@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1060 <fib@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15d
jmp    1160 <fib_test+0x20>
test   %r15d,%r15d
je     11c2 <fib_test+0x82>
lea    0xe81(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
lea    0xe7b(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"Fib Error: Input %d, Expected %d, Received %d\0A\00"
@.str.1 = [18 x i8] c"Fib Tests Passed\0A\00"
@.str.2 = [21 x i8] c"Fib Test: %d errors\0A\00"
define void @fib_test() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %2
store i32 0, i32* %1
br label %3
3: ; preds = %22, %0
%4 = load i32, i32* %1
%5 = icmp sle i32 %4, 46
br i1 %5, label %6, label %25
6: ; preds = %3
%7 = load i32, i32* %1
%8 = call i32 @fib(i32 %7)
%9 = load i32, i32* %1
%10 = call i32 @fib_c(i32 %9)
%11 = icmp ne i32 %8, %10
br i1 %11, label %12, label %21
12: ; preds = %6
%13 = load i32, i32* %1
%14 = load i32, i32* %1
%15 = call i32 @fib_c(i32 %14)
%16 = load i32, i32* %1
%17 = call i32 @fib(i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %15, i32 %17)
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %21
21: ; preds = %12, %6
br label %22
22: ; preds = %21
%23 = load i32, i32* %1
%24 = add nsw i32 %23, 1
store i32 %24, i32* %1
br label %3
25: ; preds = %3
%26 = load i32, i32* %2
%27 = icmp ne i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %33
30: ; preds = %25
%31 = load i32, i32* %2
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30, %28
ret void
}

LLVM IR (-O2):
@.str = [47 x i8] c"Fib Error: Input %d, Expected %d, Received %d\0A\00"
@.str.2 = [21 x i8] c"Fib Test: %d errors\0A\00"
@str = [17 x i8] c"Fib Tests Passed\00"
define void @fib_test() {
br label %1
1: ; preds = %0, %12
%2 = phi i32 [ 0, %0 ], [ %13, %12 ]
%3 = phi i32 [ 0, %0 ], [ %14, %12 ]
%4 = tail call i32 @fib(i32 %3)
%5 = tail call i32 @fib_c(i32 %3)
%6 = icmp eq i32 %4, %5
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = tail call i32 @fib_c(i32 %3)
%9 = tail call i32 @fib(i32 %3)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %8, i32 %9)
%11 = add nsw i32 %2, 1
br label %12
12: ; preds = %1, %7
%13 = phi i32 [ %11, %7 ], [ %2, %1 ]
%14 = add nuw nsw i32 %3, 1
%15 = icmp eq i32 %14, 47
br i1 %15, label %16, label %1
16: ; preds = %12
%17 = icmp eq i32 %13, 0
br i1 %17, label %18, label %20
18: ; preds = %16
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %22
20: ; preds = %16
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %22
22: ; preds = %20, %18
ret void
}