// File: 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:
subq $0x738, %rsp            # imm = 0x738
movq %rdi, 0x40(%rsp)
movq %rdi, %rax
movq %rax, 0x48(%rsp)
movq %rdi, 0x730(%rsp)
movq %rsi, 0x728(%rsp)
movq %rdx, 0x720(%rsp)
movl %ecx, 0x71c(%rsp)
leaq 0x698(%rsp), %rdi
callq 0x28c0
leaq 0x618(%rsp), %rdi
callq 0x28c0
jmp 0x828f
leaq 0x588(%rsp), %rdi
callq 0x28c0
jmp 0x829e
leaq 0x508(%rsp), %rdi
callq 0x28c0
jmp 0x82ad
leaq 0x488(%rsp), %rdi
callq 0x28c0
jmp 0x82bc
leaq 0x408(%rsp), %rdi
callq 0x28c0
jmp 0x82cb
leaq 0x408(%rsp), %rdi
xorl %esi, %esi
callq 0x5de0
jmp 0x82dc
movq 0x720(%rsp), %rdi
leaq 0x408(%rsp), %rsi
callq 0x7e50
movb %al, 0x3f(%rsp)
jmp 0x82f7
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0x8304
jmp 0x83d4
leaq 0x6f8(%rsp), %rdi
leaq 0x7d21(%rip), %rsi      # 0x10034
callq 0x2270
jmp 0x831a
movq 0x40(%rsp), %rdi
leaq 0x698(%rsp), %rsi
callq 0xb7e0
jmp 0x832e
movl $0x1, 0x404(%rsp)
jmp 0x8be0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x610(%rsp)
movl %eax, 0x60c(%rsp)
jmp 0x8c7c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x610(%rsp)
movl %eax, 0x60c(%rsp)
jmp 0x8c6f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x610(%rsp)
movl %eax, 0x60c(%rsp)
jmp 0x8c62
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x610(%rsp)
movl %eax, 0x60c(%rsp)
jmp 0x8c55
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x610(%rsp)
movl %eax, 0x60c(%rsp)
jmp 0x8c48
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x610(%rsp)
movl %eax, 0x60c(%rsp)
jmp 0x8c3b
movq 0x728(%rsp), %rdi
leaq 0x408(%rsp), %rsi
callq 0x7ed0
movb %al, 0x3e(%rsp)
jmp 0x83ef
movb 0x3e(%rsp), %al
testb $0x1, %al
jne 0x83f9
jmp 0x8412
movq 0x728(%rsp), %rsi
leaq 0x380(%rsp), %rdi
callq 0x2830
jmp 0x8410
jmp 0x843e
movq 0x728(%rsp), %rsi
movl $0xffffffff, 0x37c(%rsp) # imm = 0xFFFFFFFF
leaq 0x380(%rsp), %rdi
leaq 0x37c(%rsp), %rdx
callq 0x70c0
jmp 0x843c
jmp 0x843e
leaq 0x488(%rsp), %rdi
leaq 0x380(%rsp), %rsi
callq 0xb470
jmp 0x8455
leaq 0x380(%rsp), %rdi
callq 0x2780
movq 0x720(%rsp), %rdi
leaq 0x408(%rsp), %rsi
callq 0x7ed0
movb %al, 0x3d(%rsp)
jmp 0x847d
movb 0x3d(%rsp), %al
testb $0x1, %al
jne 0x8487
jmp 0x84a0
movq 0x720(%rsp), %rsi
leaq 0x2f8(%rsp), %rdi
callq 0x2830
jmp 0x849e
jmp 0x84cc
movq 0x720(%rsp), %rsi
movl $0xffffffff, 0x2f4(%rsp) # imm = 0xFFFFFFFF
leaq 0x2f8(%rsp), %rdi
leaq 0x2f4(%rsp), %rdx
callq 0x70c0
jmp 0x84ca
jmp 0x84cc
leaq 0x508(%rsp), %rdi
leaq 0x2f8(%rsp), %rsi
callq 0xb470
jmp 0x84e3
leaq 0x2f8(%rsp), %rdi
callq 0x2780
movb $0x2b, 0x588(%rsp)
movb $0x0, 0x5e4(%rsp)
movb $0x1, %al
cmpl $0x0, 0x4e0(%rsp)
movb %al, 0x3c(%rsp)
jne 0x851f
cmpl $0x0, 0x560(%rsp)
setne %al
movb %al, 0x3c(%rsp)
movb 0x3c(%rsp), %al
testb $0x1, %al
jne 0x852c
jmp 0x85f5
cmpl $0x0, 0x4e0(%rsp)
jne 0x85a3
leaq 0x490(%rsp), %rdi
movb $0x30, 0x2f3(%rsp)
leaq 0x2f3(%rsp), %rsi
callq 0xb4e0
jmp 0x8555
jmp 0x85b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x610(%rsp)
movl %eax, 0x60c(%rsp)
leaq 0x380(%rsp), %rdi
callq 0x2780
jmp 0x8c3b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x610(%rsp)
movl %eax, 0x60c(%rsp)
leaq 0x2f8(%rsp), %rdi
callq 0x2780
jmp 0x8c3b
movl 0x4e0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x4e0(%rsp)
cmpl $0x0, 0x560(%rsp)
jne 0x85df
leaq 0x510(%rsp), %rdi
movb $0x30, 0x2f2(%rsp)
leaq 0x2f2(%rsp), %rsi
callq 0xb4e0
jmp 0x85dd
jmp 0x85f0
movl 0x560(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x560(%rsp)
jmp 0x8500
leaq 0x488(%rsp), %rdi
callq 0x5d20
jmp 0x8604
leaq 0x508(%rsp), %rdi
callq 0x5d20
jmp 0x8613
movl $0x0, 0x2ec(%rsp)
movl 0x2ec(%rsp), %eax
cmpl 0x71c(%rsp), %eax
jge 0x8662
leaq 0x490(%rsp), %rdi
movb $0x30, 0x2eb(%rsp)
leaq 0x2eb(%rsp), %rsi
callq 0xb4e0
jmp 0x864d
jmp 0x864f
movl 0x2ec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2ec(%rsp)
jmp 0x861e
leaq 0x488(%rsp), %rdi
leaq 0x508(%rsp), %rsi
callq 0x4590
movl %eax, 0x38(%rsp)
jmp 0x867d
movl 0x38(%rsp), %eax
movl %eax, 0x2e4(%rsp)
cmpl $0x0, 0x2e4(%rsp)
jne 0x86b3
leaq 0x6a0(%rsp), %rdi
movb $0x31, 0x2e3(%rsp)
leaq 0x2e3(%rsp), %rsi
callq 0xb4e0
jmp 0x86b1
jmp 0x86b3
cmpl $0x2, 0x2e4(%rsp)
jne 0x86e1
movq 0x40(%rsp), %rdi
leaq 0x408(%rsp), %rsi
callq 0xb7e0
jmp 0x86d1
movl $0x1, 0x404(%rsp)
jmp 0x8be0
jmp 0x86e3
leaq 0x488(%rsp), %rdi
addq $0x8, %rdi
callq 0xb5d0
xorb $-0x1, %al
testb $0x1, %al
jne 0x86ff
jmp 0x8b31
leaq 0x590(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x490(%rsp), %rsi
leaq 0x2c0(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0xb840
movq 0x28(%rsp), %rdi
callq 0xb8a0
movq %rax, 0x30(%rsp)
jmp 0x8737
movq 0x30(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0xb5f0
jmp 0x8748
leaq 0x488(%rsp), %rdi
addq $0x8, %rdi
callq 0xb8d0
movb $0x1, 0x2bf(%rsp)
leaq 0x588(%rsp), %rsi
addq $0x8, %rsi
leaq 0x278(%rsp), %rdi
callq 0x2a80
leaq 0x298(%rsp), %rdi
leaq 0x278(%rsp), %rsi
callq 0x4220
leaq 0x588(%rsp), %rsi
addq $0x8, %rsi
leaq 0x258(%rsp), %rdi
callq 0x2ab0
leaq 0x298(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0xb940
testb $0x1, %al
jne 0x87c3
jmp 0x87f1
leaq 0x298(%rsp), %rdi
callq 0xb970
movsbl (%rax), %eax
cmpl $0x30, %eax
je 0x87e0
movb $0x0, 0x2bf(%rsp)
jmp 0x87e2
leaq 0x298(%rsp), %rdi
callq 0xb980
jmp 0x878f
leaq 0x588(%rsp), %rdi
leaq 0x508(%rsp), %rsi
callq 0x7fe0
movb %al, 0x1f(%rsp)
jmp 0x880c
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x8819
jmp 0x8b11
testb $0x1, 0x2bf(%rsp)
jne 0x8b11
movl $0x0, 0x254(%rsp)
movl $0x0, 0x250(%rsp)
movl $0x9, 0x24c(%rsp)
leaq 0x588(%rsp), %rdi
leaq 0x508(%rsp), %rsi
callq 0x7fe0
movb %al, 0x1e(%rsp)
jmp 0x8863
movb 0x1e(%rsp), %al
testb $0x1, %al
jne 0x8870
jmp 0x8a29
movl 0x24c(%rsp), %eax
subl 0x250(%rsp), %eax
movl %eax, 0x248(%rsp)
movl 0x248(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x244(%rsp)
movl 0x248(%rsp), %eax
movl 0x244(%rsp), %ecx
shll %ecx
subl %ecx, %eax
cmpl $0x0, %eax
je 0x88c2
movl 0x244(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x88cd
movl 0x244(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x248(%rsp)
leaq 0x1c0(%rsp), %rdi
leaq 0x508(%rsp), %rsi
leaq 0x248(%rsp), %rdx
callq 0x70c0
jmp 0x88f7
leaq 0x588(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x4590
movl %eax, 0x14(%rsp)
jmp 0x8912
leaq 0x1c0(%rsp), %rdi
callq 0x2780
movl 0x14(%rsp), %eax
movl %eax, 0x240(%rsp)
cmpl $0x2, 0x240(%rsp)
jne 0x896d
movl 0x248(%rsp), %eax
movl %eax, 0x24c(%rsp)
jmp 0x8a24
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x610(%rsp)
movl %eax, 0x60c(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x2780
jmp 0x8c3b
movl 0x254(%rsp), %eax
movl 0x248(%rsp), %ecx
addl %ecx, %eax
movl %eax, 0x254(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x508(%rsp), %rsi
leaq 0x248(%rsp), %rdx
callq 0x70c0
jmp 0x89a3
leaq 0x140(%rsp), %rdi
leaq 0x588(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
callq 0x67d0
jmp 0x89c2
leaq 0x588(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x2950
leaq 0x140(%rsp), %rdi
callq 0x2780
leaq 0xc0(%rsp), %rdi
callq 0x2780
movl $0x9, 0x24c(%rsp)
jmp 0x8a24
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x610(%rsp)
movl %eax, 0x60c(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x2780
jmp 0x8c3b
jmp 0x8848
leaq 0x620(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x254(%rsp), %rdi
callq 0xb5c0
movb %al, 0x13(%rsp)
jmp 0x8a49
movq 0x8(%rsp), %rdi
movb 0x13(%rsp), %al
movb %al, 0xbf(%rsp)
leaq 0xbf(%rsp), %rsi
callq 0xb4e0
jmp 0x8a68
movb $0x1, 0xbe(%rsp)
leaq 0x588(%rsp), %rsi
addq $0x8, %rsi
leaq 0x78(%rsp), %rdi
callq 0x2a80
leaq 0x98(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x4220
leaq 0x588(%rsp), %rsi
addq $0x8, %rsi
leaq 0x58(%rsp), %rdi
callq 0x2ab0
leaq 0x98(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0xb940
testb $0x1, %al
jne 0x8ac6
jmp 0x8af4
leaq 0x98(%rsp), %rdi
callq 0xb970
movsbl (%rax), %eax
cmpl $0x30, %eax
je 0x8ae3
movb $0x0, 0xbe(%rsp)
jmp 0x8ae5
leaq 0x98(%rsp), %rdi
callq 0xb980
jmp 0x8a98
testb $0x1, 0xbe(%rsp)
je 0x8b0f
leaq 0x588(%rsp), %rdi
addq $0x8, %rdi
callq 0x4330
jmp 0x8b2c
leaq 0x620(%rsp), %rdi
movb $0x30, 0x57(%rsp)
leaq 0x57(%rsp), %rsi
callq 0xb4e0
jmp 0x8b2a
jmp 0x8b2c
jmp 0x86e3
leaq 0x698(%rsp), %rdi
leaq 0x618(%rsp), %rsi
callq 0xb470
jmp 0x8b48
jmp 0x8b4a
movq 0x728(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x8b6a
movq 0x720(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x8b8a
movq 0x728(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2b, %eax
jne 0x8b94
movq 0x720(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2b, %eax
jne 0x8b94
movb $0x2b, 0x698(%rsp)
jmp 0x8b9c
movb $0x2d, 0x698(%rsp)
movl 0x71c(%rsp), %eax
movl %eax, 0x6f0(%rsp)
movb $0x0, 0x6f4(%rsp)
leaq 0x698(%rsp), %rdi
callq 0x5d20
jmp 0x8bc1
movq 0x40(%rsp), %rdi
leaq 0x698(%rsp), %rsi
callq 0xb7e0
jmp 0x8bd5
movl $0x1, 0x404(%rsp)
leaq 0x408(%rsp), %rdi
callq 0x2780
leaq 0x488(%rsp), %rdi
callq 0x2780
leaq 0x508(%rsp), %rdi
callq 0x2780
leaq 0x588(%rsp), %rdi
callq 0x2780
leaq 0x618(%rsp), %rdi
callq 0x2780
leaq 0x698(%rsp), %rdi
callq 0x2780
movq 0x48(%rsp), %rax
addq $0x738, %rsp            # imm = 0x738
retq
leaq 0x408(%rsp), %rdi
callq 0x2780
leaq 0x488(%rsp), %rdi
callq 0x2780
leaq 0x508(%rsp), %rdi
callq 0x2780
leaq 0x588(%rsp), %rdi
callq 0x2780
leaq 0x618(%rsp), %rdi
callq 0x2780
leaq 0x698(%rsp), %rdi
callq 0x2780
movq 0x610(%rsp), %rdi
callq 0x2300
nopw %cs:(%rax,%rax)