#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 compute_pi_baseline(size_t N) {
  double pi = 0.0;
  double dt = 1.0 / N;
  for (size_t i = 0; i < N; i++) {
    double x = (double)i / N;
    pi += dt / (1.0 + x * x);
  }
  return pi * 4.0;
}


x86 assembly (clang, -O0):
<compute_pi_baseline>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movaps 0xef9(%rip),%xmm0
movq   -0x8(%rbp),%xmm1
punpckldq %xmm0,%xmm1
movapd 0xef8(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xec1(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11e4 <compute_pi_baseline+0xe4>
movq   -0x20(%rbp),%xmm0
movaps 0xea6(%rip),%xmm3
punpckldq %xmm3,%xmm0
movapd 0xeaa(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movq   -0x8(%rbp),%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xe3f(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1150 <compute_pi_baseline+0x50>
movsd  0xe1c(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_pi_baseline>:
test   %rdi,%rdi
je     1153 <compute_pi_baseline+0x53>
movq   %rdi,%xmm0
punpckldq 0xeee(%rip),%xmm0
subpd  0xef6(%rip),%xmm0
movapd %xmm0,%xmm2
unpckhpd %xmm0,%xmm2
addsd  %xmm0,%xmm2
movsd  0xef2(%rip),%xmm3
movapd %xmm3,%xmm1
divsd  %xmm2,%xmm1
cmp    $0x1,%rdi
jne    1157 <compute_pi_baseline+0x57>
xorpd  %xmm0,%xmm0
xorpd  %xmm3,%xmm3
test   $0x1,%dil
jne    1216 <compute_pi_baseline+0x116>
jmp    122e <compute_pi_baseline+0x12e>
xorps  %xmm0,%xmm0
ret
mov    %rdi,%rax
and    $0xfffffffffffffffe,%rax
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
movdqa 0xe94(%rip),%xmm4
movapd 0xe9c(%rip),%xmm5
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movq   %rcx,%xmm6
punpckldq %xmm4,%xmm6
subpd  %xmm5,%xmm6
movapd %xmm6,%xmm7
unpckhpd %xmm6,%xmm7
addsd  %xmm6,%xmm7
divsd  %xmm2,%xmm7
mulsd  %xmm7,%xmm7
addsd  %xmm3,%xmm7
movapd %xmm1,%xmm6
divsd  %xmm7,%xmm6
addsd  %xmm0,%xmm6
lea    0x1(%rcx),%rdx
movq   %rdx,%xmm0
punpckldq %xmm4,%xmm0
subpd  %xmm5,%xmm0
movapd %xmm0,%xmm7
unpckhpd %xmm0,%xmm7
addsd  %xmm0,%xmm7
divsd  %xmm2,%xmm7
mulsd  %xmm7,%xmm7
addsd  %xmm3,%xmm7
movapd %xmm1,%xmm0
divsd  %xmm7,%xmm0
addsd  %xmm6,%xmm0
add    $0x2,%rcx
cmp    %rax,%rcx
jne    1180 <compute_pi_baseline+0x80>
movq   %rcx,%xmm4
punpckldq 0xe04(%rip),%xmm4
subpd  0xe0c(%rip),%xmm4
movapd %xmm4,%xmm3
unpckhpd %xmm4,%xmm3
addsd  %xmm4,%xmm3
test   $0x1,%dil
je     122e <compute_pi_baseline+0x12e>
divsd  %xmm2,%xmm3
mulsd  %xmm3,%xmm3
addsd  0xdfa(%rip),%xmm3
divsd  %xmm3,%xmm1
addsd  %xmm1,%xmm0
mulsd  0xdf2(%rip),%xmm0
ret

LLVM IR (-O0):
define double @compute_pi_baseline(i64 %0) {
%2 = alloca i64
%3 = alloca double
%4 = alloca double
%5 = alloca i64
%6 = alloca double
store i64 %0, i64* %2
store double 0.000000e+00, double* %3
%7 = load i64, i64* %2
%8 = uitofp i64 %7 to double
%9 = fdiv double 1.000000e+00, %8
store double %9, double* %4
store i64 0, i64* %5
br label %10
10: ; preds = %27, %1
%11 = load i64, i64* %5
%12 = load i64, i64* %2
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %30
14: ; preds = %10
%15 = load i64, i64* %5
%16 = uitofp i64 %15 to double
%17 = load i64, i64* %2
%18 = uitofp i64 %17 to double
%19 = fdiv double %16, %18
store double %19, double* %6
%20 = load double, double* %4
%21 = load double, double* %6
%22 = load double, double* %6
%23 = call double @llvm.fmuladd.f64(double %21, double %22, double 1.000000e+00)
%24 = fdiv double %20, %23
%25 = load double, double* %3
%26 = fadd double %25, %24
store double %26, double* %3
br label %27
27: ; preds = %14
%28 = load i64, i64* %5
%29 = add i64 %28, 1
store i64 %29, i64* %5
br label %10
30: ; preds = %10
%31 = load double, double* %3
%32 = fmul double %31, 4.000000e+00
ret double %32
}

LLVM IR (-O2):
define double @compute_pi_baseline(i64 %0) {
%2 = uitofp i64 %0 to double
%3 = fdiv double 1.000000e+00, %2
%4 = icmp eq i64 %0, 0
br i1 %4, label %25, label %5
5: ; preds = %1
%6 = and i64 %0, 1
%7 = icmp eq i64 %0, 1
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = and i64 %0, -2
br label %27
10: ; preds = %27
%11 = uitofp i64 %42 to double
br label %12
12: ; preds = %10, %5
%13 = phi double [ undef, %5 ], [ %41, %10 ]
%14 = phi double [ 0.000000e+00, %5 ], [ %41, %10 ]
%15 = phi double [ 0.000000e+00, %5 ], [ %11, %10 ]
%16 = icmp eq i64 %6, 0
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = fdiv double %15, %2
%19 = tail call double @llvm.fmuladd.f64(double %18, double %18, double 1.000000e+00)
%20 = fdiv double %3, %19
%21 = fadd double %14, %20
br label %22
22: ; preds = %12, %17
%23 = phi double [ %13, %12 ], [ %21, %17 ]
%24 = fmul double %23, 4.000000e+00
br label %25
25: ; preds = %22, %1
%26 = phi double [ 0.000000e+00, %1 ], [ %24, %22 ]
ret double %26
27: ; preds = %27, %8
%28 = phi double [ 0.000000e+00, %8 ], [ %41, %27 ]
%29 = phi i64 [ 0, %8 ], [ %42, %27 ]
%30 = phi i64 [ 0, %8 ], [ %43, %27 ]
%31 = uitofp i64 %29 to double
%32 = fdiv double %31, %2
%33 = tail call double @llvm.fmuladd.f64(double %32, double %32, double 1.000000e+00)
%34 = fdiv double %3, %33
%35 = fadd double %28, %34
%36 = or i64 %29, 1
%37 = uitofp i64 %36 to double
%38 = fdiv double %37, %2
%39 = tail call double @llvm.fmuladd.f64(double %38, double %38, double 1.000000e+00)
%40 = fdiv double %3, %39
%41 = fadd double %35, %40
%42 = add nuw i64 %29, 2
%43 = add i64 %30, 2
%44 = icmp eq i64 %43, %9
br i1 %44, label %10, label %27
}