#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 */
double now();
int /*<<< orphan*/ printf(char *, ...);
double sin(int);
void cpu() {
  double start = now();
  double s = 1.0;
  int i;
  for (i = 0; (i < 1000000); i++) {
    s = sin(i);
  }
  printf("Printing result of CPU test computation so the compiler cannot "
         "optimize it away:\r\n");
  printf("%f\r\n", s);
  double end = now();
  printf("CPU benchmark time: %.04f\r\n", end - start);
}


x86 assembly (clang, -O0):
<cpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <now@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  0xeb4(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xf4240,-0x14(%rbp)
jge    1180 <cpu+0x50>
mov    -0x14(%rbp),%edi
call   1040 <sin@plt>
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1158 <cpu+0x28>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
lea    0xec1(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <now@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
lea    0xea2(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu>:
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <now@plt>
movsd  %xmm0,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
call   1050 <sin@plt>
lea    0x1(%rbx),%edi
call   1050 <sin@plt>
lea    0x2(%rbx),%edi
call   1050 <sin@plt>
lea    0x3(%rbx),%edi
call   1050 <sin@plt>
lea    0x4(%rbx),%edi
call   1050 <sin@plt>
lea    0x5(%rbx),%edi
call   1050 <sin@plt>
lea    0x6(%rbx),%edi
call   1050 <sin@plt>
lea    0x7(%rbx),%edi
call   1050 <sin@plt>
lea    0x8(%rbx),%edi
call   1050 <sin@plt>
lea    0x9(%rbx),%edi
call   1050 <sin@plt>
add    $0xa,%ebx
cmp    $0xf4240,%ebx
jne    1160 <cpu+0x20>
lea    0xe60(%rip),%rdi
movsd  %xmm0,(%rsp)
call   1030 <puts@plt>
lea    0xe2e(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <now@plt>
subsd  0x8(%rsp),%xmm0
lea    0xe13(%rip),%rdi
mov    $0x1,%al
add    $0x10,%rsp
pop    %rbx
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [83 x i8] c"Printing result of CPU test computation so the compiler cannot optimize it away:\0D\0A\00"
@.str.1 = [5 x i8] c"%f\0D\0A\00"
@.str.2 = [28 x i8] c"CPU benchmark time: %.04f\0D\0A\00"
define void @cpu() {
%1 = alloca double
%2 = alloca double
%3 = alloca i32
%4 = alloca double
%5 = call double (...) @now()
store double %5, double* %1
store double 1.000000e+00, double* %2
store i32 0, i32* %3
br label %6
6: ; preds = %12, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 1000000
br i1 %8, label %9, label %15
9: ; preds = %6
%10 = load i32, i32* %3
%11 = call double @sin(i32 %10)
store double %11, double* %2
br label %12
12: ; preds = %9
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
br label %6
15: ; preds = %6
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0))
%17 = load double, double* %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %17)
%19 = call double (...) @now()
store double %19, double* %4
%20 = load double, double* %4
%21 = load double, double* %1
%22 = fsub double %20, %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), double %22)
ret void
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%f\0D\0A\00"
@.str.2 = [28 x i8] c"CPU benchmark time: %.04f\0D\0A\00"
@str = [82 x i8] c"Printing result of CPU test computation so the compiler cannot optimize it away:\0D\00"
define void @cpu() {
%1 = tail call double (...) @now()
br label %2
2: ; preds = %2, %0
%3 = phi i32 [ 0, %0 ], [ %23, %2 ]
%4 = tail call double @sin(i32 %3)
%5 = or i32 %3, 1
%6 = tail call double @sin(i32 %5)
%7 = add nuw nsw i32 %3, 2
%8 = tail call double @sin(i32 %7)
%9 = add nuw nsw i32 %3, 3
%10 = tail call double @sin(i32 %9)
%11 = add nuw nsw i32 %3, 4
%12 = tail call double @sin(i32 %11)
%13 = add nuw nsw i32 %3, 5
%14 = tail call double @sin(i32 %13)
%15 = add nuw nsw i32 %3, 6
%16 = tail call double @sin(i32 %15)
%17 = add nuw nsw i32 %3, 7
%18 = tail call double @sin(i32 %17)
%19 = add nuw nsw i32 %3, 8
%20 = tail call double @sin(i32 %19)
%21 = add nuw nsw i32 %3, 9
%22 = tail call double @sin(i32 %21)
%23 = add nuw nsw i32 %3, 10
%24 = icmp eq i32 %23, 1000000
br i1 %24, label %25, label %2
25: ; preds = %2
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @str, i64 0, i64 0))
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %22)
%28 = tail call double (...) @now()
%29 = fsub double %28, %1
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), double %29)
ret void
}