#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 */
long double pow(double, int);
long double pi(void) {
  long double a, b, c, tempPi;
  int ai, bi, ci;
  a = 1.0;
  b = 1.0;
  c = 0.5;
  ai = 1;
  bi = 1;
  ci = 1;
  long double Pi = a * b * c;
  while (1) {
    tempPi = Pi;
    ai += 2;
    a *= (1.0 * (ai - 2)) / (ai - 1);
    bi += 2;
    b = 1.0 / bi;
    ci += 2;
    c = pow(0.5, ci);
    Pi += a * b * c;
    if (tempPi == Pi)
      break;
  }
  return Pi * 6;
}


x86 assembly (clang, -O0):
<pi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
fld1
fld    %st(0)
fstpt  -0x10(%rbp)
fstpt  -0x20(%rbp)
flds   0xed8(%rip)
fstpt  -0x30(%rbp)
movl   $0x1,-0x44(%rbp)
movl   $0x1,-0x48(%rbp)
movl   $0x1,-0x4c(%rbp)
fldt   -0x10(%rbp)
fldt   -0x20(%rbp)
fmulp  %st,%st(1)
fldt   -0x30(%rbp)
fmulp  %st,%st(1)
fstpt  -0x60(%rbp)
fldt   -0x60(%rbp)
fstpt  -0x40(%rbp)
mov    -0x44(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,%ecx
add    $0xfffffffe,%ecx
cvtsi2sd %ecx,%xmm0
add    $0xffffffff,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
fldl   -0x68(%rbp)
fldt   -0x10(%rbp)
fmulp  %st,%st(1)
fstpt  -0x10(%rbp)
mov    -0x48(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x48(%rbp)
cvtsi2sdl -0x48(%rbp),%xmm1
movsd  0xe6c(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
fldl   -0x70(%rbp)
fstpt  -0x20(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%edi
movsd  0xe51(%rip),%xmm0
call   1030 <pow@plt>
fstpt  -0x30(%rbp)
fldt   -0x10(%rbp)
fldt   -0x20(%rbp)
fmulp  %st,%st(1)
fldt   -0x30(%rbp)
fldt   -0x60(%rbp)
fxch   %st(2)
fmulp  %st,%st(1)
faddp  %st,%st(1)
fstpt  -0x60(%rbp)
fldt   -0x40(%rbp)
fldt   -0x60(%rbp)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    1200 <pi+0xf0>
jp     1200 <pi+0xf0>
jmp    11fb <pi+0xeb>
jmp    1205 <pi+0xf5>
jmp    1150 <pi+0x40>
fldt   -0x60(%rbp)
flds   0xdf6(%rip)
fmulp  %st,%st(1)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pi>:
push   %rbx
sub    $0x30,%rsp
flds   0xee5(%rip)
fld1
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
fxch   %st(1)
fstpt  0x18(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
lea    0x1(%rbx),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
fmull  0x8(%rsp)
fstpt  0x24(%rsp)
add    $0x2,%ebx
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  0xe9d(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0xe93(%rip),%xmm0
mov    %ebx,%edi
call   1030 <pow@plt>
fldt   0x24(%rsp)
fld    %st(0)
fmull  0x10(%rsp)
fmulp  %st,%st(2)
fldt   0x18(%rsp)
fadd   %st,%st(2)
fucomip %st(2),%st
jne    1130 <pi+0x20>
jp     1130 <pi+0x20>
fstp   %st(0)
fmuls  0xe60(%rip)
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define x86_fp80 @pi() {
%1 = alloca x86_fp80
%2 = alloca x86_fp80
%3 = alloca x86_fp80
%4 = alloca x86_fp80
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca x86_fp80
store x86_fp80 0xK3FFF8000000000000000, x86_fp80* %1
store x86_fp80 0xK3FFF8000000000000000, x86_fp80* %2
store x86_fp80 0xK3FFE8000000000000000, x86_fp80* %3
store i32 1, i32* %5
store i32 1, i32* %6
store i32 1, i32* %7
%9 = load x86_fp80, x86_fp80* %1
%10 = load x86_fp80, x86_fp80* %2
%11 = fmul x86_fp80 %9, %10
%12 = load x86_fp80, x86_fp80* %3
%13 = fmul x86_fp80 %11, %12
store x86_fp80 %13, x86_fp80* %8
br label %14
14: ; preds = %0, %49
%15 = load x86_fp80, x86_fp80* %8
store x86_fp80 %15, x86_fp80* %4
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 2
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = sub nsw i32 %18, 2
%20 = sitofp i32 %19 to double
%21 = fmul double 1.000000e+00, %20
%22 = load i32, i32* %5
%23 = sub nsw i32 %22, 1
%24 = sitofp i32 %23 to double
%25 = fdiv double %21, %24
%26 = fpext double %25 to x86_fp80
%27 = load x86_fp80, x86_fp80* %1
%28 = fmul x86_fp80 %27, %26
store x86_fp80 %28, x86_fp80* %1
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 2
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = sitofp i32 %31 to double
%33 = fdiv double 1.000000e+00, %32
%34 = fpext double %33 to x86_fp80
store x86_fp80 %34, x86_fp80* %2
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 2
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = call x86_fp80 @pow(double 5.000000e-01, i32 %37)
store x86_fp80 %38, x86_fp80* %3
%39 = load x86_fp80, x86_fp80* %1
%40 = load x86_fp80, x86_fp80* %2
%41 = fmul x86_fp80 %39, %40
%42 = load x86_fp80, x86_fp80* %3
%43 = load x86_fp80, x86_fp80* %8
%44 = call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %41, x86_fp80 %42, x86_fp80 %43)
store x86_fp80 %44, x86_fp80* %8
%45 = load x86_fp80, x86_fp80* %4
%46 = load x86_fp80, x86_fp80* %8
%47 = fcmp oeq x86_fp80 %45, %46
br i1 %47, label %48, label %49
48: ; preds = %14
br label %50
49: ; preds = %14
br label %14
50: ; preds = %48
%51 = load x86_fp80, x86_fp80* %8
%52 = fmul x86_fp80 %51, 0xK4001C000000000000000
ret x86_fp80 %52
}

LLVM IR (-O2):
define x86_fp80 @pi() {
br label %1
1: ; preds = %1, %0
%2 = phi i32 [ 1, %0 ], [ %5, %1 ]
%3 = phi x86_fp80 [ 0xK3FFF8000000000000000, %0 ], [ %11, %1 ]
%4 = phi x86_fp80 [ 0xK3FFE8000000000000000, %0 ], [ %17, %1 ]
%5 = add nuw nsw i32 %2, 2
%6 = sitofp i32 %2 to double
%7 = add nuw nsw i32 %2, 1
%8 = sitofp i32 %7 to double
%9 = fdiv double %6, %8
%10 = fpext double %9 to x86_fp80
%11 = fmul x86_fp80 %3, %10
%12 = sitofp i32 %5 to double
%13 = fdiv double 1.000000e+00, %12
%14 = fpext double %13 to x86_fp80
%15 = tail call x86_fp80 @pow(double 5.000000e-01, i32 %5)
%16 = fmul x86_fp80 %11, %14
%17 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %16, x86_fp80 %15, x86_fp80 %4)
%18 = fcmp oeq x86_fp80 %4, %17
br i1 %18, label %19, label %1
19: ; preds = %1
%20 = fmul x86_fp80 %17, 0xK4001C000000000000000
ret x86_fp80 %20
}