// File: aisthesis[P]realnumber/src/convergent_series.cpp
// Function: ConvergentSeries::gauss_legendre_pi(unsigned long const&, unsigned long const&, RealNumber const&)
RealNumber ConvergentSeries::gauss_legendre_pi(const std::size_t& pi_iterations,
                                               const std::size_t& sqrt_iterations, const RealNumber& sqrt_two) {
    RealNumber a("1.0");
    RealNumber a_next;
    RealNumber b = RealNumber("1.0") / sqrt_two;
    RealNumber b_next;
    RealNumber t("0.25");
    RealNumber t_next;
    RealNumber p("1.0");
    RealNumber p_next;
    RealNumber tmp1, tmp2;
    
    const RealNumber one_half("0.5");
    const RealNumber two("2.0");
    for (std::size_t i = 0; i < pi_iterations; ++i) {
        a_next = (a + b) * one_half;
        b_next = babylonian_sqrt(a * b, a_next, sqrt_iterations);
        tmp1 = a - a_next;
        t_next = t - p * tmp1 * tmp1;
        p_next = two * p;
        a = a_next;
        b = b_next;
        t = t_next;
        p = p_next;
    }
    tmp1 = a + b;
    tmp2 = RealNumber("4.0") * t;
    return tmp1 * tmp1 / tmp2;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rdi, -0x238(%rbp)
movq %rdi, %rax
movq %rax, -0x230(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
leaq -0x49(%rbp), %rdi
movq %rdi, -0x228(%rbp)
callq 0x22a0
movq -0x228(%rbp), %rdx
leaq 0x1cca(%rip), %rsi      # 0x6004
leaq -0x48(%rbp), %rdi
callq 0x2f70
jmp 0x4345
leaq -0x28(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x3340
jmp 0x4354
leaq -0x48(%rbp), %rdi
callq 0x20a0
leaq -0x49(%rbp), %rdi
callq 0x21a0
leaq -0x68(%rbp), %rdi
callq 0x32c0
jmp 0x4371
leaq -0x99(%rbp), %rdi
movq %rdi, -0x240(%rbp)
callq 0x22a0
movq -0x240(%rbp), %rdx
leaq 0x1c72(%rip), %rsi      # 0x6004
leaq -0x98(%rbp), %rdi
callq 0x2f70
jmp 0x43a0
leaq -0x78(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x3340
jmp 0x43b2
movq -0x20(%rbp), %rdx
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x3fe0
jmp 0x43c5
leaq -0x78(%rbp), %rdi
callq 0x3650
leaq -0x98(%rbp), %rdi
callq 0x20a0
leaq -0x99(%rbp), %rdi
callq 0x21a0
leaq -0xa8(%rbp), %rdi
callq 0x32c0
jmp 0x43f4
leaq -0xd1(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0x22a0
movq -0x248(%rbp), %rdx
leaq 0x1ce8(%rip), %rsi      # 0x60fd
leaq -0xd0(%rbp), %rdi
callq 0x2f70
jmp 0x4423
leaq -0xb0(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x3340
jmp 0x4438
leaq -0xd0(%rbp), %rdi
callq 0x20a0
leaq -0xd1(%rbp), %rdi
callq 0x21a0
leaq -0xe0(%rbp), %rdi
callq 0x32c0
jmp 0x445e
leaq -0x109(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x22a0
movq -0x250(%rbp), %rdx
leaq 0x1b85(%rip), %rsi      # 0x6004
leaq -0x108(%rbp), %rdi
callq 0x2f70
jmp 0x448d
leaq -0xe8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x3340
jmp 0x44a2
leaq -0x108(%rbp), %rdi
callq 0x20a0
leaq -0x109(%rbp), %rdi
callq 0x21a0
leaq -0x118(%rbp), %rdi
callq 0x32c0
jmp 0x44c8
leaq -0x120(%rbp), %rdi
callq 0x32c0
jmp 0x44d6
leaq -0x128(%rbp), %rdi
callq 0x32c0
jmp 0x44e4
leaq -0x151(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x22a0
movq -0x258(%rbp), %rdx
leaq 0x1bfd(%rip), %rsi      # 0x6102
leaq -0x150(%rbp), %rdi
callq 0x2f70
jmp 0x4513
leaq -0x130(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x3340
jmp 0x4528
leaq -0x150(%rbp), %rdi
callq 0x20a0
leaq -0x151(%rbp), %rdi
callq 0x21a0
leaq -0x181(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x22a0
movq -0x260(%rbp), %rdx
leaq 0x1b02(%rip), %rsi      # 0x6063
leaq -0x180(%rbp), %rdi
callq 0x2f70
jmp 0x456f
leaq -0x160(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x3340
jmp 0x4584
leaq -0x180(%rbp), %rdi
callq 0x20a0
leaq -0x181(%rbp), %rdi
callq 0x21a0
movq $0x0, -0x190(%rbp)
movq -0x190(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x4aa7
leaq -0x1a0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x3d70
jmp 0x45d1
leaq -0x198(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
leaq -0x130(%rbp), %rdx
callq 0x3ed0
jmp 0x45ed
leaq -0x68(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x38e0
jmp 0x45ff
leaq -0x198(%rbp), %rdi
callq 0x3650
leaq -0x1a0(%rbp), %rdi
callq 0x3650
leaq -0x1b0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x3ed0
jmp 0x462d
movq -0x18(%rbp), %rcx
leaq -0x1a8(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x40f0
jmp 0x464a
leaq -0xa8(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x38e0
jmp 0x465f
leaq -0x1a8(%rbp), %rdi
callq 0x3650
leaq -0x1b0(%rbp), %rdi
callq 0x3650
leaq -0x1b8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x3e30
jmp 0x468d
leaq -0x120(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0x38e0
jmp 0x46a2
leaq -0x1b8(%rbp), %rdi
callq 0x3650
leaq -0x1d0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
leaq -0x120(%rbp), %rdx
callq 0x3ed0
jmp 0x46ca
leaq -0x1c8(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
leaq -0x120(%rbp), %rdx
callq 0x3ed0
jmp 0x46e6
leaq -0x1c0(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
leaq -0x1c8(%rbp), %rdx
callq 0x3e30
jmp 0x4702
leaq -0xe0(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x38e0
jmp 0x4717
leaq -0x1c0(%rbp), %rdi
callq 0x3650
leaq -0x1c8(%rbp), %rdi
callq 0x3650
leaq -0x1d0(%rbp), %rdi
callq 0x3650
leaq -0x1d8(%rbp), %rdi
leaq -0x160(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
callq 0x3ed0
jmp 0x4757
leaq -0x118(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0x38e0
jmp 0x476c
leaq -0x1d8(%rbp), %rdi
callq 0x3650
leaq -0x28(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x38e0
jmp 0x4787
leaq -0x70(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x38e0
jmp 0x4799
leaq -0xb0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x38e0
jmp 0x47ae
leaq -0xe8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x38e0
jmp 0x47c3
jmp 0x47c5
movq -0x190(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x190(%rbp)
jmp 0x45a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x47ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x20a0
leaq -0x49(%rbp), %rdi
callq 0x21a0
jmp 0x4d7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4d75
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x485b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x484f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x3650
leaq -0x98(%rbp), %rdi
callq 0x20a0
leaq -0x99(%rbp), %rdi
callq 0x21a0
jmp 0x4d6c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4d63
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x48a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x20a0
leaq -0xd1(%rbp), %rdi
callq 0x21a0
jmp 0x4d57
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4d4b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x48eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x20a0
leaq -0x109(%rbp), %rdi
callq 0x21a0
jmp 0x4d3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4d33
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4d27
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4d1b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4955
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x20a0
leaq -0x151(%rbp), %rdi
callq 0x21a0
jmp 0x4d0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x498c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x20a0
leaq -0x181(%rbp), %rdi
callq 0x21a0
jmp 0x4d03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4cf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x49d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x3650
leaq -0x1a0(%rbp), %rdi
callq 0x3650
jmp 0x4cf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4a0b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x3650
leaq -0x1b0(%rbp), %rdi
callq 0x3650
jmp 0x4cf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x3650
jmp 0x4cf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4a79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4a6d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x3650
leaq -0x1c8(%rbp), %rdi
callq 0x3650
leaq -0x1d0(%rbp), %rdi
callq 0x3650
jmp 0x4cf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x3650
jmp 0x4cf7
leaq -0x1e0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x3d70
jmp 0x4abd
leaq -0x120(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x38e0
jmp 0x4ad2
leaq -0x1e0(%rbp), %rdi
callq 0x3650
leaq -0x211(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x22a0
movq -0x268(%rbp), %rdx
leaq 0x1607(%rip), %rsi      # 0x6106
leaq -0x210(%rbp), %rdi
callq 0x2f70
jmp 0x4b0d
leaq -0x1f0(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x3340
jmp 0x4b22
leaq -0x1e8(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x3ed0
jmp 0x4b3e
leaq -0x128(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x38e0
jmp 0x4b53
leaq -0x1e8(%rbp), %rdi
callq 0x3650
leaq -0x1f0(%rbp), %rdi
callq 0x3650
leaq -0x210(%rbp), %rdi
callq 0x20a0
leaq -0x211(%rbp), %rdi
callq 0x21a0
leaq -0x220(%rbp), %rdi
leaq -0x120(%rbp), %rdx
movq %rdx, %rsi
callq 0x3ed0
jmp 0x4b9b
movq -0x238(%rbp), %rdi
leaq -0x220(%rbp), %rsi
leaq -0x128(%rbp), %rdx
callq 0x3fe0
jmp 0x4bb7
leaq -0x220(%rbp), %rdi
callq 0x3650
leaq -0x160(%rbp), %rdi
callq 0x3650
leaq -0x130(%rbp), %rdi
callq 0x3650
leaq -0x128(%rbp), %rdi
callq 0x3650
leaq -0x120(%rbp), %rdi
callq 0x3650
leaq -0x118(%rbp), %rdi
callq 0x3650
leaq -0xe8(%rbp), %rdi
callq 0x3650
leaq -0xe0(%rbp), %rdi
callq 0x3650
leaq -0xb0(%rbp), %rdi
callq 0x3650
leaq -0xa8(%rbp), %rdi
callq 0x3650
leaq -0x70(%rbp), %rdi
callq 0x3650
leaq -0x68(%rbp), %rdi
callq 0x3650
leaq -0x28(%rbp), %rdi
callq 0x3650
movq -0x230(%rbp), %rax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x3650
jmp 0x4cf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4cd1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4cc5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4cb9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0x3650
leaq -0x1f0(%rbp), %rdi
callq 0x3650
leaq -0x210(%rbp), %rdi
callq 0x20a0
leaq -0x211(%rbp), %rdi
callq 0x21a0
jmp 0x4cf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x3650
leaq -0x160(%rbp), %rdi
callq 0x3650
leaq -0x130(%rbp), %rdi
callq 0x3650
leaq -0x128(%rbp), %rdi
callq 0x3650
leaq -0x120(%rbp), %rdi
callq 0x3650
leaq -0x118(%rbp), %rdi
callq 0x3650
leaq -0xe8(%rbp), %rdi
callq 0x3650
leaq -0xe0(%rbp), %rdi
callq 0x3650
leaq -0xb0(%rbp), %rdi
callq 0x3650
leaq -0xa8(%rbp), %rdi
callq 0x3650
leaq -0x70(%rbp), %rdi
callq 0x3650
leaq -0x68(%rbp), %rdi
callq 0x3650
leaq -0x28(%rbp), %rdi
callq 0x3650
movq -0x58(%rbp), %rdi
callq 0x2290
nopw (%rax,%rax)