// File: /workspace/github_cpp_makefile_star2_O2/Mariotti94[P]BigFloat/BigFloat.cc
// Function: BigFloat::PrecDiv(BigFloat const&, BigFloat const&, int)
BigFloat BigFloat::PrecDiv(const BigFloat& left, const BigFloat& right, int div_precision)
{
    BigFloat tmp;

    BigFloat Q, R, D, N, zero;
    zero = 0;

    if(right == zero) {
        tmp.error_code = "Division For 0";
        return tmp;
    }

    N = (left > zero) ? (left) : (left * (-1));
    D = (right > zero) ? (right) : (right * (-1));
    R.sign = '+';
    R.error = 0;

    while((N.decimals != 0) || (D.decimals != 0)) {
        if(N.decimals == 0)
            N.number.push_front('0');
        else
            N.decimals--;

        if(D.decimals == 0)
            D.number.push_front('0');
        else
            D.decimals--;
    }
    N.LeadTrim();
    D.LeadTrim();

    //Increase Precision to div_precision
    for(int i = 0; i < div_precision; i++)
        N.number.push_front('0');

    int check = BigFloat::CompareNum(N, D);

    if(check == 0) {
        tmp.number.push_front('1');
    }
    if(check == 2) {
        return zero;
    }
    else {
        while(!N.number.empty()) {
            R.number.push_front(*(N.number.rbegin()));
            N.number.pop_back();

            bool is_zero = true;
            std::deque<char>::const_iterator zero_iter = R.number.begin();
            for(; zero_iter != R.number.end(); ++zero_iter)
                if(*zero_iter != '0')
                    is_zero = false;

            if((R >= D) && (!is_zero)) {
                int Q_sub = 0;
                int min = 0;
                int max = 9;

                while(R >= D) {
                    int avg = max - min;
                    int mod_avg = avg / 2;
                    avg = (avg - mod_avg * 2) ? (mod_avg + 1) : (mod_avg);

                    int div_check = BigFloat::CompareNum(R, D * avg);

                    if(div_check == 2) {
                        max = avg;
                    }
                    else {
                        Q_sub = Q_sub + avg;
                        R = R - D * avg;

                        max = 9;
                    }
                }

                Q.number.push_front(BigFloat::IntToChar(Q_sub));

                bool is_zero = true;
                std::deque<char>::const_iterator zero_iter = R.number.begin();
                for(; zero_iter != R.number.end(); ++zero_iter)
                    if(*zero_iter != '0')
                        is_zero = false;
                if(is_zero)
                    R.number.clear();

            }
            else {
                Q.number.push_front('0');
            }
        }
        tmp = Q;
    }

    if(((left.sign == '-') && (right.sign == '-')) || ((left.sign == '+') && (right.sign == '+')))
        tmp.sign = '+';
    else
        tmp.sign = '-';

    tmp.decimals = div_precision;
    tmp.error = 0;
    tmp.LeadTrim();

    return tmp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x228(%rsp), %rdi
callq 0x2610
leaq 0x328(%rsp), %rdi
callq 0x2610
leaq 0xa8(%rsp), %rdi
callq 0x2610
leaq 0x1a8(%rsp), %rdi
callq 0x2610
leaq 0x128(%rsp), %rdi
callq 0x2610
movq %rbx, 0x18(%rsp)
leaq 0x2a8(%rsp), %rdi
callq 0x2610
leaq 0x2a8(%rsp), %rdi
xorl %esi, %esi
callq 0x3b82
leaq 0x2a8(%rsp), %rsi
movq %r15, %rdi
callq 0x4d92
testb %al, %al
je 0x5029
leaq 0x288(%rsp), %rdi
leaq 0x4039(%rip), %rsi      # 0x9048
callq 0x2220
leaq 0x228(%rsp), %rsi
movq %r14, %rdi
callq 0x6d18
jmp 0x547c
leaq 0x2a8(%rsp), %rsi
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x4dca
testb %al, %al
je 0x5051
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x25b4
jmp 0x5069
leaq 0x3a8(%rsp), %rdx
orl $-0x1, (%rdx)
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x4588
leaq 0x128(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x6c40
leaq 0x28(%rsp), %rdi
callq 0x253c
leaq 0x2a8(%rsp), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4dca
testb %al, %al
je 0x50ab
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x25b4
jmp 0x50c3
leaq 0x3a8(%rsp), %rdx
orl $-0x1, (%rdx)
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x4588
movq %r15, 0x20(%rsp)
movl %ebp, 0x8(%rsp)
movq %r14, 0x10(%rsp)
leaq 0x1a8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x6c40
leaq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x253c
movb $0x2b, 0xa8(%rsp)
movb $0x0, 0x104(%rsp)
leaq 0x130(%rsp), %r12
leaq 0x1b0(%rsp), %r15
movl 0x180(%rsp), %ecx
movl 0x200(%rsp), %eax
movl %ecx, %edx
orl %eax, %edx
je 0x516b
testl %ecx, %ecx
je 0x5133
decl %ecx
movl %ecx, 0x180(%rsp)
jmp 0x514a
movb $0x30, 0x28(%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x88c4
movl 0x200(%rsp), %eax
testl %eax, %eax
je 0x5159
decl %eax
movl %eax, 0x200(%rsp)
jmp 0x5110
movb $0x30, 0x28(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x88c4
jmp 0x5110
leaq 0x128(%rsp), %rdi
callq 0x3b2c
leaq 0x1a8(%rsp), %rdi
callq 0x3b2c
xorl %ebp, %ebp
movl 0x8(%rsp), %eax
testl %eax, %eax
cmovgl %eax, %ebp
leaq 0x28(%rsp), %r14
subl $0x1, %ebp
jb 0x51ac
movb $0x30, 0x28(%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x88c4
jmp 0x5195
leaq 0x128(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
callq 0x2edc
movq 0x10(%rsp), %r14
cmpl $0x2, %eax
je 0x5471
testl %eax, %eax
jne 0x51e8
leaq 0x230(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movb $0x31, (%rsi)
callq 0x88c4
leaq 0xb0(%rsp), %r13
leaq 0xa8(%rsp), %r15
leaq 0x1a8(%rsp), %rbx
leaq 0x28(%rsp), %r14
movq 0x160(%rsp), %rsi
cmpq 0x140(%rsp), %rsi
je 0x5401
cmpq 0x168(%rsp), %rsi
jne 0x5239
movq 0x178(%rsp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
decq %rsi
movq %r13, %rdi
callq 0x6c84
movq %r12, %rdi
callq 0x6d5c
movq 0xc0(%rsp), %rax
movq 0xd0(%rsp), %rsi
movq 0xd8(%rsp), %rcx
movb $0x1, %bpl
movq 0xe0(%rsp), %rdx
cmpq %rdx, %rax
je 0x5297
cmpb $0x30, (%rax)
sete %dil
andb %dil, %bpl
incq %rax
cmpq %rsi, %rax
jne 0x526f
movq 0x8(%rcx), %rax
addq $0x8, %rcx
leaq 0x200(%rax), %rsi
jmp 0x526f
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4e14
notb %al
orb %bpl, %al
testb $0x1, %al
je 0x52c5
movb $0x30, 0x28(%rsp)
leaq 0x330(%rsp), %rdi
movq %r14, %rsi
callq 0x88c4
jmp 0x5205
xorl %ebp, %ebp
pushq $0x9
popq %r13
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4e14
testb %al, %al
je 0x5378
movl %r13d, %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
leal (%rax,%rax), %ecx
xorl %r12d, %r12d
cmpl %ecx, %r13d
setne %r12b
addl %eax, %r12d
movl %r12d, 0xc(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
leaq 0xc(%rsp), %rdx
callq 0x4588
movq %r15, %rdi
movq %r14, %rsi
callq 0x2edc
movl %eax, %r13d
movq %r14, %rdi
callq 0x253c
cmpl $0x2, %r13d
je 0x5370
leaq 0x3a8(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rsi
leaq 0xc(%rsp), %rdx
callq 0x4588
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x40de
addl %r12d, %ebp
movq %r15, %rdi
movq %r14, %rsi
callq 0x2678
movq %r14, %rdi
callq 0x253c
movq %r13, %rdi
callq 0x253c
pushq $0x9
popq %r12
movl %r12d, %r13d
jmp 0x52cb
addb $0x30, %bpl
movb %bpl, 0x28(%rsp)
leaq 0x330(%rsp), %rdi
movq %r14, %rsi
callq 0x88c4
movq 0xc0(%rsp), %rax
movq 0xd0(%rsp), %rdi
movq 0xd8(%rsp), %rdx
movb $0x1, %cl
movq 0xe0(%rsp), %rsi
leaq 0x130(%rsp), %r12
leaq 0xb0(%rsp), %r13
cmpq %rsi, %rax
je 0x53eb
cmpb $0x30, (%rax)
sete %r8b
andb %r8b, %cl
incq %rax
cmpq %rdi, %rax
jne 0x53c3
movq 0x8(%rdx), %rax
addq $0x8, %rdx
leaq 0x200(%rax), %rdi
jmp 0x53c3
testb $0x1, %cl
je 0x5205
movq %r13, %rdi
callq 0x2df6
jmp 0x5205
leaq 0x228(%rsp), %rbx
leaq 0x328(%rsp), %rsi
movq %rbx, %rdi
callq 0x6c40
movq 0x10(%rsp), %r14
movl 0x8(%rsp), %edi
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rax
movb (%rax), %al
movl %eax, %ecx
xorb $0x2d, %cl
movb (%rdx), %dl
movl %edx, %esi
xorb $0x2d, %sil
orb %cl, %sil
sete %cl
xorb $0x2b, %al
xorb $0x2b, %dl
orb %al, %dl
sete %al
orb %cl, %al
xorb $0x1, %al
addb %al, %al
addb $0x2b, %al
movb %al, 0x228(%rsp)
movl %edi, 0x280(%rsp)
movb $0x0, 0x284(%rsp)
movq %rbx, %rdi
callq 0x3b2c
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6d18
leaq 0x2a8(%rsp), %rdi
callq 0x253c
leaq 0x128(%rsp), %rdi
callq 0x253c
leaq 0x1a8(%rsp), %rdi
callq 0x253c
leaq 0xa8(%rsp), %rdi
callq 0x253c
leaq 0x328(%rsp), %rdi
callq 0x253c
leaq 0x228(%rsp), %rdi
callq 0x253c
movq %r14, %rax
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5538
jmp 0x5538
jmp 0x5538
jmp 0x5529
jmp 0x5529
jmp 0x5538
jmp 0x5538
movq %rax, %rbx
jmp 0x5548
movq %rax, %rbx
jmp 0x5555
movq %rax, %rbx
jmp 0x5562
movq %rax, %rbx
jmp 0x556f
movq %rax, %rbx
jmp 0x557c
jmp 0x5538
jmp 0x5538
jmp 0x5538
jmp 0x5538
jmp 0x5538
jmp 0x5538
jmp 0x5538
jmp 0x5538
jmp 0x5538
jmp 0x5538
movq %rax, %rbx
leaq 0x3a8(%rsp), %rdi
jmp 0x5531
jmp 0x5538
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x253c
jmp 0x553b
movq %rax, %rbx
leaq 0x2a8(%rsp), %rdi
callq 0x253c
leaq 0x128(%rsp), %rdi
callq 0x253c
leaq 0x1a8(%rsp), %rdi
callq 0x253c
leaq 0xa8(%rsp), %rdi
callq 0x253c
leaq 0x328(%rsp), %rdi
callq 0x253c
leaq 0x228(%rsp), %rdi
callq 0x253c
movq %rbx, %rdi
callq 0x2200
nop