#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 pow(int, int);
long double pi(void) {
  int n = 1;
  long double Pi = 0;
  for (int i = 0; i <= 10000; i++) {
    Pi += (1.0 / n) * pow(-1, i);
    n += 2;
  }
  return Pi * 4;
}


x86 assembly (clang, -O0):
<pi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x1,-0x4(%rbp)
fldz
fstpt  -0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x2710,-0x24(%rbp)
jg     118e <pi+0x7e>
cvtsi2sdl -0x4(%rbp),%xmm1
movsd  0xec3(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x24(%rbp),%esi
mov    $0xffffffff,%edi
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
fldl   -0x30(%rbp)
fldt   -0x20(%rbp)
faddp  %st,%st(1)
fstpt  -0x20(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112b <pi+0x1b>
fldt   -0x20(%rbp)
flds   0xe69(%rip)
fmulp  %st,%st(1)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pi>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
movsd  0xee2(%rip),%xmm1
fldz
fstpt  (%rsp)
xor    %ebx,%ebx
mov    $0x3,%ebp
nopw   0x0(%rax,%rax,1)
movsd  0xec8(%rip),%xmm0
movsd  %xmm1,0x20(%rsp)
divsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    $0xffffffff,%edi
mov    %ebx,%esi
call   1030 <pow@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x30(%rsp)
fldt   (%rsp)
faddl  0x30(%rsp)
add    $0x1,%ebx
cmp    $0x2711,%ebx
je     11c9 <pi+0xb9>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  0xe7f(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
mov    $0xffffffff,%edi
mov    %ebx,%esi
fstpt  0x10(%rsp)
call   1030 <pow@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x28(%rsp)
fldt   0x10(%rsp)
faddl  0x28(%rsp)
fstpt  (%rsp)
movsd  0x20(%rsp),%xmm1
addsd  0xe4a(%rip),%xmm1
add    $0x4,%ebp
add    $0x1,%ebx
jmp    1130 <pi+0x20>
fmuls  0xe41(%rip)
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define x86_fp80 @pi() {
%1 = alloca i32
%2 = alloca x86_fp80
%3 = alloca i32
store i32 1, i32* %1
store x86_fp80 0xK00000000000000000000, x86_fp80* %2
store i32 0, i32* %3
br label %4
4: ; preds = %19, %0
%5 = load i32, i32* %3
%6 = icmp sle i32 %5, 10000
br i1 %6, label %7, label %22
7: ; preds = %4
%8 = load i32, i32* %1
%9 = sitofp i32 %8 to double
%10 = fdiv double 1.000000e+00, %9
%11 = load i32, i32* %3
%12 = call double @pow(i32 -1, i32 %11)
%13 = fmul double %10, %12
%14 = fpext double %13 to x86_fp80
%15 = load x86_fp80, x86_fp80* %2
%16 = fadd x86_fp80 %15, %14
store x86_fp80 %16, x86_fp80* %2
%17 = load i32, i32* %1
%18 = add nsw i32 %17, 2
store i32 %18, i32* %1
br label %19
19: ; preds = %7
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %4
22: ; preds = %4
%23 = load x86_fp80, x86_fp80* %2
%24 = fmul x86_fp80 %23, 0xK40018000000000000000
ret x86_fp80 %24
}

LLVM IR (-O2):
define x86_fp80 @pi() {
br label %3
1: ; preds = %3
%2 = fmul x86_fp80 %12, 0xK40018000000000000000
ret x86_fp80 %2
3: ; preds = %15, %0
%4 = phi i32 [ 0, %0 ], [ %24, %15 ]
%5 = phi x86_fp80 [ 0xK00000000000000000000, %0 ], [ %22, %15 ]
%6 = phi i32 [ 1, %0 ], [ %23, %15 ]
%7 = sitofp i32 %6 to double
%8 = fdiv double 1.000000e+00, %7
%9 = tail call double @pow(i32 -1, i32 %4)
%10 = fmul double %8, %9
%11 = fpext double %10 to x86_fp80
%12 = fadd x86_fp80 %5, %11
%13 = or i32 %4, 1
%14 = icmp eq i32 %13, 10001
br i1 %14, label %1, label %15
15: ; preds = %3
%16 = add nuw nsw i32 %6, 2
%17 = sitofp i32 %16 to double
%18 = fdiv double 1.000000e+00, %17
%19 = tail call double @pow(i32 -1, i32 %13)
%20 = fmul double %18, %19
%21 = fpext double %20 to x86_fp80
%22 = fadd x86_fp80 %12, %21
%23 = add nuw nsw i32 %6, 4
%24 = add nuw nsw i32 %4, 2
br label %3
}