#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 */
typedef int /*<<< orphan*/ mpf_t;

/* Variables and functions */
int /*<<< orphan*/ mpf_add(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpf_div(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpf_init2(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpf_mul_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpf_out_str(int /*<<< orphan*/, int, int /*<<< orphan*/,
                               int /*<<< orphan*/);
int /*<<< orphan*/ mpf_set_si(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpf_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
void gregoryLeibniz(unsigned long long times) {
  mpf_t pi, term, numer;
  mpf_init2(pi, 1024);
  mpf_init2(term, 1024);
  mpf_init2(numer, 1024);
  int a;
  for (a = 0; a < times; a++) {
    mpf_set_si(numer, (a % 2) ? (-1) : (1));
    mpf_set_ui(term, (2 * a + 1));
    mpf_div(term, numer, term);
    mpf_add(pi, pi, term);
  }
  mpf_mul_ui(pi, pi, 4);
  mpf_out_str(stdout, 10, 0, pi);
  printf("\n");
}


x86 assembly (clang, -O0):
<gregoryLeibniz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x400,%esi
call   10a0 <mpf_init2@plt>
mov    -0x10(%rbp),%edi
mov    $0x400,%esi
call   10a0 <mpf_init2@plt>
mov    -0x14(%rbp),%edi
mov    $0x400,%esi
call   10a0 <mpf_init2@plt>
movl   $0x0,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    1226 <gregoryLeibniz+0xa6>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    $0x1,%esi
mov    $0xffffffff,%eax
cmp    $0x0,%edx
cmovne %eax,%esi
call   1040 <mpf_set_si@plt>
mov    -0x10(%rbp),%edi
mov    -0x18(%rbp),%esi
shl    $0x1,%esi
add    $0x1,%esi
call   1060 <mpf_set_ui@plt>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1090 <mpf_div@plt>
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <mpf_add@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ba <gregoryLeibniz+0x3a>
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x4,%edx
call   1070 <mpf_mul_ui@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%ecx
mov    $0xa,%esi
xor    %edx,%edx
call   1080 <mpf_out_str@plt>
lea    0xdab(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gregoryLeibniz>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x400,%esi
call   10a0 <mpf_init2@plt>
mov    $0x400,%esi
call   10a0 <mpf_init2@plt>
mov    $0x400,%esi
call   10a0 <mpf_init2@plt>
test   %r14,%r14
je     11ef <gregoryLeibniz+0x6f>
mov    $0x1,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
and    $0x1,%eax
neg    %rax
sbb    %esi,%esi
or     $0x1,%esi
call   1040 <mpf_set_si@plt>
mov    %ebp,%esi
call   1060 <mpf_set_ui@plt>
call   1090 <mpf_div@plt>
call   1050 <mpf_add@plt>
add    $0x1,%rbx
add    $0x2,%ebp
cmp    %rbx,%r14
jne    11c0 <gregoryLeibniz+0x40>
mov    $0x4,%edx
call   1070 <mpf_mul_ui@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    $0xa,%esi
xor    %edx,%edx
call   1080 <mpf_out_str@plt>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [2 x i8] c"\0A\00"
define void @gregoryLeibniz(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i64 %0, i64* %2
%7 = load i32, i32* %3
%8 = call i32 @mpf_init2(i32 %7, i32 1024)
%9 = load i32, i32* %4
%10 = call i32 @mpf_init2(i32 %9, i32 1024)
%11 = load i32, i32* %5
%12 = call i32 @mpf_init2(i32 %11, i32 1024)
store i32 0, i32* %6
br label %13
13: ; preds = %39, %1
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = load i64, i64* %2
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %42
18: ; preds = %13
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = srem i32 %20, 2
%22 = icmp ne i32 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i32 -1, i32 1
%25 = call i32 @mpf_set_si(i32 %19, i32 %24)
%26 = load i32, i32* %4
%27 = load i32, i32* %6
%28 = mul nsw i32 2, %27
%29 = add nsw i32 %28, 1
%30 = call i32 @mpf_set_ui(i32 %26, i32 %29)
%31 = load i32, i32* %4
%32 = load i32, i32* %5
%33 = load i32, i32* %4
%34 = call i32 @mpf_div(i32 %31, i32 %32, i32 %33)
%35 = load i32, i32* %3
%36 = load i32, i32* %3
%37 = load i32, i32* %4
%38 = call i32 @mpf_add(i32 %35, i32 %36, i32 %37)
br label %39
39: ; preds = %18
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %13
42: ; preds = %13
%43 = load i32, i32* %3
%44 = load i32, i32* %3
%45 = call i32 @mpf_mul_ui(i32 %43, i32 %44, i32 4)
%46 = load i32, i32* @stdout
%47 = load i32, i32* %3
%48 = call i32 @mpf_out_str(i32 %46, i32 10, i32 0, i32 %47)
%49 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
define void @gregoryLeibniz(i64 %0) {
%2 = tail call i32 @mpf_init2(i32 undef, i32 1024)
%3 = tail call i32 @mpf_init2(i32 undef, i32 1024)
%4 = tail call i32 @mpf_init2(i32 undef, i32 1024)
%5 = icmp eq i64 %0, 0
br i1 %5, label %20, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %18, %6 ], [ 0, %1 ]
%8 = and i64 %7, 1
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i32 1, i32 -1
%11 = tail call i32 @mpf_set_si(i32 undef, i32 %10)
%12 = trunc i64 %7 to i32
%13 = shl i32 %12, 1
%14 = or i32 %13, 1
%15 = tail call i32 @mpf_set_ui(i32 undef, i32 %14)
%16 = tail call i32 @mpf_div(i32 undef, i32 undef, i32 undef)
%17 = tail call i32 @mpf_add(i32 undef, i32 undef, i32 undef)
%18 = add nuw i64 %7, 1
%19 = icmp eq i64 %18, %0
br i1 %19, label %20, label %6
20: ; preds = %6, %1
%21 = tail call i32 @mpf_mul_ui(i32 undef, i32 undef, i32 4)
%22 = load i32, i32* @stdout
%23 = tail call i32 @mpf_out_str(i32 %22, i32 10, i32 0, i32 undef)
%24 = tail call i32 @putchar(i32 10)
ret void
}