#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
int EXIT_SUCCESS;
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, double);
int main(int argc, char *argv[]) {
  int i, num_steps;
  double x, sum, step, pi;
  clock_t t_start, t_end;
  num_steps = 500000000;
  x = 0;
  sum = 0.0;
  step = 1.0 / (double)num_steps;
  t_start = clock();
  for (i = 0; i < num_steps; i++) {
    x = (i + 0.5) * step;
    sum = sum + 4.0 / (1.0 + x * x);
  }
  pi = step * sum;
  t_end = clock();
  printf("Value of pi = %g\n", pi);
  printf("Expended wall clock time = %.20f\n",
         (double)(t_end - t_start) / CLOCKS_PER_SEC);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1dcd6500,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm1
movsd  0xea6(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11de <main+0xbe>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xe82(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm2
movsd  0xe49(%rip),%xmm1
addsd  %xmm1,%xmm2
movsd  0xe45(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1175 <main+0x55>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
mov    -0x48(%rbp),%rax
sub    -0x40(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2dcb(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
xorpd  %xmm0,%xmm0
mov    $0x1,%eax
movsd  0xec1(%rip),%xmm1
movsd  0xec1(%rip),%xmm2
movsd  0xec1(%rip),%xmm3
movsd  0xec1(%rip),%xmm5
movsd  0xec0(%rip),%xmm8
xorpd  %xmm4,%xmm4
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movapd %xmm0,%xmm6
addsd  %xmm1,%xmm6
mulsd  %xmm2,%xmm6
mulsd  %xmm6,%xmm6
addsd  %xmm3,%xmm6
movapd %xmm5,%xmm7
divsd  %xmm6,%xmm7
addsd  %xmm4,%xmm7
xorps  %xmm6,%xmm6
cvtsi2sd %eax,%xmm6
addsd  %xmm1,%xmm6
mulsd  %xmm2,%xmm6
mulsd  %xmm6,%xmm6
addsd  %xmm3,%xmm6
movapd %xmm5,%xmm4
divsd  %xmm6,%xmm4
addsd  %xmm7,%xmm4
addsd  %xmm8,%xmm0
add    $0x2,%eax
cmp    $0x1dcd6501,%eax
jne    1170 <main+0x50>
mulsd  0xe3e(%rip),%xmm4
movsd  %xmm4,(%rsp)
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
lea    0xe48(%rip),%rdi
movsd  (%rsp),%xmm0
call   1040 <printf@plt>
sub    %r14,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
mov    0x2dec(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe33(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Value of pi = %g\0A\00"
@.str.1 = [34 x i8] c"Expended wall clock time = %.20f\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i64
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 500000000, i32* %7
store double 0.000000e+00, double* %8
store double 0.000000e+00, double* %9
%14 = load i32, i32* %7
%15 = sitofp i32 %14 to double
%16 = fdiv double 1.000000e+00, %15
store double %16, double* %10
%17 = call i64 (...) @clock()
store i64 %17, i64* %12
store i32 0, i32* %6
br label %18
18: ; preds = %34, %2
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %37
22: ; preds = %18
%23 = load i32, i32* %6
%24 = sitofp i32 %23 to double
%25 = fadd double %24, 5.000000e-01
%26 = load double, double* %10
%27 = fmul double %25, %26
store double %27, double* %8
%28 = load double, double* %9
%29 = load double, double* %8
%30 = load double, double* %8
%31 = call double @llvm.fmuladd.f64(double %29, double %30, double 1.000000e+00)
%32 = fdiv double 4.000000e+00, %31
%33 = fadd double %28, %32
store double %33, double* %9
br label %34
34: ; preds = %22
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %18
37: ; preds = %18
%38 = load double, double* %10
%39 = load double, double* %9
%40 = fmul double %38, %39
store double %40, double* %11
%41 = call i64 (...) @clock()
store i64 %41, i64* %13
%42 = load double, double* %11
%43 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %42)
%44 = load i64, i64* %13
%45 = load i64, i64* %12
%46 = sub nsw i64 %44, %45
%47 = sitofp i64 %46 to double
%48 = load double, double* @CLOCKS_PER_SEC
%49 = fdiv double %47, %48
%50 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), double %49)
%51 = load i32, i32* @EXIT_SUCCESS
ret i32 %51
}

LLVM IR (-O2):
@.str = [18 x i8] c"Value of pi = %g\0A\00"
@.str.1 = [34 x i8] c"Expended wall clock time = %.20f\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @clock()
br label %4
4: ; preds = %4, %2
%5 = phi i32 [ 0, %2 ], [ %20, %4 ]
%6 = phi double [ 0.000000e+00, %2 ], [ %19, %4 ]
%7 = sitofp i32 %5 to double
%8 = fadd double %7, 5.000000e-01
%9 = fmul double %8, 2.000000e-09
%10 = tail call double @llvm.fmuladd.f64(double %9, double %9, double 1.000000e+00)
%11 = fdiv double 4.000000e+00, %10
%12 = fadd double %6, %11
%13 = or i32 %5, 1
%14 = sitofp i32 %13 to double
%15 = fadd double %14, 5.000000e-01
%16 = fmul double %15, 2.000000e-09
%17 = tail call double @llvm.fmuladd.f64(double %16, double %16, double 1.000000e+00)
%18 = fdiv double 4.000000e+00, %17
%19 = fadd double %12, %18
%20 = add nuw nsw i32 %5, 2
%21 = icmp eq i32 %20, 500000000
br i1 %21, label %22, label %4
22: ; preds = %4
%23 = fmul double %19, 2.000000e-09
%24 = tail call i64 (...) @clock()
%25 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %23)
%26 = sub nsw i64 %24, %3
%27 = sitofp i64 %26 to double
%28 = load double, double* @CLOCKS_PER_SEC
%29 = fdiv double %27, %28
%30 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), double %29)
%31 = load i32, i32* @EXIT_SUCCESS
ret i32 %31
}