// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
cmpq $0x1, %rsi
je 0x14482
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %r12
cmpq $0x1, %rdi
jne 0x13ebe
testb $0x1, %r14b
jne 0x13eae
decl (%r14)
jne 0x13eae
movq %r14, %rdi
callq 0x5030
movq $0x1, (%r13)
movl $0x1, %r12d
jmp 0x13ed0
leaq -0x3(%r14), %rax
cmpq $0x1, %rax
ja 0x13ee2
movq $0x1, (%r13)
movq %r12, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $-0x2, %r14
jb 0x13f06
movq $0x1, (%r13)
movq %r12, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xee12
testb $0x1, %r12b
jne 0x13f1b
movq 0x10(%r12), %rax
cmpq $0x2, %rax
jne 0x13fa7
testb $0x1, %r14b
jne 0x13f2f
movq 0x10(%r14), %rax
cmpq $0x2, %rax
jne 0x14007
movq %r12, %rdi
callq 0xe445
movq %rax, %r12
movq %r14, %rdi
callq 0xe445
movq %rax, %rcx
decq %rax
cmpq $-0x2, %rax
jae 0x144a7
movabsq $0x4000000000000000, %rbx # imm = 0x4000000000000000
movq %r12, %rax
cqto
idivq %rcx
movq %rax, %r14
testq %rdx, %rdx
je 0x13fc0
movq %rdx, %r15
xorq %rcx, %r12
sarq $0x3f, %r12
andq %r12, %rcx
addq %rcx, %r15
addq %r12, %r14
movq %r15, %rax
addq %rbx, %rax
jns 0x13fc3
movl $0x3, %edi
callq 0x524c
movq $0x2, 0x10(%rax)
movl %r15d, 0x18(%rax)
shrq $0x20, %r15
movl %r15d, 0x1c(%rax)
jmp 0x13fcb
movl 0x14(%r12,%rax,4), %ecx
testb $0x1, %r14b
jne 0x1401c
movq 0x10(%r14), %rax
movl 0x14(%r14,%rax,4), %ebx
shrl $0x1f, %ebx
jmp 0x14022
xorl %r15d, %r15d
leaq 0x1(,%r15,2), %rax
movq %rax, (%r13)
addq %r14, %rbx
js 0x13fe1
leaq 0x1(,%r14,2), %r12
jmp 0x13ed0
movl $0x3, %edi
callq 0x524c
movq %rax, %r12
movq $0x2, 0x10(%rax)
movl %r14d, 0x18(%rax)
shrq $0x20, %r14
movl %r14d, 0x1c(%rax)
jmp 0x13ed0
testb $0x1, %r12b
jne 0x1402e
movq 0x10(%r12), %rcx
movl 0x14(%r12,%rcx,4), %ecx
shrl $0x1f, %ecx
jmp 0x14034
testq %r14, %r14
setle %bl
movl %ecx, -0x3c(%rbp)
testl %ecx, %ecx
js 0x14060
movq %r12, %r15
jmp 0x1406b
testq %r12, %r12
setle %cl
cmpl $0x0, 0x14(%r14,%rax,4)
setns %al
xorb %cl, %al
je 0x141dd
decl (%r14)
movl $0x1, %ebx
jne 0x141f2
movq %r14, %rdi
callq 0x5030
jmp 0x141f2
movq %r12, %rdi
callq 0xee12
movq %rax, %r15
testb %bl, %bl
je 0x1407a
movq %r14, %rdi
callq 0xee12
movq %rax, %r14
testb $0x1, %r15b
jne 0x144b5
testb $0x1, %r14b
jne 0x140fe
movl (%r14), %eax
leal 0x1(%rax), %ecx
movl %ecx, (%r14)
movq 0x10(%r14), %rcx
leaq -0x1(%rcx), %r12
movl 0x14(%r14,%rcx,4), %esi
testl %esi, %esi
jne 0x140b9
testq %r12, %r12
je 0x144e7
movl 0x10(%r14,%rcx,4), %esi
addq $-0x2, %rcx
movq %rcx, %r12
testq %r12, %r12
je 0x140d4
xorl %ecx, %ecx
cmpl $0x0, 0x18(%r14,%rcx,4)
jne 0x14222
incq %rcx
cmpq %rcx, %r12
jne 0x140c0
cmpq 0x10(%r15), %r12
jae 0x143c3
movl %ebx, -0x2c(%rbp)
leaq 0x10(%r15), %rbx
movl %eax, (%r14)
testl %eax, %eax
jne 0x1414d
movq %r14, %rdi
movq %rsi, -0x38(%rbp)
callq 0x5030
movq -0x38(%rbp), %rsi
jmp 0x1414d
leaq -0x1(%r14), %rax
movq %rax, %rcx
sarq %rcx
cmpq $0x1, %rcx
jle 0x144be
xorl %r12d, %r12d
movq %rcx, %rsi
shrq $0x20, %rsi
setne %r12b
movq 0x10(%r15), %rdi
cmpq %r12, %rdi
jbe 0x141fe
movl %ebx, -0x2c(%rbp)
leaq 0x10(%r15), %rbx
testq %rsi, %rsi
sete %dl
cmovel %ecx, %esi
shrq %rax
testl %eax, %eax
sete %al
orb %dl, %al
je 0x14239
testl %esi, %esi
je 0x144cc
movq %rsi, -0x38(%rbp)
movq (%rbx), %rdi
subq %r12, %rdi
jbe 0x144d5
addq $0x2, %rdi
callq 0x524c
movq (%rbx), %rsi
movq %rax, %rbx
movq %rsi, %rax
subq %r12, %rax
movq %rax, 0x10(%rbx)
movq %r15, %rdi
callq 0xeefb
movq %rax, %rdi
movq 0x10(%rax), %rcx
cmpq %r12, %rcx
movq %rbx, -0x50(%rbp)
je 0x143da
movl -0x38(%rbp), %esi
leaq (,%r12,4), %rax
movq %rbx, %r8
subq %rax, %r8
addq $0x14, %r8
xorl %edx, %edx
movl -0x2c(%rbp), %ebx
shlq $0x20, %rdx
movl 0x14(%rdi,%rcx,4), %eax
orq %rdx, %rax
movl $0x0, 0x14(%rdi,%rcx,4)
xorl %edx, %edx
divq %rsi
movl %eax, (%r8,%rcx,4)
decq %rcx
cmpq %rcx, %r12
jne 0x141b4
jmp 0x143df
movq %r12, %rdi
movq %r14, %rsi
callq 0xe50f
movq %rax, %r12
movq $-0x1, %rbx
movq %r12, (%r13)
movq %rbx, %r12
jmp 0x13ed0
cmpl $0x0, -0x3c(%rbp)
sets %al
xorb %bl, %al
movl $0x1, %r12d
je 0x1446a
cmpq $0x1, %r15
je 0x1441c
jmp 0x14444
movq 0x10(%r15), %rdi
cmpq %rdi, %r12
jae 0x143c3
movl %ebx, -0x2c(%rbp)
movq %r15, %rbx
addq $0x10, %rbx
movq %r14, -0x58(%rbp)
movq %r13, -0x68(%rbp)
movq %rsi, -0x38(%rbp)
testl %esi, %esi
je 0x144de
subq %r12, %rdi
addq $0x2, %rdi
callq 0x524c
movq %r12, %r14
movq %rax, %r12
movq (%rbx), %rsi
movq %rsi, %rbx
subq %r14, %rbx
movq %rbx, 0x10(%rax)
movq %r15, %rdi
movq %rsi, -0x60(%rbp)
callq 0xeefb
movq %rax, %r15
movq 0x10(%rax), %r8
movq %r8, %rcx
movq %r14, -0x48(%rbp)
subq %r14, %rcx
je 0x14338
movl -0x38(%rbp), %eax
movq %rax, -0x50(%rbp)
incq %rax
movq %rax, -0x70(%rbp)
movq %rcx, %r13
leaq -0x1(%rcx), %rax
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %rax
leaq (%rcx,%rax), %r14
decq %r14
addq %rax, %r13
cmpq %r13, %r8
jbe 0x142c2
movl 0x18(%r15,%r13,4), %eax
jmp 0x142ca
movl 0x14(%r15,%r8,4), %eax
sarl $0x1f, %eax
movq -0x38(%rbp), %rcx
cmpq %r14, %r8
jbe 0x142da
movl 0x18(%r15,%r14,4), %edx
jmp 0x142e2
movl 0x14(%r15,%r8,4), %edx
sarl $0x1f, %edx
movl %edx, %edx
shlq $0x20, %rax
orq %rdx, %rax
cmpq -0x50(%rbp), %rax
jbe 0x1432f
xorl %edx, %edx
divq -0x70(%rbp)
movq %rax, %rdi
movq %rcx, %rdx
cmpq %rbx, %rdx
jae 0x1431b
movq %rdi, %rsi
shrq $0x20, %rsi
addl %edi, 0x18(%r12,%rdx,4)
leaq 0x1(%rdx), %rdx
adcq $0x0, %rsi
movq %rsi, %rdi
jne 0x142fd
movq %r15, %rdi
movq -0x58(%rbp), %rsi
movl %eax, %edx
callq 0x14503
movq 0x10(%r15), %r8
jmp 0x142b6
testq %rcx, %rcx
jne 0x1429d
movq %r15, %rdi
movq -0x58(%rbp), %r14
movq %r14, %rsi
callq 0x14634
testl %eax, %eax
movq -0x68(%rbp), %r13
movl -0x2c(%rbp), %ebx
js 0x143a0
movq %r15, %rdi
movq %r14, %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x14503
movq -0x60(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x1438d
movq -0x48(%rbp), %rdx
notq %rdx
addq %rax, %rdx
xorl %eax, %eax
incl 0x18(%r12,%rax,4)
jne 0x1438d
leaq 0x1(%rax), %rcx
cmpq %rax, %rdx
movq %rcx, %rax
jne 0x1437a
movq %r15, %rdi
movq %r14, %rsi
callq 0x14634
testl %eax, %eax
jns 0x144f5
testb $0x1, %r14b
jne 0x143b3
decl (%r14)
jne 0x143b3
movq %r14, %rdi
callq 0x5030
movq %r15, %rdi
callq 0xefb0
movq %rax, %r15
movq %r12, %rdi
jmp 0x143f0
movl %eax, (%r14)
movl $0x1, %r12d
testl %eax, %eax
jne 0x143f8
movq %r14, %rdi
callq 0x5030
jmp 0x143f8
xorl %edx, %edx
movl -0x2c(%rbp), %ebx
movl %edx, 0x18(%rdi,%r12,4)
callq 0xefb0
movq %rax, %r15
movq -0x50(%rbp), %rdi
callq 0xefb0
movq %rax, %r12
cmpl $0x0, -0x3c(%rbp)
sets %al
xorb %bl, %al
je 0x1442f
cmpq $0x1, %r15
jne 0x14444
testb $0x1, %r14b
jne 0x1441c
decl (%r14)
jne 0x1441c
movq %r14, %rdi
callq 0x5030
movq %r12, %rdi
callq 0xee12
movq %rax, %r12
movl $0x1, %r15d
jmp 0x1446a
testb $0x1, %r14b
jne 0x1446a
decl (%r14)
jne 0x1446a
movq %r14, %rdi
callq 0x5030
jmp 0x1446a
movq %r14, %rdi
movq %r15, %rsi
callq 0xe9fc
movq %rax, %r15
movl $0x3, %esi
movq %r12, %rdi
callq 0xe50f
movq %rax, %rdi
callq 0xee12
movq %rax, %r12
testb %bl, %bl
je 0x14479
movq %r15, %rdi
callq 0xee12
movq %rax, %r15
movq %r15, (%r13)
jmp 0x13ed0
leaq 0xcdb5b(%rip), %rsi     # 0xe1fe4
movl $0x12, %edx
movl $0x2, %edi
callq 0x5060
callq 0x52b6
movl $0x1, %edi
callq 0x5130
leaq 0xcdb49(%rip), %rsi     # 0xe1ff7
movl $0x45, %edx
jmp 0x1448e
leaq 0xcdb81(%rip), %rsi     # 0xe203d
jmp 0x144ee
leaq 0xcdbea(%rip), %rsi     # 0xe20af
movl $0x34, %edx
jmp 0x1448e
leaq 0xcdc11(%rip), %rsi     # 0xe20e4
jmp 0x144ee
leaq 0xcdc41(%rip), %rsi     # 0xe211d
jmp 0x144ae
leaq 0xcdc7e(%rip), %rsi     # 0xe2163
jmp 0x144ee
leaq 0xcdb88(%rip), %rsi     # 0xe2076
movl $0x38, %edx
jmp 0x1448e
leaq 0xcdca0(%rip), %rsi     # 0xe219c
movl $0x44, %edx
jmp 0x1448e