// 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;
    }

    if((left.decimals != 0) || (right.decimals != 0)) {
        tmp.error_code = "Modulus Between Non Integers";
        return tmp;
    }

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

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

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

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

    if(check == 0) {
        return zero;
    }
    if(check == 2) {
        return left;
    }
    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));
                ret = R;

                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 {
                ret = R;
                Q.number.push_front('0');
            }
        }

        Q.LeadTrim();
        ret.LeadTrim();
        tmp = ret;
    }

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

    if(!BigFloat::CompareNum(tmp, zero))
        tmp.sign = '+';

    tmp.error = 0;
    return tmp;
}

// Assembly:
subq $0x798, %rsp            # imm = 0x798
movq %rdi, 0x40(%rsp)
movq %rdi, %rax
movq %rax, 0x48(%rsp)
movq %rdi, 0x790(%rsp)
movq %rsi, 0x788(%rsp)
movq %rdx, 0x780(%rsp)
leaq 0x700(%rsp), %rdi
callq 0x28c0
movq 0x788(%rsp), %rax
testb $0x1, 0x5c(%rax)
jne 0x8e65
movq 0x780(%rsp), %rax
testb $0x1, 0x5c(%rax)
je 0x8ea2
movq 0x40(%rsp), %rdi
leaq 0x700(%rsp), %rsi
callq 0xb7e0
jmp 0x8e79
movl $0x1, 0x6f0(%rsp)
jmp 0x984f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6f8(%rsp)
movl %eax, 0x6f4(%rsp)
jmp 0x9869
movq 0x788(%rsp), %rax
cmpl $0x0, 0x58(%rax)
jne 0x8ebe
movq 0x780(%rsp), %rax
cmpl $0x0, 0x58(%rax)
je 0x8ef8
leaq 0x760(%rsp), %rdi
leaq 0x7176(%rip), %rsi      # 0x10043
callq 0x2270
jmp 0x8ed4
movq 0x40(%rsp), %rdi
leaq 0x700(%rsp), %rsi
callq 0xb7e0
jmp 0x8ee8
movl $0x1, 0x6f0(%rsp)
jmp 0x984f
leaq 0x670(%rsp), %rdi
callq 0x28c0
jmp 0x8f07
leaq 0x5f0(%rsp), %rdi
callq 0x28c0
jmp 0x8f16
leaq 0x570(%rsp), %rdi
callq 0x28c0
jmp 0x8f25
leaq 0x4f0(%rsp), %rdi
callq 0x28c0
jmp 0x8f34
leaq 0x470(%rsp), %rdi
callq 0x28c0
jmp 0x8f43
leaq 0x3f0(%rsp), %rdi
callq 0x28c0
jmp 0x8f52
leaq 0x470(%rsp), %rdi
xorl %esi, %esi
callq 0x5de0
jmp 0x8f63
movq 0x780(%rsp), %rdi
leaq 0x470(%rsp), %rsi
callq 0x7e50
movb %al, 0x3f(%rsp)
jmp 0x8f7e
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0x8f8b
jmp 0x905b
leaq 0x760(%rsp), %rdi
leaq 0x70c6(%rip), %rsi      # 0x10060
callq 0x2270
jmp 0x8fa1
movq 0x40(%rsp), %rdi
leaq 0x700(%rsp), %rsi
callq 0xb7e0
jmp 0x8fb5
movl $0x1, 0x6f0(%rsp)
jmp 0x97af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6f8(%rsp)
movl %eax, 0x6f4(%rsp)
jmp 0x9840
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6f8(%rsp)
movl %eax, 0x6f4(%rsp)
jmp 0x9833
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6f8(%rsp)
movl %eax, 0x6f4(%rsp)
jmp 0x9826
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6f8(%rsp)
movl %eax, 0x6f4(%rsp)
jmp 0x9819
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6f8(%rsp)
movl %eax, 0x6f4(%rsp)
jmp 0x980c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6f8(%rsp)
movl %eax, 0x6f4(%rsp)
jmp 0x97ff
movq 0x788(%rsp), %rdi
leaq 0x470(%rsp), %rsi
callq 0x7ed0
movb %al, 0x3e(%rsp)
jmp 0x9076
movb 0x3e(%rsp), %al
testb $0x1, %al
jne 0x9080
jmp 0x9099
movq 0x788(%rsp), %rsi
leaq 0x370(%rsp), %rdi
callq 0x2830
jmp 0x9097
jmp 0x90c5
movq 0x788(%rsp), %rsi
movl $0xffffffff, 0x36c(%rsp) # imm = 0xFFFFFFFF
leaq 0x370(%rsp), %rdi
leaq 0x36c(%rsp), %rdx
callq 0x70c0
jmp 0x90c3
jmp 0x90c5
leaq 0x4f0(%rsp), %rdi
leaq 0x370(%rsp), %rsi
callq 0xb470
jmp 0x90dc
leaq 0x370(%rsp), %rdi
callq 0x2780
movq 0x780(%rsp), %rdi
leaq 0x470(%rsp), %rsi
callq 0x7ed0
movb %al, 0x3d(%rsp)
jmp 0x9104
movb 0x3d(%rsp), %al
testb $0x1, %al
jne 0x910e
jmp 0x9127
movq 0x780(%rsp), %rsi
leaq 0x2e8(%rsp), %rdi
callq 0x2830
jmp 0x9125
jmp 0x9153
movq 0x780(%rsp), %rsi
movl $0xffffffff, 0x2e4(%rsp) # imm = 0xFFFFFFFF
leaq 0x2e8(%rsp), %rdi
leaq 0x2e4(%rsp), %rdx
callq 0x70c0
jmp 0x9151
jmp 0x9153
leaq 0x570(%rsp), %rdi
leaq 0x2e8(%rsp), %rsi
callq 0xb470
jmp 0x916a
leaq 0x2e8(%rsp), %rdi
callq 0x2780
movb $0x2b, 0x5f0(%rsp)
movb $0x0, 0x64c(%rsp)
leaq 0x4f0(%rsp), %rdi
leaq 0x570(%rsp), %rsi
callq 0x4590
movl %eax, 0x38(%rsp)
jmp 0x91a2
movl 0x38(%rsp), %eax
movl %eax, 0x2e0(%rsp)
cmpl $0x0, 0x2e0(%rsp)
jne 0x9227
movq 0x40(%rsp), %rdi
leaq 0x470(%rsp), %rsi
callq 0xb7e0
jmp 0x91cb
movl $0x1, 0x6f0(%rsp)
jmp 0x97af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6f8(%rsp)
movl %eax, 0x6f4(%rsp)
leaq 0x370(%rsp), %rdi
callq 0x2780
jmp 0x97ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6f8(%rsp)
movl %eax, 0x6f4(%rsp)
leaq 0x2e8(%rsp), %rdi
callq 0x2780
jmp 0x97ff
cmpl $0x2, 0x2e0(%rsp)
jne 0x9255
movq 0x40(%rsp), %rdi
movq 0x788(%rsp), %rsi
callq 0x2830
jmp 0x9245
movl $0x1, 0x6f0(%rsp)
jmp 0x97af
jmp 0x9257
leaq 0x4f0(%rsp), %rdi
addq $0x8, %rdi
callq 0xb5d0
xorb $-0x1, %al
testb $0x1, %al
jne 0x9273
jmp 0x96d3
leaq 0x5f8(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x4f8(%rsp), %rsi
leaq 0x2c0(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0xb840
movq 0x28(%rsp), %rdi
callq 0xb8a0
movq %rax, 0x30(%rsp)
jmp 0x92ab
movq 0x30(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0xb5f0
jmp 0x92bc
leaq 0x4f0(%rsp), %rdi
addq $0x8, %rdi
callq 0xb8d0
movb $0x1, 0x2bf(%rsp)
leaq 0x5f0(%rsp), %rsi
addq $0x8, %rsi
leaq 0x278(%rsp), %rdi
callq 0x2a80
leaq 0x298(%rsp), %rdi
leaq 0x278(%rsp), %rsi
callq 0x4220
leaq 0x5f0(%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 0x9337
jmp 0x9365
leaq 0x298(%rsp), %rdi
callq 0xb970
movsbl (%rax), %eax
cmpl $0x30, %eax
je 0x9354
movb $0x0, 0x2bf(%rsp)
jmp 0x9356
leaq 0x298(%rsp), %rdi
callq 0xb980
jmp 0x9303
leaq 0x5f0(%rsp), %rdi
leaq 0x570(%rsp), %rsi
callq 0x7fe0
movb %al, 0x1f(%rsp)
jmp 0x9380
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x938d
jmp 0x969c
testb $0x1, 0x2bf(%rsp)
jne 0x969c
movl $0x0, 0x254(%rsp)
movl $0x0, 0x250(%rsp)
movl $0x9, 0x24c(%rsp)
leaq 0x5f0(%rsp), %rdi
leaq 0x570(%rsp), %rsi
callq 0x7fe0
movb %al, 0x1e(%rsp)
jmp 0x93d7
movb 0x1e(%rsp), %al
testb $0x1, %al
jne 0x93e4
jmp 0x959d
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 0x9436
movl 0x244(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x9441
movl 0x244(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x248(%rsp)
leaq 0x1c0(%rsp), %rdi
leaq 0x570(%rsp), %rsi
leaq 0x248(%rsp), %rdx
callq 0x70c0
jmp 0x946b
leaq 0x5f0(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x4590
movl %eax, 0x14(%rsp)
jmp 0x9486
leaq 0x1c0(%rsp), %rdi
callq 0x2780
movl 0x14(%rsp), %eax
movl %eax, 0x240(%rsp)
cmpl $0x2, 0x240(%rsp)
jne 0x94e1
movl 0x248(%rsp), %eax
movl %eax, 0x24c(%rsp)
jmp 0x9598
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6f8(%rsp)
movl %eax, 0x6f4(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x2780
jmp 0x97ff
movl 0x254(%rsp), %eax
movl 0x248(%rsp), %ecx
addl %ecx, %eax
movl %eax, 0x254(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x570(%rsp), %rsi
leaq 0x248(%rsp), %rdx
callq 0x70c0
jmp 0x9517
leaq 0x140(%rsp), %rdi
leaq 0x5f0(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
callq 0x67d0
jmp 0x9536
leaq 0x5f0(%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 0x9598
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6f8(%rsp)
movl %eax, 0x6f4(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x2780
jmp 0x97ff
jmp 0x93bc
leaq 0x678(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x254(%rsp), %rdi
callq 0xb5c0
movb %al, 0x13(%rsp)
jmp 0x95bd
movq 0x8(%rsp), %rdi
movb 0x13(%rsp), %al
movb %al, 0xbf(%rsp)
leaq 0xbf(%rsp), %rsi
callq 0xb4e0
jmp 0x95dc
leaq 0x3f0(%rsp), %rdi
leaq 0x5f0(%rsp), %rsi
callq 0xb470
jmp 0x95f3
movb $0x1, 0xbe(%rsp)
leaq 0x5f0(%rsp), %rsi
addq $0x8, %rsi
leaq 0x78(%rsp), %rdi
callq 0x2a80
leaq 0x98(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x4220
leaq 0x5f0(%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 0x9651
jmp 0x967f
leaq 0x98(%rsp), %rdi
callq 0xb970
movsbl (%rax), %eax
cmpl $0x30, %eax
je 0x966e
movb $0x0, 0xbe(%rsp)
jmp 0x9670
leaq 0x98(%rsp), %rdi
callq 0xb980
jmp 0x9623
testb $0x1, 0xbe(%rsp)
je 0x969a
leaq 0x5f0(%rsp), %rdi
addq $0x8, %rdi
callq 0x4330
jmp 0x96ce
leaq 0x3f0(%rsp), %rdi
leaq 0x5f0(%rsp), %rsi
callq 0xb470
jmp 0x96b3
leaq 0x678(%rsp), %rdi
movb $0x30, 0x57(%rsp)
leaq 0x57(%rsp), %rsi
callq 0xb4e0
jmp 0x96cc
jmp 0x96ce
jmp 0x9257
leaq 0x670(%rsp), %rdi
callq 0x5d20
jmp 0x96e2
leaq 0x3f0(%rsp), %rdi
callq 0x5d20
jmp 0x96f1
leaq 0x700(%rsp), %rdi
leaq 0x3f0(%rsp), %rsi
callq 0xb470
jmp 0x9708
jmp 0x970a
movq 0x788(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x972a
movq 0x780(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x974a
movq 0x788(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2b, %eax
jne 0x9754
movq 0x780(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2b, %eax
jne 0x9754
movb $0x2b, 0x700(%rsp)
jmp 0x975c
movb $0x2d, 0x700(%rsp)
leaq 0x700(%rsp), %rdi
leaq 0x470(%rsp), %rsi
callq 0x4590
movl %eax, 0x4(%rsp)
jmp 0x9777
movl 0x4(%rsp), %eax
cmpl $0x0, %eax
jne 0x9788
movb $0x2b, 0x700(%rsp)
movq 0x40(%rsp), %rdi
movb $0x0, 0x75c(%rsp)
leaq 0x700(%rsp), %rsi
callq 0xb7e0
jmp 0x97a4
movl $0x1, 0x6f0(%rsp)
leaq 0x3f0(%rsp), %rdi
callq 0x2780
leaq 0x470(%rsp), %rdi
callq 0x2780
leaq 0x4f0(%rsp), %rdi
callq 0x2780
leaq 0x570(%rsp), %rdi
callq 0x2780
leaq 0x5f0(%rsp), %rdi
callq 0x2780
leaq 0x670(%rsp), %rdi
callq 0x2780
jmp 0x984f
leaq 0x3f0(%rsp), %rdi
callq 0x2780
leaq 0x470(%rsp), %rdi
callq 0x2780
leaq 0x4f0(%rsp), %rdi
callq 0x2780
leaq 0x570(%rsp), %rdi
callq 0x2780
leaq 0x5f0(%rsp), %rdi
callq 0x2780
leaq 0x670(%rsp), %rdi
callq 0x2780
jmp 0x9869
leaq 0x700(%rsp), %rdi
callq 0x2780
movq 0x48(%rsp), %rax
addq $0x798, %rsp            # imm = 0x798
retq
leaq 0x700(%rsp), %rdi
callq 0x2780
movq 0x6f8(%rsp), %rdi
callq 0x2300
nopw %cs:(%rax,%rax)