// File: Mariotti94[P]BigFloat/BigFloat.cc
// Function: operator/(BigFloat const&, BigFloat const&)
BigFloat operator/(const BigFloat& left, const BigFloat& right)
{
    BigFloat tmp;

    if((left.error) || (right.error)) {
        return 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 highest decimal quote
    int div_precision = (left.decimals > right.decimals) ? (left.decimals) : (right.decimals);
    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, 0x48(%rsp)
movq %rdi, %rax
movq %rax, 0x50(%rsp)
movq %rdi, 0x730(%rsp)
movq %rsi, 0x728(%rsp)
movq %rdx, 0x720(%rsp)
leaq 0x6a0(%rsp), %rdi
callq 0x28c0
movq 0x728(%rsp), %rax
testb $0x1, 0x5c(%rax)
jne 0x73c5
movq 0x720(%rsp), %rax
testb $0x1, 0x5c(%rax)
je 0x7402
movq 0x48(%rsp), %rdi
leaq 0x6a0(%rsp), %rsi
callq 0xb7e0
jmp 0x73d9
movl $0x1, 0x690(%rsp)
jmp 0x7e18
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x698(%rsp)
movl %eax, 0x694(%rsp)
jmp 0x7e32
leaq 0x610(%rsp), %rdi
callq 0x28c0
jmp 0x7411
leaq 0x590(%rsp), %rdi
callq 0x28c0
jmp 0x7420
leaq 0x510(%rsp), %rdi
callq 0x28c0
jmp 0x742f
leaq 0x490(%rsp), %rdi
callq 0x28c0
jmp 0x743e
leaq 0x410(%rsp), %rdi
callq 0x28c0
jmp 0x744d
leaq 0x410(%rsp), %rdi
xorl %esi, %esi
callq 0x5de0
jmp 0x745e
movq 0x720(%rsp), %rdi
leaq 0x410(%rsp), %rsi
callq 0x7e50
movb %al, 0x47(%rsp)
jmp 0x7479
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0x7486
jmp 0x753d
leaq 0x700(%rsp), %rdi
leaq 0x8b9f(%rip), %rsi      # 0x10034
callq 0x2270
jmp 0x749c
movq 0x48(%rsp), %rdi
leaq 0x6a0(%rsp), %rsi
callq 0xb7e0
jmp 0x74b0
movl $0x1, 0x690(%rsp)
jmp 0x7d92
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x698(%rsp)
movl %eax, 0x694(%rsp)
jmp 0x7e09
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x698(%rsp)
movl %eax, 0x694(%rsp)
jmp 0x7dfc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x698(%rsp)
movl %eax, 0x694(%rsp)
jmp 0x7def
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x698(%rsp)
movl %eax, 0x694(%rsp)
jmp 0x7de2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x698(%rsp)
movl %eax, 0x694(%rsp)
jmp 0x7dd5
movq 0x728(%rsp), %rdi
leaq 0x410(%rsp), %rsi
callq 0x7ed0
movb %al, 0x46(%rsp)
jmp 0x7558
movb 0x46(%rsp), %al
testb $0x1, %al
jne 0x7562
jmp 0x757b
movq 0x728(%rsp), %rsi
leaq 0x390(%rsp), %rdi
callq 0x2830
jmp 0x7579
jmp 0x75a7
movq 0x728(%rsp), %rsi
movl $0xffffffff, 0x38c(%rsp) # imm = 0xFFFFFFFF
leaq 0x390(%rsp), %rdi
leaq 0x38c(%rsp), %rdx
callq 0x70c0
jmp 0x75a5
jmp 0x75a7
leaq 0x490(%rsp), %rdi
leaq 0x390(%rsp), %rsi
callq 0xb470
jmp 0x75be
leaq 0x390(%rsp), %rdi
callq 0x2780
movq 0x720(%rsp), %rdi
leaq 0x410(%rsp), %rsi
callq 0x7ed0
movb %al, 0x45(%rsp)
jmp 0x75e6
movb 0x45(%rsp), %al
testb $0x1, %al
jne 0x75f0
jmp 0x7609
movq 0x720(%rsp), %rsi
leaq 0x308(%rsp), %rdi
callq 0x2830
jmp 0x7607
jmp 0x7635
movq 0x720(%rsp), %rsi
movl $0xffffffff, 0x304(%rsp) # imm = 0xFFFFFFFF
leaq 0x308(%rsp), %rdi
leaq 0x304(%rsp), %rdx
callq 0x70c0
jmp 0x7633
jmp 0x7635
leaq 0x510(%rsp), %rdi
leaq 0x308(%rsp), %rsi
callq 0xb470
jmp 0x764c
leaq 0x308(%rsp), %rdi
callq 0x2780
movb $0x2b, 0x590(%rsp)
movb $0x0, 0x5ec(%rsp)
movb $0x1, %al
cmpl $0x0, 0x4e8(%rsp)
movb %al, 0x44(%rsp)
jne 0x7688
cmpl $0x0, 0x568(%rsp)
setne %al
movb %al, 0x44(%rsp)
movb 0x44(%rsp), %al
testb $0x1, %al
jne 0x7695
jmp 0x775e
cmpl $0x0, 0x4e8(%rsp)
jne 0x770c
leaq 0x498(%rsp), %rdi
movb $0x30, 0x303(%rsp)
leaq 0x303(%rsp), %rsi
callq 0xb4e0
jmp 0x76be
jmp 0x771d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x698(%rsp)
movl %eax, 0x694(%rsp)
leaq 0x390(%rsp), %rdi
callq 0x2780
jmp 0x7dd5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x698(%rsp)
movl %eax, 0x694(%rsp)
leaq 0x308(%rsp), %rdi
callq 0x2780
jmp 0x7dd5
movl 0x4e8(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x4e8(%rsp)
cmpl $0x0, 0x568(%rsp)
jne 0x7748
leaq 0x518(%rsp), %rdi
movb $0x30, 0x302(%rsp)
leaq 0x302(%rsp), %rsi
callq 0xb4e0
jmp 0x7746
jmp 0x7759
movl 0x568(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x568(%rsp)
jmp 0x7669
leaq 0x490(%rsp), %rdi
callq 0x5d20
jmp 0x776d
leaq 0x510(%rsp), %rdi
callq 0x5d20
jmp 0x777c
movq 0x728(%rsp), %rax
movl 0x58(%rax), %eax
movq 0x720(%rsp), %rcx
cmpl 0x58(%rcx), %eax
jle 0x77a5
movq 0x728(%rsp), %rax
movl 0x58(%rax), %eax
movl %eax, 0x40(%rsp)
jmp 0x77b4
movq 0x720(%rsp), %rax
movl 0x58(%rax), %eax
movl %eax, 0x40(%rsp)
movl 0x40(%rsp), %eax
movl %eax, 0x2fc(%rsp)
movl $0x0, 0x2f8(%rsp)
movl 0x2f8(%rsp), %eax
cmpl 0x2fc(%rsp), %eax
jge 0x780e
leaq 0x498(%rsp), %rdi
movb $0x30, 0x2f7(%rsp)
leaq 0x2f7(%rsp), %rsi
callq 0xb4e0
jmp 0x77f9
jmp 0x77fb
movl 0x2f8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2f8(%rsp)
jmp 0x77ca
leaq 0x490(%rsp), %rdi
leaq 0x510(%rsp), %rsi
callq 0x4590
movl %eax, 0x3c(%rsp)
jmp 0x7829
movl 0x3c(%rsp), %eax
movl %eax, 0x2f0(%rsp)
cmpl $0x0, 0x2f0(%rsp)
jne 0x785f
leaq 0x6a8(%rsp), %rdi
movb $0x31, 0x2ef(%rsp)
leaq 0x2ef(%rsp), %rsi
callq 0xb4e0
jmp 0x785d
jmp 0x785f
cmpl $0x2, 0x2f0(%rsp)
jne 0x788d
movq 0x48(%rsp), %rdi
leaq 0x410(%rsp), %rsi
callq 0xb7e0
jmp 0x787d
movl $0x1, 0x690(%rsp)
jmp 0x7d92
jmp 0x788f
leaq 0x490(%rsp), %rdi
addq $0x8, %rdi
callq 0xb5d0
xorb $-0x1, %al
testb $0x1, %al
jne 0x78ab
jmp 0x7ce3
leaq 0x598(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x498(%rsp), %rsi
leaq 0x2c8(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0xb840
movq 0x28(%rsp), %rdi
callq 0xb8a0
movq %rax, 0x30(%rsp)
jmp 0x78e3
movq 0x30(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0xb5f0
jmp 0x78f4
leaq 0x490(%rsp), %rdi
addq $0x8, %rdi
callq 0xb8d0
movb $0x1, 0x2c7(%rsp)
leaq 0x590(%rsp), %rsi
addq $0x8, %rsi
leaq 0x280(%rsp), %rdi
callq 0x2a80
leaq 0x2a0(%rsp), %rdi
leaq 0x280(%rsp), %rsi
callq 0x4220
leaq 0x590(%rsp), %rsi
addq $0x8, %rsi
leaq 0x260(%rsp), %rdi
callq 0x2ab0
leaq 0x2a0(%rsp), %rdi
leaq 0x260(%rsp), %rsi
callq 0xb940
testb $0x1, %al
jne 0x796f
jmp 0x799d
leaq 0x2a0(%rsp), %rdi
callq 0xb970
movsbl (%rax), %eax
cmpl $0x30, %eax
je 0x798c
movb $0x0, 0x2c7(%rsp)
jmp 0x798e
leaq 0x2a0(%rsp), %rdi
callq 0xb980
jmp 0x793b
leaq 0x590(%rsp), %rdi
leaq 0x510(%rsp), %rsi
callq 0x7fe0
movb %al, 0x1f(%rsp)
jmp 0x79b8
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x79c5
jmp 0x7cc3
testb $0x1, 0x2c7(%rsp)
jne 0x7cc3
movl $0x0, 0x25c(%rsp)
movl $0x0, 0x258(%rsp)
movl $0x9, 0x254(%rsp)
leaq 0x590(%rsp), %rdi
leaq 0x510(%rsp), %rsi
callq 0x7fe0
movb %al, 0x1e(%rsp)
jmp 0x7a0f
movb 0x1e(%rsp), %al
testb $0x1, %al
jne 0x7a1c
jmp 0x7bd5
movl 0x254(%rsp), %eax
subl 0x258(%rsp), %eax
movl %eax, 0x250(%rsp)
movl 0x250(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x24c(%rsp)
movl 0x250(%rsp), %eax
movl 0x24c(%rsp), %ecx
shll %ecx
subl %ecx, %eax
cmpl $0x0, %eax
je 0x7a6e
movl 0x24c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x7a79
movl 0x24c(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x250(%rsp)
leaq 0x1c8(%rsp), %rdi
leaq 0x510(%rsp), %rsi
leaq 0x250(%rsp), %rdx
callq 0x70c0
jmp 0x7aa3
leaq 0x590(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x4590
movl %eax, 0x14(%rsp)
jmp 0x7abe
leaq 0x1c8(%rsp), %rdi
callq 0x2780
movl 0x14(%rsp), %eax
movl %eax, 0x248(%rsp)
cmpl $0x2, 0x248(%rsp)
jne 0x7b19
movl 0x250(%rsp), %eax
movl %eax, 0x254(%rsp)
jmp 0x7bd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x698(%rsp)
movl %eax, 0x694(%rsp)
leaq 0x1c8(%rsp), %rdi
callq 0x2780
jmp 0x7dd5
movl 0x25c(%rsp), %eax
movl 0x250(%rsp), %ecx
addl %ecx, %eax
movl %eax, 0x25c(%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0x510(%rsp), %rsi
leaq 0x250(%rsp), %rdx
callq 0x70c0
jmp 0x7b4f
leaq 0x148(%rsp), %rdi
leaq 0x590(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
callq 0x67d0
jmp 0x7b6e
leaq 0x590(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x2950
leaq 0x148(%rsp), %rdi
callq 0x2780
leaq 0xc8(%rsp), %rdi
callq 0x2780
movl $0x9, 0x254(%rsp)
jmp 0x7bd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x698(%rsp)
movl %eax, 0x694(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x2780
jmp 0x7dd5
jmp 0x79f4
leaq 0x618(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x25c(%rsp), %rdi
callq 0xb5c0
movb %al, 0x13(%rsp)
jmp 0x7bf5
movq 0x8(%rsp), %rdi
movb 0x13(%rsp), %al
movb %al, 0xc7(%rsp)
leaq 0xc7(%rsp), %rsi
callq 0xb4e0
jmp 0x7c14
movb $0x1, 0xc6(%rsp)
leaq 0x590(%rsp), %rsi
addq $0x8, %rsi
leaq 0x80(%rsp), %rdi
callq 0x2a80
leaq 0xa0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x4220
leaq 0x590(%rsp), %rsi
addq $0x8, %rsi
leaq 0x60(%rsp), %rdi
callq 0x2ab0
leaq 0xa0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0xb940
testb $0x1, %al
jne 0x7c78
jmp 0x7ca6
leaq 0xa0(%rsp), %rdi
callq 0xb970
movsbl (%rax), %eax
cmpl $0x30, %eax
je 0x7c95
movb $0x0, 0xc6(%rsp)
jmp 0x7c97
leaq 0xa0(%rsp), %rdi
callq 0xb980
jmp 0x7c4a
testb $0x1, 0xc6(%rsp)
je 0x7cc1
leaq 0x590(%rsp), %rdi
addq $0x8, %rdi
callq 0x4330
jmp 0x7cde
leaq 0x618(%rsp), %rdi
movb $0x30, 0x5f(%rsp)
leaq 0x5f(%rsp), %rsi
callq 0xb4e0
jmp 0x7cdc
jmp 0x7cde
jmp 0x788f
leaq 0x6a0(%rsp), %rdi
leaq 0x610(%rsp), %rsi
callq 0xb470
jmp 0x7cfa
jmp 0x7cfc
movq 0x728(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x7d1c
movq 0x720(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x7d3c
movq 0x728(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2b, %eax
jne 0x7d46
movq 0x720(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2b, %eax
jne 0x7d46
movb $0x2b, 0x6a0(%rsp)
jmp 0x7d4e
movb $0x2d, 0x6a0(%rsp)
movl 0x2fc(%rsp), %eax
movl %eax, 0x6f8(%rsp)
movb $0x0, 0x6fc(%rsp)
leaq 0x6a0(%rsp), %rdi
callq 0x5d20
jmp 0x7d73
movq 0x48(%rsp), %rdi
leaq 0x6a0(%rsp), %rsi
callq 0xb7e0
jmp 0x7d87
movl $0x1, 0x690(%rsp)
leaq 0x410(%rsp), %rdi
callq 0x2780
leaq 0x490(%rsp), %rdi
callq 0x2780
leaq 0x510(%rsp), %rdi
callq 0x2780
leaq 0x590(%rsp), %rdi
callq 0x2780
leaq 0x610(%rsp), %rdi
callq 0x2780
jmp 0x7e18
leaq 0x410(%rsp), %rdi
callq 0x2780
leaq 0x490(%rsp), %rdi
callq 0x2780
leaq 0x510(%rsp), %rdi
callq 0x2780
leaq 0x590(%rsp), %rdi
callq 0x2780
leaq 0x610(%rsp), %rdi
callq 0x2780
jmp 0x7e32
leaq 0x6a0(%rsp), %rdi
callq 0x2780
movq 0x50(%rsp), %rax
addq $0x738, %rsp            # imm = 0x738
retq
leaq 0x6a0(%rsp), %rdi
callq 0x2780
movq 0x698(%rsp), %rdi
callq 0x2300
nopl (%rax)