#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 fabs(double);
double pi_kernel(int, double);
int /*<<< orphan*/ printf(char *, double, double);
int main(int argc, char **argv) {
  int n = 1000000;
  double PI25DT = 3.141592653589793238462643;
  double pi, h, area, x;
  h = 1.0 / (double)n;
  area = pi_kernel(n, h);
  pi = h * area;
  printf("pi is approximately %.16f, Error is %.16f\n", pi, fabs(pi - PI25DT));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xf4240,-0x14(%rbp)
movsd  0xeda(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xec0(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%edi
movsd  -0x30(%rbp),%xmm0
call   1040 <pi_kernel@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
subsd  -0x20(%rbp),%xmm1
movaps 0xe70(%rip),%xmm2
pand   %xmm2,%xmm1
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movsd  0xed7(%rip),%xmm0
mov    $0xf4240,%edi
call   1040 <pi_kernel@plt>
mulsd  0xec5(%rip),%xmm0
movsd  0xec5(%rip),%xmm1
addsd  %xmm0,%xmm1
andpd  0xec1(%rip),%xmm1
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [43 x i8] c"pi is approximately %.16f, Error is %.16f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 1000000, i32* %5
store double 0x400921FB54442D18, double* %6
%11 = load i32, i32* %5
%12 = sitofp i32 %11 to double
%13 = fdiv double 1.000000e+00, %12
store double %13, double* %8
%14 = load i32, i32* %5
%15 = load double, double* %8
%16 = call double @pi_kernel(i32 %14, double %15)
store double %16, double* %9
%17 = load double, double* %8
%18 = load double, double* %9
%19 = fmul double %17, %18
store double %19, double* %7
%20 = load double, double* %7
%21 = load double, double* %7
%22 = load double, double* %6
%23 = fsub double %21, %22
%24 = call double @llvm.fabs.f64(double %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), double %20, double %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [43 x i8] c"pi is approximately %.16f, Error is %.16f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call double @pi_kernel(i32 1000000, double 0x3EB0C6F7A0B5ED8D)
%4 = fmul double %3, 0x3EB0C6F7A0B5ED8D
%5 = fadd double %4, 0xC00921FB54442D18
%6 = tail call double @llvm.fabs.f64(double %5)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), double %4, double %6)
ret i32 0
}