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


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

x86 assembly (clang, -O2):
<abs_test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffff9c,%ebp
lea    0xebd(%rip),%r14
xor    %r15d,%r15d
jmp    1158 <abs_test+0x28>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0x64,%ebp
je     1187 <abs_test+0x57>
mov    %ebp,%ebx
neg    %ebx
cmovs  %ebp,%ebx
mov    %ebp,%edi
call   1050 <abs_c@plt>
cmp    %eax,%ebx
je     1150 <abs_test+0x20>
mov    %ebp,%edi
call   1050 <abs_c@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15d
jmp    1150 <abs_test+0x20>
test   %r15d,%r15d
je     11a7 <abs_test+0x77>
lea    0xe9c(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
lea    0xe96(%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"ABS Error: Input %d, Expected %d, Received %d\0A\00"
@.str.1 = [18 x i8] c"ABS Tests Passed\0A\00"
@.str.2 = [21 x i8] c"ABS Test: %d errors\0A\00"
define void @abs_test() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 -100, i32* %2
br label %3
3: ; preds = %22, %0
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 100
br i1 %5, label %6, label %25
6: ; preds = %3
%7 = load i32, i32* %2
%8 = call i32 @abs(i32 %7)
%9 = load i32, i32* %2
%10 = call i32 @abs_c(i32 %9)
%11 = icmp ne i32 %8, %10
br i1 %11, label %12, label %21
12: ; preds = %6
%13 = load i32, i32* %2
%14 = load i32, i32* %2
%15 = call i32 @abs_c(i32 %14)
%16 = load i32, i32* %2
%17 = call i32 @abs(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* %1
%20 = add nsw i32 %19, 1
store i32 %20, i32* %1
br label %21
21: ; preds = %12, %6
br label %22
22: ; preds = %21
%23 = load i32, i32* %2
%24 = add nsw i32 %23, 1
store i32 %24, i32* %2
br label %3
25: ; preds = %3
%26 = load i32, i32* %1
%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* %1
%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"ABS Error: Input %d, Expected %d, Received %d\0A\00"
@.str.2 = [21 x i8] c"ABS Test: %d errors\0A\00"
@str = [17 x i8] c"ABS Tests Passed\00"
define void @abs_test() {
br label %1
1: ; preds = %0, %11
%2 = phi i32 [ -100, %0 ], [ %13, %11 ]
%3 = phi i32 [ 0, %0 ], [ %12, %11 ]
%4 = tail call i32 @llvm.abs.i32(i32 %2, i1 true)
%5 = tail call i32 @abs_c(i32 %2)
%6 = icmp eq i32 %4, %5
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = tail call i32 @abs_c(i32 %2)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %8, i32 %4)
%10 = add nsw i32 %3, 1
br label %11
11: ; preds = %1, %7
%12 = phi i32 [ %10, %7 ], [ %3, %1 ]
%13 = add nsw i32 %2, 1
%14 = icmp eq i32 %13, 100
br i1 %14, label %15, label %1
15: ; preds = %11
%16 = icmp eq i32 %12, 0
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %21
19: ; preds = %15
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %21
21: ; preds = %19, %17
ret void
}