#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);
    if (!(a % (times / 100)))
      printf("%d\n", a / (times / 100));
  }
  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    $0x30,%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    128a <gregoryLeibniz+0x10a>
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>
movslq -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x64,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    1277 <gregoryLeibniz+0xf7>
movslq -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x64,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,%rsi
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    127c <gregoryLeibniz+0xfc>
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    0x2d3f(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%ecx
mov    $0xa,%esi
xor    %edx,%edx
call   1080 <mpf_out_str@plt>
lea    0xd49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gregoryLeibniz>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
mov    $0x400,%esi
call   10b0 <mpf_init2@plt>
mov    $0x400,%esi
call   10b0 <mpf_init2@plt>
mov    $0x400,%esi
call   10b0 <mpf_init2@plt>
test   %r14,%r14
je     125b <gregoryLeibniz+0xcb>
mov    %r14,%rax
shr    $0x2,%rax
movabs $0x28f5c28f5c28f5c3,%rcx
c2 f5 28
mul    %rcx
mov    %rdx,%r12
shr    $0x2,%r12
mov    $0x1,%ebp
lea    0xe17(%rip),%r15
xor    %ebx,%ebx
jmp    11fc <gregoryLeibniz+0x6c>
nopl   (%rax)
add    $0x1,%rbx
add    $0x2,%ebp
cmp    %rbx,%r14
je     125b <gregoryLeibniz+0xcb>
mov    %ebx,%eax
and    $0x1,%eax
neg    %rax
sbb    %esi,%esi
or     $0x1,%esi
call   1050 <mpf_set_si@plt>
mov    %ebp,%esi
call   1070 <mpf_set_ui@plt>
call   10a0 <mpf_div@plt>
call   1060 <mpf_add@plt>
mov    %rbx,%rax
or     %r12,%rax
shr    $0x20,%rax
je     1240 <gregoryLeibniz+0xb0>
mov    %rbx,%rax
xor    %edx,%edx
div    %r12
test   %rdx,%rdx
jne    11f0 <gregoryLeibniz+0x60>
jmp    124c <gregoryLeibniz+0xbc>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %r12d
test   %rdx,%rdx
jne    11f0 <gregoryLeibniz+0x60>
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f0 <gregoryLeibniz+0x60>
mov    $0x4,%edx
call   1080 <mpf_mul_ui@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
mov    $0xa,%esi
xor    %edx,%edx
call   1090 <mpf_out_str@plt>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@stdout = global i32 0
@.str.1 = [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 = %53, %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 %56
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)
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = load i64, i64* %2
%42 = udiv i64 %41, 100
%43 = urem i64 %40, %42
%44 = icmp ne i64 %43, 0
br i1 %44, label %52, label %45
45: ; preds = %18
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = load i64, i64* %2
%49 = udiv i64 %48, 100
%50 = udiv i64 %47, %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %50)
br label %52
52: ; preds = %45, %18
br label %53
53: ; preds = %52
%54 = load i32, i32* %6
%55 = add nsw i32 %54, 1
store i32 %55, i32* %6
br label %13
56: ; preds = %13
%57 = load i32, i32* %3
%58 = load i32, i32* %3
%59 = call i32 @mpf_mul_ui(i32 %57, i32 %58, i32 4)
%60 = load i32, i32* @stdout
%61 = load i32, i32* %3
%62 = call i32 @mpf_out_str(i32 %60, i32 10, i32 0, i32 %61)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@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 %28, label %6
6: ; preds = %1
%7 = udiv i64 %0, 100
br label %8
8: ; preds = %6, %25
%9 = phi i64 [ 0, %6 ], [ %26, %25 ]
%10 = and i64 %9, 1
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i32 1, i32 -1
%13 = tail call i32 @mpf_set_si(i32 undef, i32 %12)
%14 = trunc i64 %9 to i32
%15 = shl i32 %14, 1
%16 = or i32 %15, 1
%17 = tail call i32 @mpf_set_ui(i32 undef, i32 %16)
%18 = tail call i32 @mpf_div(i32 undef, i32 undef, i32 undef)
%19 = tail call i32 @mpf_add(i32 undef, i32 undef, i32 undef)
%20 = urem i64 %9, %7
%21 = udiv i64 %9, %7
%22 = icmp eq i64 %20, 0
br i1 %22, label %23, label %25
23: ; preds = %8
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %21)
br label %25
25: ; preds = %8, %23
%26 = add nuw i64 %9, 1
%27 = icmp eq i64 %26, %0
br i1 %27, label %28, label %8
28: ; preds = %25, %1
%29 = tail call i32 @mpf_mul_ui(i32 undef, i32 undef, i32 4)
%30 = load i32, i32* @stdout
%31 = tail call i32 @mpf_out_str(i32 %30, i32 10, i32 0, i32 undef)
%32 = tail call i32 @putchar(i32 10)
ret void
}