#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 */
struct timespec {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
double atan(double);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ elapsed_time_hr(struct timespec, struct timespec, char *);
double fabs(double);
double piapprox(int, unsigned int);
int /*<<< orphan*/ printf(char *, double, double);
double recur_piapprox(int, unsigned int);
int /*<<< orphan*/ sleep(int);
int function_calls_recursive(unsigned int N) {
  double pi, exactpi;
  int i = 0, j = 0, rep = N;
  double idx, nn;
  struct timespec start, end;
  if (N > 10000) {
    rep = N / 10000;
    N = 10000;
  }
  nn = (double)N;
  for (i = 1; i <= 1000; i++) {
    idx = (double)i;
    pi = pi + 1.0 / (1.0 + (idx - 0.5) / 1000.0 * (idx - 0.5) / 1000.0);
  }
  clock_gettime(CLOCK_MONOTONIC, &start);
  for (j = 0; j < rep; j++) {
    pi = 0.0;
    for (i = N; i >= 1; i--) {
      idx = (double)i;
      pi = pi + 1.0 / (1.0 + (idx - 0.5) / nn * (idx - 0.5) / nn);
    }
  }
  clock_gettime(CLOCK_MONOTONIC, &end);
  elapsed_time_hr(start, end, "No Function Calls");
  pi = pi * 4.0 / nn;
  exactpi = 4.0 * atan(1.0);
  printf("pi = %f, %% error = %f\n", pi,
         fabs(100.0 * (pi - exactpi) / exactpi));
  sleep(5);
  pi = 0.0;
  for (i = 1; i <= 1000; i++) {
    pi = pi + piapprox(i, 1000);
  }
  clock_gettime(CLOCK_MONOTONIC, &start);
  for (j = 0; j < rep; j++) {
    pi = 0.0;
    for (i = N; i >= 1; i--) {
      pi = pi + piapprox(i, N);
    }
  }
  clock_gettime(CLOCK_MONOTONIC, &end);
  elapsed_time_hr(start, end, "Function Calls");
  pi = pi * 4.0 / nn;
  exactpi = 4.0 * atan(1.0);
  printf("pi = %f, %% error = %f\n", pi,
         fabs(100.0 * (pi - exactpi) / exactpi));
  sleep(5);
  i = 1000;
  pi = recur_piapprox(i, N);
  clock_gettime(CLOCK_MONOTONIC, &start);
  i = N;
  for (j = 0; j < rep; j++) {
    pi = 0.0;
    pi = recur_piapprox(i, N);
  }
  clock_gettime(CLOCK_MONOTONIC, &end);
  elapsed_time_hr(start, end, "Recursive Function Calls");
  pi = pi * 4.0 / nn;
  exactpi = 4.0 * atan(1.0);
  printf("pi = %f, %% error = %f\n", pi,
         fabs(100.0 * (pi - exactpi) / exactpi));
  return 0;
}


x86 assembly (clang, -O0):
<function_calls_recursive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x2710,-0x4(%rbp)
jbe    11b2 <function_calls_recursive+0x42>
mov    -0x4(%rbp),%eax
mov    $0x2710,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x24(%rbp)
movl   $0x2710,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jg     124f <function_calls_recursive+0xdf>
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  0xe39(%rip),%xmm2
subsd  %xmm2,%xmm1
movsd  0xe35(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  0xe1c(%rip),%xmm3
subsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
movsd  0xe14(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xdf8(%rip),%xmm2
addsd  %xmm1,%xmm2
movsd  0xdec(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c6 <function_calls_recursive+0x56>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
call   1040 <clock_gettime@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    130d <function_calls_recursive+0x19d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jl     12fa <function_calls_recursive+0x18a>
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  0xd80(%rip),%xmm2
subsd  %xmm2,%xmm1
divsd  -0x38(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  0xd6a(%rip),%xmm3
subsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
divsd  -0x38(%rbp),%xmm1
movsd  0xd4d(%rip),%xmm2
addsd  %xmm1,%xmm2
movsd  0xd41(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1282 <function_calls_recursive+0x112>
jmp    12ff <function_calls_recursive+0x18f>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1268 <function_calls_recursive+0xf8>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x40(%rbp),%edi
mov    -0x48(%rbp),%esi
lea    0xd0c(%rip),%rdx
call   1030 <elapsed_time_hr@plt>
movsd  0xcdf(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xcd0(%rip),%xmm0
call   1080 <atan@plt>
movaps %xmm0,%xmm1
movsd  0xcb8(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
subsd  -0x18(%rbp),%xmm2
movsd  0xc90(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  -0x18(%rbp),%xmm1
movaps 0xc70(%rip),%xmm2
pand   %xmm2,%xmm1
lea    0xcaf(%rip),%rdi
call   1050 <printf@plt>
mov    $0x5,%edi
call   1090 <sleep@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jg     13fc <function_calls_recursive+0x28c>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x3e8,%esi
call   1070 <piapprox@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    13b9 <function_calls_recursive+0x249>
mov    0x2be5(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
call   1040 <clock_gettime@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1480 <function_calls_recursive+0x310>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jl     146d <function_calls_recursive+0x2fd>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1070 <piapprox@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    142f <function_calls_recursive+0x2bf>
jmp    1472 <function_calls_recursive+0x302>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1415 <function_calls_recursive+0x2a5>
mov    0x2b61(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x40(%rbp),%edi
mov    -0x48(%rbp),%esi
lea    0xbcd(%rip),%rdx
call   1030 <elapsed_time_hr@plt>
movsd  0xb6c(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xb5d(%rip),%xmm0
call   1080 <atan@plt>
movaps %xmm0,%xmm1
movsd  0xb45(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
subsd  -0x18(%rbp),%xmm2
movsd  0xb1d(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  -0x18(%rbp),%xmm1
movaps 0xafd(%rip),%xmm2
pand   %xmm2,%xmm1
lea    0xb3c(%rip),%rdi
call   1050 <printf@plt>
mov    $0x5,%edi
call   1090 <sleep@plt>
movl   $0x3e8,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1060 <recur_piapprox@plt>
movsd  %xmm0,-0x10(%rbp)
mov    0x2aad(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1585 <function_calls_recursive+0x415>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1060 <recur_piapprox@plt>
movsd  %xmm0,-0x10(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1553 <function_calls_recursive+0x3e3>
mov    0x2a5c(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x40(%rbp),%edi
mov    -0x48(%rbp),%esi
lea    0xabe(%rip),%rdx
call   1030 <elapsed_time_hr@plt>
movsd  0xa67(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xa58(%rip),%xmm0
call   1080 <atan@plt>
movaps %xmm0,%xmm1
movsd  0xa40(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
subsd  -0x18(%rbp),%xmm2
movsd  0xa18(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  -0x18(%rbp),%xmm1
movaps 0x9f8(%rip),%xmm2
pand   %xmm2,%xmm1
lea    0xa37(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<function_calls_recursive>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edi,%r14d
cmp    $0x2711,%edi
mov    $0x2710,%r12d
cmovb  %edi,%r12d
movsd  0xe69(%rip),%xmm0
mov    $0x3e8,%eax
movsd  0xe6c(%rip),%xmm1
movapd %xmm0,%xmm2
nopl   0x0(%rax,%rax,1)
movapd %xmm2,%xmm3
addsd  0xe4c(%rip),%xmm3
movapd %xmm3,%xmm4
divsd  %xmm1,%xmm4
mulsd  %xmm3,%xmm4
divsd  %xmm1,%xmm4
addsd  %xmm0,%xmm4
movapd %xmm0,%xmm3
divsd  %xmm4,%xmm3
addsd  %xmm3,%xmm5
addsd  %xmm0,%xmm2
add    $0xffffffff,%eax
jne    11b0 <function_calls_recursive+0x40>
cmp    $0x2711,%r14d
movsd  %xmm5,(%rsp)
jb     1204 <function_calls_recursive+0x94>
mov    %r14d,%eax
mov    $0xd1b71759,%r14d
imul   %rax,%r14
shr    $0x2d,%r14
mov    %r12d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x18(%rsp)
mov    0x2dcc(%rip),%r15
mov    (%r15),%edi
lea    0x10(%rsp),%rsi
call   1040 <clock_gettime@plt>
movsd  0x18(%rsp),%xmm3
test   %r14d,%r14d
movsd  (%rsp),%xmm4
movsd  0xdc9(%rip),%xmm5
jle    12a7 <function_calls_recursive+0x137>
xor    %eax,%eax
movsd  0xdb5(%rip),%xmm0
jmp    1258 <function_calls_recursive+0xe8>
nopl   (%rax)
add    $0x1,%eax
cmp    %r14d,%eax
je     12a7 <function_calls_recursive+0x137>
xorpd  %xmm4,%xmm4
test   %r12d,%r12d
jle    1250 <function_calls_recursive+0xe0>
mov    %r12d,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
addsd  %xmm5,%xmm1
movapd %xmm1,%xmm2
divsd  %xmm3,%xmm2
mulsd  %xmm1,%xmm2
divsd  %xmm3,%xmm2
addsd  %xmm0,%xmm2
movapd %xmm0,%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm4
lea    -0x1(%rcx),%edx
cmp    $0x1,%ecx
mov    %edx,%ecx
ja     1270 <function_calls_recursive+0x100>
jmp    1250 <function_calls_recursive+0xe0>
movsd  %xmm4,(%rsp)
mov    (%r15),%edi
lea    0x8(%rsp),%rsi
call   1040 <clock_gettime@plt>
mov    0x10(%rsp),%edi
mov    0x8(%rsp),%esi
lea    0xd88(%rip),%rdx
call   1030 <elapsed_time_hr@plt>
movsd  (%rsp),%xmm0
mulsd  0xd3e(%rip),%xmm0
divsd  0x18(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0xd13(%rip),%xmm0
call   1080 <atan@plt>
movsd  0xd26(%rip),%xmm1
movsd  (%rsp),%xmm0
addsd  %xmm0,%xmm1
mulsd  0xd1d(%rip),%xmm1
divsd  0xd1d(%rip),%xmm1
andpd  0xd25(%rip),%xmm1
lea    0xd40(%rip),%rdi
call   1050 <printf@plt>
mov    $0x5,%edi
call   1090 <sleep@plt>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mov    $0x1,%ebp
nop
mov    %ebp,%edi
mov    $0x3e8,%esi
call   1070 <piapprox@plt>
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
add    $0x1,%ebp
cmp    $0x3e9,%ebp
jne    1340 <function_calls_recursive+0x1d0>
mov    (%r15),%edi
lea    0x10(%rsp),%rsi
call   1040 <clock_gettime@plt>
test   %r14d,%r14d
movsd  (%rsp),%xmm0
jle    13ce <function_calls_recursive+0x25e>
xor    %ebx,%ebx
jmp    1388 <function_calls_recursive+0x218>
add    $0x1,%ebx
cmp    %r14d,%ebx
je     13ce <function_calls_recursive+0x25e>
xorpd  %xmm0,%xmm0
test   %r12d,%r12d
jle    1380 <function_calls_recursive+0x210>
mov    %r12d,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm0,(%rsp)
mov    %ebp,%edi
mov    %r12d,%esi
call   1070 <piapprox@plt>
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
lea    -0x1(%rbp),%eax
cmp    $0x1,%ebp
mov    %eax,%ebp
ja     13a0 <function_calls_recursive+0x230>
jmp    1380 <function_calls_recursive+0x210>
movsd  %xmm0,(%rsp)
mov    (%r15),%edi
lea    0x8(%rsp),%rsi
call   1040 <clock_gettime@plt>
mov    0x10(%rsp),%edi
mov    0x8(%rsp),%esi
lea    0xc95(%rip),%rdx
call   1030 <elapsed_time_hr@plt>
movsd  (%rsp),%xmm0
mulsd  0xc17(%rip),%xmm0
divsd  0x18(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0xbec(%rip),%xmm0
call   1080 <atan@plt>
movsd  0xbff(%rip),%xmm1
movsd  (%rsp),%xmm0
addsd  %xmm0,%xmm1
mulsd  0xbf6(%rip),%xmm1
divsd  0xbf6(%rip),%xmm1
andpd  0xbfe(%rip),%xmm1
lea    0xc19(%rip),%rdi
call   1050 <printf@plt>
mov    $0x5,%edi
call   1090 <sleep@plt>
mov    $0x3e8,%edi
mov    %r12d,%esi
call   1060 <recur_piapprox@plt>
movsd  %xmm0,(%rsp)
mov    (%r15),%edi
lea    0x10(%rsp),%rsi
call   1040 <clock_gettime@plt>
test   %r14d,%r14d
jle    1496 <function_calls_recursive+0x326>
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %r12d,%esi
call   1060 <recur_piapprox@plt>
add    $0xffffffff,%r14d
jne    1480 <function_calls_recursive+0x310>
movsd  %xmm0,(%rsp)
mov    (%r15),%edi
lea    0x8(%rsp),%rsi
call   1040 <clock_gettime@plt>
mov    0x10(%rsp),%edi
mov    0x8(%rsp),%esi
lea    0xbc8(%rip),%rdx
call   1030 <elapsed_time_hr@plt>
movsd  (%rsp),%xmm0
mulsd  0xb54(%rip),%xmm0
divsd  0x18(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0xb29(%rip),%xmm0
call   1080 <atan@plt>
movsd  0xb3c(%rip),%xmm1
movsd  (%rsp),%xmm0
addsd  %xmm0,%xmm1
mulsd  0xb33(%rip),%xmm1
divsd  0xb33(%rip),%xmm1
andpd  0xb3b(%rip),%xmm1
lea    0xb56(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [18 x i8] c"No Function Calls\00"
@.str.1 = [24 x i8] c"pi = %f, %% error = %f\0A\00"
@.str.2 = [15 x i8] c"Function Calls\00"
@.str.3 = [25 x i8] c"Recursive Function Calls\00"
define i32 @function_calls_recursive(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca %struct.timespec
%11 = alloca %struct.timespec
store i32 %0, i32* %2
store i32 0, i32* %5
store i32 0, i32* %6
%12 = load i32, i32* %2
store i32 %12, i32* %7
%13 = load i32, i32* %2
%14 = icmp ugt i32 %13, 10000
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = load i32, i32* %2
%17 = udiv i32 %16, 10000
store i32 %17, i32* %7
store i32 10000, i32* %2
br label %18
18: ; preds = %15, %1
%19 = load i32, i32* %2
%20 = uitofp i32 %19 to double
store double %20, double* %9
store i32 1, i32* %5
br label %21
21: ; preds = %38, %18
%22 = load i32, i32* %5
%23 = icmp sle i32 %22, 1000
br i1 %23, label %24, label %41
24: ; preds = %21
%25 = load i32, i32* %5
%26 = sitofp i32 %25 to double
store double %26, double* %8
%27 = load double, double* %3
%28 = load double, double* %8
%29 = fsub double %28, 5.000000e-01
%30 = fdiv double %29, 1.000000e+03
%31 = load double, double* %8
%32 = fsub double %31, 5.000000e-01
%33 = fmul double %30, %32
%34 = fdiv double %33, 1.000000e+03
%35 = fadd double 1.000000e+00, %34
%36 = fdiv double 1.000000e+00, %35
%37 = fadd double %27, %36
store double %37, double* %3
br label %38
38: ; preds = %24
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
br label %21
41: ; preds = %21
%42 = load i32, i32* @CLOCK_MONOTONIC
%43 = call i32 @clock_gettime(i32 %42, %struct.timespec* %10)
store i32 0, i32* %6
br label %44
44: ; preds = %73, %41
%45 = load i32, i32* %6
%46 = load i32, i32* %7
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %76
48: ; preds = %44
store double 0.000000e+00, double* %3
%49 = load i32, i32* %2
store i32 %49, i32* %5
br label %50
50: ; preds = %69, %48
%51 = load i32, i32* %5
%52 = icmp sge i32 %51, 1
br i1 %52, label %53, label %72
53: ; preds = %50
%54 = load i32, i32* %5
%55 = sitofp i32 %54 to double
store double %55, double* %8
%56 = load double, double* %3
%57 = load double, double* %8
%58 = fsub double %57, 5.000000e-01
%59 = load double, double* %9
%60 = fdiv double %58, %59
%61 = load double, double* %8
%62 = fsub double %61, 5.000000e-01
%63 = fmul double %60, %62
%64 = load double, double* %9
%65 = fdiv double %63, %64
%66 = fadd double 1.000000e+00, %65
%67 = fdiv double 1.000000e+00, %66
%68 = fadd double %56, %67
store double %68, double* %3
br label %69
69: ; preds = %53
%70 = load i32, i32* %5
%71 = add nsw i32 %70, -1
store i32 %71, i32* %5
br label %50
72: ; preds = %50
br label %73
73: ; preds = %72
%74 = load i32, i32* %6
%75 = add nsw i32 %74, 1
store i32 %75, i32* %6
br label %44
76: ; preds = %44
%77 = load i32, i32* @CLOCK_MONOTONIC
%78 = call i32 @clock_gettime(i32 %77, %struct.timespec* %11)
%79 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 0
%80 = load i32, i32* %79
%81 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 0
%82 = load i32, i32* %81
%83 = call i32 @elapsed_time_hr(i32 %80, i32 %82, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%84 = load double, double* %3
%85 = fmul double %84, 4.000000e+00
%86 = load double, double* %9
%87 = fdiv double %85, %86
store double %87, double* %3
%88 = call double @atan(double 1.000000e+00)
%89 = fmul double 4.000000e+00, %88
store double %89, double* %4
%90 = load double, double* %3
%91 = load double, double* %3
%92 = load double, double* %4
%93 = fsub double %91, %92
%94 = fmul double 1.000000e+02, %93
%95 = load double, double* %4
%96 = fdiv double %94, %95
%97 = call double @llvm.fabs.f64(double %96)
%98 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), double %90, double %97)
%99 = call i32 @sleep(i32 5)
store double 0.000000e+00, double* %3
store i32 1, i32* %5
br label %100
100: ; preds = %108, %76
%101 = load i32, i32* %5
%102 = icmp sle i32 %101, 1000
br i1 %102, label %103, label %111
103: ; preds = %100
%104 = load double, double* %3
%105 = load i32, i32* %5
%106 = call double @piapprox(i32 %105, i32 1000)
%107 = fadd double %104, %106
store double %107, double* %3
br label %108
108: ; preds = %103
%109 = load i32, i32* %5
%110 = add nsw i32 %109, 1
store i32 %110, i32* %5
br label %100
111: ; preds = %100
%112 = load i32, i32* @CLOCK_MONOTONIC
%113 = call i32 @clock_gettime(i32 %112, %struct.timespec* %10)
store i32 0, i32* %6
br label %114
114: ; preds = %133, %111
%115 = load i32, i32* %6
%116 = load i32, i32* %7
%117 = icmp slt i32 %115, %116
br i1 %117, label %118, label %136
118: ; preds = %114
store double 0.000000e+00, double* %3
%119 = load i32, i32* %2
store i32 %119, i32* %5
br label %120
120: ; preds = %129, %118
%121 = load i32, i32* %5
%122 = icmp sge i32 %121, 1
br i1 %122, label %123, label %132
123: ; preds = %120
%124 = load double, double* %3
%125 = load i32, i32* %5
%126 = load i32, i32* %2
%127 = call double @piapprox(i32 %125, i32 %126)
%128 = fadd double %124, %127
store double %128, double* %3
br label %129
129: ; preds = %123
%130 = load i32, i32* %5
%131 = add nsw i32 %130, -1
store i32 %131, i32* %5
br label %120
132: ; preds = %120
br label %133
133: ; preds = %132
%134 = load i32, i32* %6
%135 = add nsw i32 %134, 1
store i32 %135, i32* %6
br label %114
136: ; preds = %114
%137 = load i32, i32* @CLOCK_MONOTONIC
%138 = call i32 @clock_gettime(i32 %137, %struct.timespec* %11)
%139 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 0
%140 = load i32, i32* %139
%141 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 0
%142 = load i32, i32* %141
%143 = call i32 @elapsed_time_hr(i32 %140, i32 %142, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%144 = load double, double* %3
%145 = fmul double %144, 4.000000e+00
%146 = load double, double* %9
%147 = fdiv double %145, %146
store double %147, double* %3
%148 = call double @atan(double 1.000000e+00)
%149 = fmul double 4.000000e+00, %148
store double %149, double* %4
%150 = load double, double* %3
%151 = load double, double* %3
%152 = load double, double* %4
%153 = fsub double %151, %152
%154 = fmul double 1.000000e+02, %153
%155 = load double, double* %4
%156 = fdiv double %154, %155
%157 = call double @llvm.fabs.f64(double %156)
%158 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), double %150, double %157)
%159 = call i32 @sleep(i32 5)
store i32 1000, i32* %5
%160 = load i32, i32* %5
%161 = load i32, i32* %2
%162 = call double @recur_piapprox(i32 %160, i32 %161)
store double %162, double* %3
%163 = load i32, i32* @CLOCK_MONOTONIC
%164 = call i32 @clock_gettime(i32 %163, %struct.timespec* %10)
%165 = load i32, i32* %2
store i32 %165, i32* %5
store i32 0, i32* %6
br label %166
166: ; preds = %174, %136
%167 = load i32, i32* %6
%168 = load i32, i32* %7
%169 = icmp slt i32 %167, %168
br i1 %169, label %170, label %177
170: ; preds = %166
store double 0.000000e+00, double* %3
%171 = load i32, i32* %5
%172 = load i32, i32* %2
%173 = call double @recur_piapprox(i32 %171, i32 %172)
store double %173, double* %3
br label %174
174: ; preds = %170
%175 = load i32, i32* %6
%176 = add nsw i32 %175, 1
store i32 %176, i32* %6
br label %166
177: ; preds = %166
%178 = load i32, i32* @CLOCK_MONOTONIC
%179 = call i32 @clock_gettime(i32 %178, %struct.timespec* %11)
%180 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 0
%181 = load i32, i32* %180
%182 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 0
%183 = load i32, i32* %182
%184 = call i32 @elapsed_time_hr(i32 %181, i32 %183, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%185 = load double, double* %3
%186 = fmul double %185, 4.000000e+00
%187 = load double, double* %9
%188 = fdiv double %186, %187
store double %188, double* %3
%189 = call double @atan(double 1.000000e+00)
%190 = fmul double 4.000000e+00, %189
store double %190, double* %4
%191 = load double, double* %3
%192 = load double, double* %3
%193 = load double, double* %4
%194 = fsub double %192, %193
%195 = fmul double 1.000000e+02, %194
%196 = load double, double* %4
%197 = fdiv double %195, %196
%198 = call double @llvm.fabs.f64(double %197)
%199 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), double %191, double %198)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [18 x i8] c"No Function Calls\00"
@.str.1 = [24 x i8] c"pi = %f, %% error = %f\0A\00"
@.str.2 = [15 x i8] c"Function Calls\00"
@.str.3 = [25 x i8] c"Recursive Function Calls\00"
define i32 @function_calls_recursive(i32 %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %2 to i8*
%5 = bitcast %struct.timespec* %3 to i8*
%6 = icmp ugt i32 %0, 10000
%7 = udiv i32 %0, 10000
%8 = select i1 %6, i32 10000, i32 %0
br label %9
9: ; preds = %1, %9
%10 = phi i32 [ 1, %1 ], [ %20, %9 ]
%11 = phi double [ undef, %1 ], [ %19, %9 ]
%12 = sitofp i32 %10 to double
%13 = fadd double %12, -5.000000e-01
%14 = fdiv double %13, 1.000000e+03
%15 = fmul double %13, %14
%16 = fdiv double %15, 1.000000e+03
%17 = fadd double %16, 1.000000e+00
%18 = fdiv double 1.000000e+00, %17
%19 = fadd double %11, %18
%20 = add nuw nsw i32 %10, 1
%21 = icmp eq i32 %20, 1001
br i1 %21, label %22, label %9
22: ; preds = %9
%23 = select i1 %6, i32 %7, i32 %0
%24 = uitofp i32 %8 to double
%25 = load i32, i32* @CLOCK_MONOTONIC
%26 = call i32 @clock_gettime(i32 %25, %struct.timespec* %2)
%27 = icmp sgt i32 %23, 0
br i1 %27, label %28, label %49
28: ; preds = %22
%29 = icmp sgt i32 %8, 0
br label %30
30: ; preds = %28, %45
%31 = phi i32 [ 0, %28 ], [ %47, %45 ]
br i1 %29, label %32, label %45
32: ; preds = %30, %32
%33 = phi i32 [ %43, %32 ], [ %8, %30 ]
%34 = phi double [ %42, %32 ], [ 0.000000e+00, %30 ]
%35 = sitofp i32 %33 to double
%36 = fadd double %35, -5.000000e-01
%37 = fdiv double %36, %24
%38 = fmul double %36, %37
%39 = fdiv double %38, %24
%40 = fadd double %39, 1.000000e+00
%41 = fdiv double 1.000000e+00, %40
%42 = fadd double %34, %41
%43 = add nsw i32 %33, -1
%44 = icmp ugt i32 %33, 1
br i1 %44, label %32, label %45
45: ; preds = %32, %30
%46 = phi double [ 0.000000e+00, %30 ], [ %42, %32 ]
%47 = add nuw nsw i32 %31, 1
%48 = icmp eq i32 %47, %23
br i1 %48, label %49, label %30
49: ; preds = %45, %22
%50 = phi double [ %19, %22 ], [ %46, %45 ]
%51 = load i32, i32* @CLOCK_MONOTONIC
%52 = call i32 @clock_gettime(i32 %51, %struct.timespec* %3)
%53 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%54 = load i32, i32* %53
%55 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%56 = load i32, i32* %55
%57 = call i32 @elapsed_time_hr(i32 %54, i32 %56, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%58 = fmul double %50, 4.000000e+00
%59 = fdiv double %58, %24
%60 = call double @atan(double 1.000000e+00)
%61 = fadd double %59, 0xC00921FB54442D18
%62 = fmul double %61, 1.000000e+02
%63 = fdiv double %62, 0x400921FB54442D18
%64 = call double @llvm.fabs.f64(double %63)
%65 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), double %59, double %64)
%66 = call i32 @sleep(i32 5)
br label %67
67: ; preds = %49, %67
%68 = phi i32 [ 1, %49 ], [ %72, %67 ]
%69 = phi double [ 0.000000e+00, %49 ], [ %71, %67 ]
%70 = call double @piapprox(i32 %68, i32 1000)
%71 = fadd double %69, %70
%72 = add nuw nsw i32 %68, 1
%73 = icmp eq i32 %72, 1001
br i1 %73, label %74, label %67
74: ; preds = %67
%75 = load i32, i32* @CLOCK_MONOTONIC
%76 = call i32 @clock_gettime(i32 %75, %struct.timespec* %2)
br i1 %27, label %77, label %92
77: ; preds = %74
%78 = icmp sgt i32 %8, 0
br label %79
79: ; preds = %77, %88
%80 = phi i32 [ 0, %77 ], [ %90, %88 ]
br i1 %78, label %81, label %88
81: ; preds = %79, %81
%82 = phi i32 [ %86, %81 ], [ %8, %79 ]
%83 = phi double [ %85, %81 ], [ 0.000000e+00, %79 ]
%84 = call double @piapprox(i32 %82, i32 %8)
%85 = fadd double %83, %84
%86 = add nsw i32 %82, -1
%87 = icmp ugt i32 %82, 1
br i1 %87, label %81, label %88
88: ; preds = %81, %79
%89 = phi double [ 0.000000e+00, %79 ], [ %85, %81 ]
%90 = add nuw nsw i32 %80, 1
%91 = icmp eq i32 %90, %23
br i1 %91, label %92, label %79
92: ; preds = %88, %74
%93 = phi double [ %71, %74 ], [ %89, %88 ]
%94 = load i32, i32* @CLOCK_MONOTONIC
%95 = call i32 @clock_gettime(i32 %94, %struct.timespec* %3)
%96 = load i32, i32* %53
%97 = load i32, i32* %55
%98 = call i32 @elapsed_time_hr(i32 %96, i32 %97, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%99 = fmul double %93, 4.000000e+00
%100 = fdiv double %99, %24
%101 = call double @atan(double 1.000000e+00)
%102 = fadd double %100, 0xC00921FB54442D18
%103 = fmul double %102, 1.000000e+02
%104 = fdiv double %103, 0x400921FB54442D18
%105 = call double @llvm.fabs.f64(double %104)
%106 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), double %100, double %105)
%107 = call i32 @sleep(i32 5)
%108 = call double @recur_piapprox(i32 1000, i32 %8)
%109 = load i32, i32* @CLOCK_MONOTONIC
%110 = call i32 @clock_gettime(i32 %109, %struct.timespec* %2)
br i1 %27, label %111, label %116
111: ; preds = %92, %111
%112 = phi i32 [ %114, %111 ], [ 0, %92 ]
%113 = call double @recur_piapprox(i32 %8, i32 %8)
%114 = add nuw nsw i32 %112, 1
%115 = icmp eq i32 %114, %23
br i1 %115, label %116, label %111
116: ; preds = %111, %92
%117 = phi double [ %108, %92 ], [ %113, %111 ]
%118 = load i32, i32* @CLOCK_MONOTONIC
%119 = call i32 @clock_gettime(i32 %118, %struct.timespec* %3)
%120 = load i32, i32* %53
%121 = load i32, i32* %55
%122 = call i32 @elapsed_time_hr(i32 %120, i32 %121, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%123 = fmul double %117, 4.000000e+00
%124 = fdiv double %123, %24
%125 = call double @atan(double 1.000000e+00)
%126 = fadd double %124, 0xC00921FB54442D18
%127 = fmul double %126, 1.000000e+02
%128 = fdiv double %127, 0x400921FB54442D18
%129 = call double @llvm.fabs.f64(double %128)
%130 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), double %124, double %129)
ret i32 0
}