// File: /workspace/github_c_makefile_star2_O2/mirth-lang[P]mirth/bin/mirth1.c
// Function: int_divmod
static INT int_divmod(INT a, INT b, INT *r) {
    EXPECT(!int_is_zero_(b), "Division by zero.");
    if (int_is_zero_(a)) { int_decref(b); *r = a; return a; }
    if (GET_I63(b) == 1) { *r = WRAP_I63(0); return a; }
    if (GET_I63(b) == -1) { *r = WRAP_I63(0); return int_negate(a); }
    if (IS_I63(a) || (GET_BIG(a)->size == 2)) {
        if (IS_I63(b) || GET_BIG(b)->size == 2) {
            int64_t ia = int_to_i64(a);
            int64_t ib = int_to_i64(b);
            ASSERT((ib != 0) && (ib != -1));
            int64_t iq = ia / ib;
            int64_t ir = ia % ib;
            if (ir && ((ia < 0) ^ (ib < 0))) {
                iq -= 1;
                ir += ib;
            }
            *r = i64_to_int(ir);
            return i64_to_int(iq);
        } else {
            BIG* bb = GET_BIG(b);
            bool an = int_is_negative_(a);
            bool bn = SIGN_RADIX(bb) != 0;
            if (an ^ bn) {
                *r = int_add(a, b);
                return WRAP_I63(-1);
            } else {
                big_decref(bb);
                *r = a;
                return WRAP_I63(0);
            }
        }
    } else {
        bool an = int_is_negative_(a);
        bool bn = int_is_negative_(b);
        INT ma = an ? int_negate(a) : a;
        INT mb = bn ? int_negate(b) : b;
        ASSERT(IS_BIG(ma));
        INT mq, mr;
        int_incref(mb);
        big_pos_udivmod(GET_BIG(ma),mb,&mq,&mr);
        if (an ^ bn) {
            if (int_is_zero_(mr)) {
                int_decref(mb);
                mq = int_negate(mq);
            } else {
                mr = int_sub(mb, mr);
                mq = int_negate(int_add(mq, WRAP_I63(1)));
            }
        } else {
            int_decref(mb);
        }
        if (bn) mr = int_negate(mr);
        *r = mr;
        return mq;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
cmpq $0x1, %rsi
je 0x13668
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, %r12
cmpq $0x1, %rdi
jne 0x131a6
movq %rbx, %rdi
callq 0x136e3
movq $0x1, (%r13)
pushq $0x1
popq %r12
jmp 0x131b8
leaq -0x3(%rbx), %rax
cmpq $0x1, %rax
ja 0x131ca
movq $0x1, (%r13)
movq %r12, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $-0x2, %rbx
jb 0x131ee
movq $0x1, (%r13)
movq %r12, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe53d
testb $0x1, %r12b
jne 0x131fc
cmpq $0x2, 0x10(%r12)
jne 0x13255
testb $0x1, %bl
movq %rbx, %r14
jne 0x13212
movq 0x10(%r14), %rbx
cmpq $0x2, %rbx
jne 0x132a2
movq %r12, %rdi
callq 0xdc43
movq %rax, %r15
movq %r14, %rdi
callq 0xdc43
movq %rax, %rcx
decq %rax
cmpq $-0x2, %rax
jae 0x13687
movq %r15, %rax
cqto
idivq %rcx
movq %rax, %r14
testq %rdx, %rdx
je 0x13281
movq %rdx, %rdi
xorq %rcx, %r15
jns 0x13283
decq %r14
addq %rcx, %rdi
jmp 0x13283
movq %r13, -0x48(%rbp)
movq %r12, %rdi
callq 0x136f5
movl %eax, %r15d
movq %rbx, %rdi
callq 0x136f5
movl %eax, %r14d
testb %r15b, %r15b
je 0x132ca
movq %r12, %rdi
callq 0xe53d
movq %rax, %r13
jmp 0x132cd
xorl %edi, %edi
callq 0xd86d
movq %rax, (%r13)
movq %r14, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd86d
movq %r12, %rdi
callq 0x136f5
cmpl $0x0, 0x14(%r14,%rbx,4)
setns %cl
xorb %al, %cl
je 0x13498
movq %r14, %rdi
callq 0xe181
pushq $0x1
jmp 0x134a8
movq %r12, %r13
testb %r14b, %r14b
je 0x132dd
movq %rbx, %rdi
callq 0xe53d
movq %rax, %rbx
testb $0x1, %r13b
jne 0x13695
testb $0x1, %bl
movb %r14b, -0x2a(%rbp)
movb %r15b, -0x29(%rbp)
jne 0x1334d
incl (%rbx)
movq 0x10(%rbx), %rax
leaq -0x1(%rax), %r14
movl 0x14(%rbx,%rax,4), %r15d
testl %r15d, %r15d
jne 0x1331d
testq %r14, %r14
je 0x136c7
movl 0x10(%rbx,%rax,4), %r15d
addq $-0x2, %rax
movq %rax, %r14
xorl %eax, %eax
cmpq %rax, %r14
je 0x134b5
cmpl $0x0, 0x18(%rbx,%rax,4)
leaq 0x1(%rax), %rax
je 0x1331f
movq 0x10(%r13), %rdi
cmpq %rdi, %r14
jae 0x1355b
movq %rbx, -0x38(%rbp)
movq %r13, %rbx
addq $0x10, %rbx
jmp 0x1339e
leaq -0x1(%rbx), %rax
movq %rax, %rcx
sarq %rcx
cmpq $0x1, %rcx
jle 0x1369e
xorl %r14d, %r14d
movq %rcx, %r15
shrq $0x20, %r15
setne %r14b
movq 0x10(%r13), %rdi
cmpq %r14, %rdi
jbe 0x1355b
movq %rbx, -0x38(%rbp)
leaq 0x10(%r13), %rbx
testq %r15, %r15
setne %dl
cmovel %ecx, %r15d
shrq %rax
testl %eax, %eax
setne %al
testb %al, %dl
je 0x134ca
testl %r15d, %r15d
je 0x136be
subq %r14, %rdi
addq $0x2, %rdi
callq 0x524c
movq %rax, %r12
movq (%rbx), %rsi
movq %rsi, %rbx
subq %r14, %rbx
movq %rbx, 0x10(%rax)
movq %r13, %rdi
callq 0xe5d9
movq %rax, %r13
movq 0x10(%rax), %rcx
movq %rcx, %rsi
movq %r14, -0x50(%rbp)
subq %r14, %rsi
movl %r15d, %eax
movq %rax, -0x60(%rbp)
incq %rax
movq %rax, -0x58(%rbp)
movq %rsi, %r8
subq $0x1, %r8
jb 0x13586
movq -0x50(%rbp), %rax
movq %r8, -0x40(%rbp)
leaq (%r8,%rax), %r15
addq %rax, %rsi
cmpq %rsi, %rcx
jbe 0x13412
movl 0x18(%r13,%rsi,4), %eax
jmp 0x1341a
movl 0x14(%r13,%rcx,4), %eax
sarl $0x1f, %eax
movq -0x40(%rbp), %r8
cmpq %r15, %rcx
jbe 0x1342a
movl 0x18(%r13,%r15,4), %edx
jmp 0x13432
movl 0x14(%r13,%rcx,4), %edx
sarl $0x1f, %edx
movl %edx, %edx
shlq $0x20, %rax
orq %rdx, %rax
cmpq -0x60(%rbp), %rax
jbe 0x13490
movq %rsi, %r14
xorl %edx, %edx
divq -0x58(%rbp)
movq %r8, %rcx
movq %rax, %rdx
testq %rdx, %rdx
je 0x13473
cmpq %rbx, %rcx
jae 0x13473
movq %rdx, %rsi
shrq $0x20, %rsi
addl %edx, 0x18(%r12,%rcx,4)
leaq 0x1(%rcx), %rcx
adcq $0x0, %rsi
movq %rsi, %rdx
jmp 0x13450
movq %r13, %rdi
movq -0x38(%rbp), %rsi
movl %eax, %edx
movq %r8, %rcx
callq 0x13713
movq 0x10(%r13), %rcx
movq %r14, %rsi
jmp 0x13406
movq %r8, %rsi
jmp 0x133ed
movq %r12, %rdi
movq %r14, %rsi
callq 0xdd03
movq %rax, %r12
pushq $-0x1
popq %rax
movq %r12, (%r13)
movq %rax, %r12
jmp 0x131b8
cmpq 0x10(%r13), %r14
jae 0x1355b
movq %rbx, -0x38(%rbp)
movq %r13, %rbx
addq $0x10, %rbx
movq -0x38(%rbp), %rdi
callq 0x136e3
testl %r15d, %r15d
je 0x136ac
movq (%rbx), %rdi
subq %r14, %rdi
jbe 0x136b5
addq $0x2, %rdi
callq 0x524c
movq %rax, %r12
movq (%rbx), %rsi
movq %rsi, %rax
subq %r14, %rax
movq %rax, 0x10(%r12)
movq %r13, %rdi
callq 0xe5d9
movq %rax, %rdi
movq 0x10(%rax), %rcx
movl %r15d, %esi
movq %r14, %r9
leaq (,%r14,4), %rax
negq %rax
leaq (%r12,%rax), %r8
addq $0x14, %r8
xorl %edx, %edx
movq -0x38(%rbp), %rbx
movb -0x2a(%rbp), %r14b
movb -0x29(%rbp), %r15b
cmpq %rcx, %r9
je 0x1356c
shlq $0x20, %rdx
movl 0x14(%rdi,%rcx,4), %eax
andl $0x0, 0x14(%rdi,%rcx,4)
orq %rdx, %rax
xorl %edx, %edx
divq %rsi
movl %eax, (%r8,%rcx,4)
decq %rcx
jmp 0x13538
movq %rbx, %rdi
callq 0x136e3
pushq $0x1
popq %r12
jmp 0x135f8
movl %edx, 0x18(%rdi,%r9,4)
callq 0xe679
movq %rax, %r13
movq %r12, %rdi
callq 0xe679
movq %rax, %r12
jmp 0x13600
movq %r13, %rdi
movq -0x38(%rbp), %r15
movq %r15, %rsi
callq 0x1381e
testl %eax, %eax
js 0x135d7
xorl %r14d, %r14d
pushq $0x1
popq %rdx
movq %r13, %rdi
movq %r15, -0x38(%rbp)
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x13713
cmpq %r14, %rbx
je 0x135c0
incl 0x18(%r12,%r14,4)
leaq 0x1(%r14), %r14
je 0x135b0
movq %r13, %rdi
movq -0x38(%rbp), %r15
movq %r15, %rsi
callq 0x1381e
testl %eax, %eax
jns 0x136d5
movq %r15, %rdi
callq 0x136e3
movq %r13, %rdi
callq 0xe679
movq %rax, %r13
movq %r12, %rdi
callq 0xe679
movq %rax, %r12
movq %r15, %rbx
movb -0x2a(%rbp), %r14b
movb -0x29(%rbp), %r15b
movq %rbx, %rdi
cmpb %r14b, %r15b
je 0x13624
cmpq $0x1, %r13
jne 0x1362b
callq 0x136e3
movq %r12, %rdi
callq 0xe53d
movq %rax, %r12
pushq $0x1
popq %r13
jmp 0x1364c
callq 0x136e3
jmp 0x1364c
movq %r13, %rsi
callq 0xe191
movq %rax, %r13
pushq $0x3
popq %rsi
movq %r12, %rdi
callq 0xdd03
movq %rax, %rdi
callq 0xe53d
movq %rax, %r12
testb %r14b, %r14b
je 0x1365c
movq %r13, %rdi
callq 0xe53d
movq %rax, %r13
movq -0x48(%rbp), %rax
movq %r13, (%rax)
jmp 0x131b8
leaq 0xc2abe(%rip), %rsi     # 0xd612d
pushq $0x2
popq %rdi
pushq $0x12
popq %rdx
callq 0x5060
callq 0x52ae
pushq $0x1
popq %rdi
callq 0x5130
leaq 0xc2ab2(%rip), %rsi     # 0xd6140
pushq $0x2
popq %rdi
pushq $0x45
jmp 0x13674
leaq 0xc2aea(%rip), %rsi     # 0xd6186
jmp 0x136ce
leaq 0xc2b53(%rip), %rsi     # 0xd61f8
pushq $0x2
popq %rdi
pushq $0x34
jmp 0x13674
leaq 0xc2b7a(%rip), %rsi     # 0xd622d
jmp 0x136ce
leaq 0xc2baa(%rip), %rsi     # 0xd6266
jmp 0x1368e
leaq 0xc2be7(%rip), %rsi     # 0xd62ac
jmp 0x136ce
leaq 0xc2af1(%rip), %rsi     # 0xd61bf
pushq $0x2
popq %rdi
pushq $0x38
jmp 0x13674
leaq 0xc2c09(%rip), %rsi     # 0xd62e5
pushq $0x2
popq %rdi
pushq $0x44
jmp 0x13674