#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*/ printf(char *);
int stdlib_base_labs(int);
double tic();
double benchmark() {
  double elapsed;
  double t;
  int x;
  int y;
  int i;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    x = i - 1000000;
    y = stdlib_base_labs(x);
    if (y < 0) {
      printf("should not return a negative number\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (y < 0) {
    printf("should not return a negative number\n");
  }
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <tic@plt>
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xf4240,-0x1c(%rbp)
jge    119c <benchmark+0x6c>
mov    -0x1c(%rbp),%eax
sub    $0xf4240,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <stdlib_base_labs@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1189 <benchmark+0x59>
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
jmp    119c <benchmark+0x6c>
jmp    118e <benchmark+0x5e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114b <benchmark+0x1b>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11c3 <benchmark+0x93>
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0xfff0bdc0,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1050 <stdlib_base_labs@plt>
test   %eax,%eax
js     1168 <benchmark+0x38>
inc    %ebx
jne    1150 <benchmark+0x20>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    1190 <benchmark+0x60>
lea    0xe91(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1030 <puts@plt>
movsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [37 x i8] c"should not return a negative number\0A\00"
define double @benchmark() {
%1 = alloca double
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = call double (...) @tic()
store double %6, double* %2
store i32 0, i32* %5
br label %7
7: ; preds = %20, %0
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 1000000
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, 1000000
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = call i32 @stdlib_base_labs(i32 %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %23
19: ; preds = %10
br label %20
20: ; preds = %19
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %7
23: ; preds = %17, %7
%24 = call double (...) @tic()
%25 = load double, double* %2
%26 = fsub double %24, %25
store double %26, double* %1
%27 = load i32, i32* %4
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %29, %23
%32 = load double, double* %1
ret double %32
}

LLVM IR (-O2):
@str.1 = [36 x i8] c"should not return a negative number\00"
define double @benchmark() {
%1 = tail call double (...) @tic()
br label %5
2: ; preds = %5
%3 = add nuw nsw i32 %6, 1
%4 = icmp eq i32 %3, 1000000
br i1 %4, label %10, label %5
5: ; preds = %0, %2
%6 = phi i32 [ 0, %0 ], [ %3, %2 ]
%7 = add nuw nsw i32 %6, -1000000
%8 = tail call i32 @stdlib_base_labs(i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %12, label %2
10: ; preds = %2
%11 = tail call double (...) @tic()
br label %16
12: ; preds = %5
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.1, i64 0, i64 0))
%14 = tail call double (...) @tic()
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.1, i64 0, i64 0))
br label %16
16: ; preds = %10, %12
%17 = phi double [ %14, %12 ], [ %11, %10 ]
%18 = fsub double %17, %1
ret double %18
}