#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 */
int /*<<< orphan*/ printf(char *, unsigned long, double, unsigned long,
                          unsigned long);
double iterate_approx_pi(size_t iterations, int verbose) {
  size_t i;
  unsigned long numerator;
  unsigned long denominator;
  double pi, piover2;
  numerator = 2;
  denominator = 1;
  piover2 = 1.0;
  i = 0;
  while (i < iterations) {
    piover2 *= (((double)numerator) / ((double)denominator));
    pi = (piover2 * 2.0);
    ++i;
    if (verbose) {
      printf("%6lu\t%f\t%6ld\t%6ld\n", (unsigned long)i, pi, numerator,
             denominator);
    }
    if (1 == (i % 2)) {
      denominator += 2;
    } else {
      numerator += 2;
    }
  }
  return pi;
}


x86 assembly (clang, -O0):
<iterate_approx_pi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x2,-0x20(%rbp)
movq   $0x1,-0x28(%rbp)
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    121c <iterate_approx_pi+0x10c>
movq   -0x20(%rbp),%xmm0
movaps 0xeb2(%rip),%xmm3
punpckldq %xmm3,%xmm0
movapd 0xeb6(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movq   -0x28(%rbp),%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe61(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11e4 <iterate_approx_pi+0xd4>
mov    -0x18(%rbp),%rsi
movsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rcx
and    $0x1,%rcx
mov    $0x1,%eax
cmp    %rcx,%rax
jne    120b <iterate_approx_pi+0xfb>
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
jmp    1217 <iterate_approx_pi+0x107>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    1144 <iterate_approx_pi+0x34>
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iterate_approx_pi>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %rdi,%rdi
je     1218 <iterate_approx_pi+0x108>
mov    %esi,%r14d
mov    %rdi,%r15
neg    %r15
mov    $0x2,%r13d
movsd  0xec2(%rip),%xmm4
mov    $0x1,%ebx
lea    0xee6(%rip),%r12
mov    $0x1,%ebp
jmp    1189 <iterate_approx_pi+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x2(%rbp),%rax
lea    0x2(%r13),%rcx
test   $0x1,%bl
cmove  %rcx,%r13
cmovne %rax,%rbp
lea    (%r15,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
je     1218 <iterate_approx_pi+0x108>
movapd %xmm4,%xmm0
movq   %r13,%xmm1
movdqa 0xe76(%rip),%xmm2
punpckldq %xmm2,%xmm1
movapd 0xe7a(%rip),%xmm3
subpd  %xmm3,%xmm1
movapd %xmm1,%xmm4
unpckhpd %xmm1,%xmm4
addsd  %xmm1,%xmm4
movq   %rbp,%xmm1
punpckldq %xmm2,%xmm1
subpd  %xmm3,%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm4
mulsd  %xmm0,%xmm4
movapd %xmm4,%xmm0
addsd  %xmm4,%xmm0
test   %r14d,%r14d
je     1160 <iterate_approx_pi+0x50>
mov    %r12,%rdi
mov    %rbx,%rsi
movapd %xmm0,(%rsp)
movaps (%rsp),%xmm0
mov    %r13,%rdx
mov    %rbp,%rcx
movapd %xmm4,0x10(%rsp)
call   1030 <printf@plt>
movapd (%rsp),%xmm0
movapd 0x10(%rsp),%xmm4
jmp    1160 <iterate_approx_pi+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"%6lu\09%f\09%6ld\09%6ld\0A\00"
define double @iterate_approx_pi(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca double
%9 = alloca double
store i64 %0, i64* %3
store i32 %1, i32* %4
store i64 2, i64* %6
store i64 1, i64* %7
store double 1.000000e+00, double* %9
store i64 0, i64* %5
br label %10
10: ; preds = %44, %2
%11 = load i64, i64* %5
%12 = load i64, i64* %3
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %45
14: ; preds = %10
%15 = load i64, i64* %6
%16 = uitofp i64 %15 to double
%17 = load i64, i64* %7
%18 = uitofp i64 %17 to double
%19 = fdiv double %16, %18
%20 = load double, double* %9
%21 = fmul double %20, %19
store double %21, double* %9
%22 = load double, double* %9
%23 = fmul double %22, 2.000000e+00
store double %23, double* %8
%24 = load i64, i64* %5
%25 = add i64 %24, 1
store i64 %25, i64* %5
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %14
%29 = load i64, i64* %5
%30 = load double, double* %8
%31 = load i64, i64* %6
%32 = load i64, i64* %7
%33 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %29, double %30, i64 %31, i64 %32)
br label %34
34: ; preds = %28, %14
%35 = load i64, i64* %5
%36 = urem i64 %35, 2
%37 = icmp eq i64 1, %36
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i64, i64* %7
%40 = add i64 %39, 2
store i64 %40, i64* %7
br label %44
41: ; preds = %34
%42 = load i64, i64* %6
%43 = add i64 %42, 2
store i64 %43, i64* %6
br label %44
44: ; preds = %41, %38
br label %10
45: ; preds = %10
%46 = load double, double* %8
ret double %46
}

LLVM IR (-O2):
@.str = [19 x i8] c"%6lu\09%f\09%6ld\09%6ld\0A\00"
define double @iterate_approx_pi(i64 %0, i32 %1) {
%3 = icmp eq i64 %0, 0
br i1 %3, label %27, label %4
4: ; preds = %2
%5 = icmp eq i32 %1, 0
br label %6
6: ; preds = %4, %19
%7 = phi double [ 1.000000e+00, %4 ], [ %14, %19 ]
%8 = phi i64 [ 1, %4 ], [ %25, %19 ]
%9 = phi i64 [ 2, %4 ], [ %24, %19 ]
%10 = phi i64 [ 0, %4 ], [ %16, %19 ]
%11 = uitofp i64 %9 to double
%12 = uitofp i64 %8 to double
%13 = fdiv double %11, %12
%14 = fmul double %7, %13
%15 = fmul double %14, 2.000000e+00
%16 = add nuw i64 %10, 1
br i1 %5, label %19, label %17
17: ; preds = %6
%18 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %16, double %15, i64 %9, i64 %8)
br label %19
19: ; preds = %17, %6
%20 = and i64 %16, 1
%21 = icmp eq i64 %20, 0
%22 = add i64 %8, 2
%23 = add i64 %9, 2
%24 = select i1 %21, i64 %23, i64 %9
%25 = select i1 %21, i64 %8, i64 %22
%26 = icmp eq i64 %16, %0
br i1 %26, label %27, label %6
27: ; preds = %19, %2
%28 = phi double [ undef, %2 ], [ %15, %19 ]
ret double %28
}