// File: /workspace/github_c_makefile_star2_O1/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 0x147a5
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %r12
cmpq $0x1, %rdi
jne 0x14222
testb $0x1, %r14b
jne 0x1421c
decl (%r14)
jne 0x1421c
movq %r14, %rdi
callq 0x5030
movq %r12, (%r13)
jmp 0x14234
leaq -0x3(%r14), %rax
cmpq $0x1, %rax
ja 0x14246
movq $0x1, (%r13)
movq %r12, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $-0x2, %r14
jb 0x1426a
movq $0x1, (%r13)
movq %r12, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf1af
testb $0x1, %r12b
jne 0x1427b
movq 0x10(%r12), %rax
cmpq $0x2, %rax
jne 0x142d2
testb $0x1, %r14b
jne 0x1428f
movq 0x10(%r14), %rax
cmpq $0x2, %rax
jne 0x1436b
movq %r12, %rdi
callq 0xe818
movq %rax, %r12
movq %r14, %rdi
callq 0xe818
movq %rax, %rcx
decq %rax
cmpq $-0x2, %rax
jae 0x147ca
movq %r12, %rax
cqto
idivq %rcx
movq %rax, %r14
testq %rdx, %rdx
je 0x142f2
movq %rdx, %r15
xorq %rcx, %r12
jns 0x142f5
decq %r14
addq %rcx, %r15
jmp 0x142f5
movl 0x14(%r12,%rax,4), %ecx
testb $0x1, %r14b
jne 0x14380
movq 0x10(%r14), %rax
movl 0x14(%r14,%rax,4), %ebx
shrl $0x1f, %ebx
jmp 0x14386
xorl %r15d, %r15d
movabsq $0x4000000000000000, %rbx # imm = 0x4000000000000000
movq %r15, %rax
addq %rbx, %rax
js 0x14311
leaq 0x1(,%r15,2), %rax
jmp 0x1432f
movl $0x3, %edi
callq 0x524c
movq $0x2, 0x10(%rax)
movl %r15d, 0x18(%rax)
shrq $0x20, %r15
movl %r15d, 0x1c(%rax)
movq %rax, (%r13)
addq %r14, %rbx
js 0x14345
leaq 0x1(,%r14,2), %r12
jmp 0x14234
movl $0x3, %edi
callq 0x524c
movq %rax, %r12
movq $0x2, 0x10(%rax)
movl %r14d, 0x18(%rax)
shrq $0x20, %r14
movl %r14d, 0x1c(%rax)
jmp 0x14234
testb $0x1, %r12b
jne 0x14392
movq 0x10(%r12), %rcx
movl 0x14(%r12,%rcx,4), %ecx
shrl $0x1f, %ecx
jmp 0x14398
testq %r14, %r14
setle %bl
movl %ecx, -0x44(%rbp)
testl %ecx, %ecx
js 0x143c4
movq %r12, %r15
jmp 0x143cf
testq %r12, %r12
setle %cl
cmpl $0x0, 0x14(%r14,%rax,4)
setns %al
xorb %cl, %al
je 0x14574
decl (%r14)
movl $0x1, %ebx
jne 0x14589
movq %r14, %rdi
callq 0x5030
jmp 0x14589
movq %r12, %rdi
callq 0xf1af
movq %rax, %r15
testb %bl, %bl
je 0x143de
movq %r14, %rdi
callq 0xf1af
movq %rax, %r14
testb $0x1, %r15b
jne 0x147d8
testb $0x1, %r14b
jne 0x143f1
incl (%r14)
testb $0x1, %r14b
jne 0x1444b
movq 0x10(%r14), %rax
leaq -0x1(%rax), %rsi
movl 0x14(%r14,%rax,4), %r12d
testl %r12d, %r12d
jne 0x1441e
testq %rsi, %rsi
je 0x14818
movl 0x10(%r14,%rax,4), %r12d
addq $-0x2, %rax
movq %rax, %rsi
testq %rsi, %rsi
sete %al
je 0x14480
movq %rsi, %rdi
leaq -0x1(%rsi), %rcx
xorl %edx, %edx
cmpl $0x0, 0x18(%r14,%rdx,4)
sete %al
jne 0x14446
leaq 0x1(%rdx), %rsi
cmpq %rdx, %rcx
movq %rsi, %rdx
jne 0x1442f
movq %rdi, %rsi
jmp 0x14480
leaq -0x1(%r14), %rax
movq %rax, %rcx
sarq %rcx
cmpq $0x1, %rcx
jle 0x147e6
movq %rcx, %r12
shrq $0x20, %r12
shrq %rax
testl %eax, %eax
sete %dl
xorl %esi, %esi
testq %r12, %r12
setne %sil
sete %al
cmovel %ecx, %r12d
orb %dl, %al
movq 0x10(%r15), %rdi
movq %rsi, -0x40(%rbp)
subq %rsi, %rdi
jbe 0x1454e
testb %al, %al
movl %ebx, -0x2c(%rbp)
movq %r12, -0x38(%rbp)
je 0x14595
testb $0x1, %r14b
jne 0x144b3
decl (%r14)
jne 0x144b3
movq %r14, %rdi
callq 0x5030
testl %r12d, %r12d
je 0x147fd
testq %r15, %r15
movq -0x40(%rbp), %r12
je 0x147f4
movq 0x10(%r15), %rdi
subq %r12, %rdi
jbe 0x147f4
addq $0x2, %rdi
callq 0x524c
movq %rax, %rbx
movq 0x10(%r15), %rsi
movq %rsi, %rax
subq %r12, %rax
movq %rax, 0x10(%rbx)
movq %r15, %rdi
callq 0xf298
movq %rax, %rdi
movq 0x10(%rax), %rcx
cmpq %r12, %rcx
movq %r12, %r9
je 0x14709
movl -0x38(%rbp), %esi
leaq (,%r9,4), %rax
movq %rbx, %r8
subq %rax, %r8
addq $0x14, %r8
xorl %edx, %edx
movq %rbx, %r12
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, %r9
jne 0x14525
jmp 0x1470e
movl $0x1, %r12d
testb $0x1, %r14b
jne 0x14729
decl (%r14)
jne 0x14729
movq %r14, %rdi
callq 0x5030
jmp 0x14729
movq %r12, %rdi
movq %r14, %rsi
callq 0xe8e2
movq %rax, %r12
movq $-0x1, %rbx
movq %r12, (%r13)
movq %rbx, %r12
jmp 0x14234
testl %r12d, %r12d
je 0x14806
movq %r14, -0x50(%rbp)
movq %r13, -0x58(%rbp)
testq %r15, %r15
je 0x1480f
addq $0x2, %rdi
callq 0x524c
movq %rax, %r12
movq 0x10(%r15), %rsi
movq %rsi, %rax
movq -0x40(%rbp), %rbx
subq %rbx, %rax
movq %rax, 0x10(%r12)
movq %r15, %rdi
callq 0xf298
movq %rax, %r15
movq 0x10(%rax), %r13
subq %rbx, %r13
je 0x14690
movl -0x38(%rbp), %eax
movq %rax, -0x38(%rbp)
incq %rax
movq %rax, -0x60(%rbp)
movq %r13, %r14
decq %r13
movq -0x40(%rbp), %rax
leaq (%r14,%rax), %rbx
decq %rbx
addq %rax, %r14
movq 0x10(%r15), %rcx
cmpq %r14, %rcx
jbe 0x14618
movl 0x18(%r15,%r14,4), %eax
jmp 0x14620
movl 0x14(%r15,%rcx,4), %eax
sarl $0x1f, %eax
cmpq %rbx, %rcx
jbe 0x1462c
movl 0x18(%r15,%rbx,4), %ecx
jmp 0x14634
movl 0x14(%r15,%rcx,4), %ecx
sarl $0x1f, %ecx
movl %ecx, %ecx
shlq $0x20, %rax
orq %rcx, %rax
cmpq -0x38(%rbp), %rax
jbe 0x14687
xorl %edx, %edx
divq -0x60(%rbp)
movq 0x10(%r12), %rcx
movq %rax, %rsi
movq %r13, %rdx
cmpq %rcx, %rdx
jae 0x14674
movq %rsi, %rdi
shrq $0x20, %rdi
addl %esi, 0x18(%r12,%rdx,4)
adcq $0x0, %rdi
incq %rdx
movq %rdi, %rsi
testq %rdi, %rdi
jne 0x14654
movq %r15, %rdi
movq -0x50(%rbp), %rsi
movl %eax, %edx
movq %r13, %rcx
callq 0x1482f
jmp 0x14608
testq %r13, %r13
jne 0x145f4
movq %r15, %rdi
movq -0x50(%rbp), %r14
movq %r14, %rsi
callq 0x14968
testl %eax, %eax
movq -0x58(%rbp), %r13
movl -0x2c(%rbp), %ebx
js 0x146f1
movq %r15, %rdi
movq %r14, %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x1482f
movq 0x10(%r12), %rax
testq %rax, %rax
je 0x146de
decq %rax
xorl %ecx, %ecx
incl 0x18(%r12,%rcx,4)
jne 0x146de
leaq 0x1(%rcx), %rdx
cmpq %rcx, %rax
movq %rdx, %rcx
jne 0x146cb
movq %r15, %rdi
movq %r14, %rsi
callq 0x14968
testl %eax, %eax
jns 0x14821
testb $0x1, %r14b
jne 0x14704
decl (%r14)
jne 0x14704
movq %r14, %rdi
callq 0x5030
movq %r15, %rdi
jmp 0x14716
xorl %edx, %edx
movq %rbx, %r12
movl -0x2c(%rbp), %ebx
movl %edx, 0x18(%rdi,%r9,4)
callq 0xf34b
movq %rax, %r15
movq %r12, %rdi
callq 0xf34b
movq %rax, %r12
cmpl $0x0, -0x44(%rbp)
sets %al
cmpb %bl, %al
je 0x14752
cmpq $0x1, %r15
jne 0x14767
testb $0x1, %r14b
jne 0x1474d
decl (%r14)
jne 0x1474d
movq %r14, %rdi
callq 0x5030
movq %r12, %rdi
jmp 0x14785
testb $0x1, %r14b
jne 0x1478d
decl (%r14)
jne 0x1478d
movq %r14, %rdi
callq 0x5030
jmp 0x1478d
movq %r14, %rdi
movq %r15, %rsi
callq 0xedca
movq %rax, %r15
movl $0x3, %esi
movq %r12, %rdi
callq 0xe8e2
movq %rax, %rdi
callq 0xf1af
movq %rax, %r12
testb %bl, %bl
je 0x1479c
movq %r15, %rdi
callq 0xf1af
movq %rax, %r15
movq %r15, (%r13)
jmp 0x14234
leaq 0xd18f1(%rip), %rsi     # 0xe609d
movl $0x12, %edx
movl $0x2, %edi
callq 0x5060
callq 0x52be
movl $0x1, %edi
callq 0x5130
leaq 0xd18df(%rip), %rsi     # 0xe60b0
movl $0x45, %edx
jmp 0x147b1
leaq 0xd1917(%rip), %rsi     # 0xe60f6
movl $0x38, %edx
jmp 0x147b1
leaq 0xd197b(%rip), %rsi     # 0xe6168
movl $0x34, %edx
jmp 0x147b1
leaq 0xd19db(%rip), %rsi     # 0xe61d6
jmp 0x147d1
leaq 0xd1999(%rip), %rsi     # 0xe619d
jmp 0x147df
leaq 0xd1a0f(%rip), %rsi     # 0xe621c
jmp 0x147df
leaq 0xd1a3f(%rip), %rsi     # 0xe6255
jmp 0x147d1
leaq 0xd1910(%rip), %rsi     # 0xe612f
jmp 0x147df
leaq 0xd1a73(%rip), %rsi     # 0xe629b
movl $0x44, %edx
jmp 0x147b1