#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 clock_it();
double f(double);
int /*<<< orphan*/ printf(char *, double);
main() {
  double sum, pi, x, h;
  double start_time, stop_time;
  int i;
  h = (double)1.0 / (double)2000000000;
  sum = 0.0;
  start_time = clock_it();
  for (i = 0; i < 2000000000; i++) {
    x = h * (i - 0.5);
    sum = sum + f(x);
  }
  stop_time = clock_it();
  pi = h * sum;
  printf("    pi is approximately : %12.9f \n", pi);
  printf("Elapsed time = %lf seconds\n", (stop_time - start_time));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xeb9(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1050 <clock_it@plt>
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x77359400,-0x3c(%rbp)
jge    11c6 <main+0x96>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x3c(%rbp),%xmm1
movsd  0xe82(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <f@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1167 <main+0x37>
mov    $0x0,%al
call   1050 <clock_it@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe23(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x38(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
lea    0xe30(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
xor    %eax,%eax
call   1050 <clock_it@plt>
movsd  %xmm0,0x18(%rsp)
xorpd  %xmm1,%xmm1
mov    $0x77359400,%ebx
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
addsd  0xe8e(%rip),%xmm0
mulsd  0xe8e(%rip),%xmm0
call   1030 <f@plt>
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x8(%rsp),%xmm1
addsd  0xe73(%rip),%xmm1
add    $0xffffffff,%ebx
jne    1160 <main+0x30>
xor    %eax,%eax
call   1050 <clock_it@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  0xe4b(%rip),%xmm0
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [35 x i8] c" pi is approximately : %12.9f \0A\00"
@.str.1 = [28 x i8] c"Elapsed time = %lf seconds\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
store i32 0, i32* %1
store double 5.000000e-10, double* %5
store double 0.000000e+00, double* %2
%9 = call double (...) @clock_it()
store double %9, double* %6
store i32 0, i32* %8
br label %10
10: ; preds = %23, %0
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 2000000000
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = load double, double* %5
%15 = load i32, i32* %8
%16 = sitofp i32 %15 to double
%17 = fsub double %16, 5.000000e-01
%18 = fmul double %14, %17
store double %18, double* %4
%19 = load double, double* %2
%20 = load double, double* %4
%21 = call double @f(double %20)
%22 = fadd double %19, %21
store double %22, double* %2
br label %23
23: ; preds = %13
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
store i32 %25, i32* %8
br label %10
26: ; preds = %10
%27 = call double (...) @clock_it()
store double %27, double* %7
%28 = load double, double* %5
%29 = load double, double* %2
%30 = fmul double %28, %29
store double %30, double* %3
%31 = load double, double* %3
%32 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), double %31)
%33 = load double, double* %7
%34 = load double, double* %6
%35 = fsub double %33, %34
%36 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), double %35)
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str = [35 x i8] c" pi is approximately : %12.9f \0A\00"
@.str.1 = [28 x i8] c"Elapsed time = %lf seconds\0A\00"
define i32 @main() {
%1 = tail call double (...) @clock_it()
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ 0, %0 ], [ %10, %2 ]
%4 = phi double [ 0.000000e+00, %0 ], [ %9, %2 ]
%5 = sitofp i32 %3 to double
%6 = fadd double %5, -5.000000e-01
%7 = fmul double %6, 5.000000e-10
%8 = tail call double @f(double %7)
%9 = fadd double %4, %8
%10 = add nuw nsw i32 %3, 1
%11 = icmp eq i32 %10, 2000000000
br i1 %11, label %12, label %2
12: ; preds = %2
%13 = tail call double (...) @clock_it()
%14 = fmul double %9, 5.000000e-10
%15 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), double %14)
%16 = fsub double %13, %1
%17 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), double %16)
ret i32 0
}