// File: /workspace/github_c_makefile_star2_O0/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
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x41840
testb $0x1, %al
jne 0x413b6
jmp 0x413e0
movl $0x2, %edi
leaq 0x314564(%rip), %rsi    # 0x355926
movl $0x12, %edx
callq 0x5060
callq 0x5310
callq 0x53b0
movl $0x1, %edi
callq 0x5130
jmp 0x413e2
movq -0x10(%rbp), %rdi
callq 0x41840
testb $0x1, %al
jne 0x413f1
jmp 0x41412
movq -0x18(%rbp), %rdi
callq 0x41860
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x41829
movq -0x18(%rbp), %rax
subq $0x1, %rax
movl $0x2, %ecx
cqto
idivq %rcx
cmpq $0x1, %rax
jne 0x4144a
movq -0x20(%rbp), %rax
movq $0x1, -0x28(%rbp)
movq -0x28(%rbp), %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x41829
movq -0x18(%rbp), %rax
subq $0x1, %rax
movl $0x2, %ecx
cqto
idivq %rcx
cmpq $-0x1, %rax
jne 0x41487
movq -0x20(%rbp), %rax
movq $0x1, -0x30(%rbp)
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
callq 0x1c7f0
movq %rax, -0x8(%rbp)
jmp 0x41829
movq -0x10(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
jne 0x414a4
movq -0x10(%rbp), %rax
cmpq $0x2, 0x10(%rax)
jne 0x41668
movq -0x18(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
jne 0x414c1
movq -0x18(%rbp), %rax
cmpq $0x2, 0x10(%rax)
jne 0x415ad
movq -0x10(%rbp), %rdi
callq 0xc6c0
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
callq 0xc6c0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x414e9
cmpq $-0x1, -0x40(%rbp)
jne 0x41513
movl $0x2, %edi
leaq 0x314444(%rip), %rsi    # 0x355939
movl $0x45, %edx
callq 0x5060
callq 0x5310
callq 0x53b0
movl $0x1, %edi
callq 0x5130
jmp 0x41515
movq -0x38(%rbp), %rax
cqto
idivq -0x40(%rbp)
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
cqto
idivq -0x40(%rbp)
movq %rdx, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x41572
cmpq $0x0, -0x38(%rbp)
setl %al
andb $0x1, %al
movzbl %al, %eax
cmpq $0x0, -0x40(%rbp)
setl %cl
andb $0x1, %cl
movzbl %cl, %ecx
xorl %ecx, %eax
cmpl $0x0, %eax
je 0x41572
movq -0x48(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x50(%rbp), %rdi
callq 0x1a290
movq %rax, %rcx
movq -0xc8(%rbp), %rax
movq %rcx, -0x58(%rbp)
movq -0x58(%rbp), %rcx
movq %rcx, (%rax)
movq -0x48(%rbp), %rdi
callq 0x1a290
movq %rax, -0x8(%rbp)
jmp 0x41829
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
callq 0x41890
andb $0x1, %al
movb %al, -0x61(%rbp)
movq -0x60(%rbp), %rax
movq -0x60(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq $0x1, %rcx
movl 0x18(%rax,%rcx,4), %edx
andl $0x80000000, %edx       # imm = 0x80000000
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $0x0, %edx
cmovnel %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x62(%rbp)
movb -0x61(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movb -0x62(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
xorl %ecx, %eax
cmpl $0x0, %eax
je 0x41647
movq -0x20(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x1b780
movq %rax, %rcx
movq -0xd0(%rbp), %rax
movq %rcx, -0x70(%rbp)
movq -0x70(%rbp), %rcx
movq %rcx, (%rax)
movq $-0x1, -0x8(%rbp)
jmp 0x41829
movq -0x60(%rbp), %rdi
callq 0x1c3a0
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rcx, (%rax)
movq $0x1, -0x8(%rbp)
jmp 0x41829
movq -0x10(%rbp), %rdi
callq 0x41890
andb $0x1, %al
movb %al, -0x71(%rbp)
movq -0x18(%rbp), %rdi
callq 0x41890
andb $0x1, %al
movb %al, -0x72(%rbp)
testb $0x1, -0x71(%rbp)
je 0x41699
movq -0x10(%rbp), %rdi
callq 0x1c7f0
movq %rax, -0x80(%rbp)
jmp 0x416a1
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
testb $0x1, -0x72(%rbp)
je 0x416b9
movq -0x18(%rbp), %rdi
callq 0x1c7f0
movq %rax, -0x88(%rbp)
jmp 0x416c4
movq -0x18(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x416c6
movq -0x80(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x416fe
movl $0x2, %edi
leaq 0x31429f(%rip), %rsi    # 0x35597f
movl $0x38, %edx
callq 0x5060
callq 0x5310
callq 0x53b0
movl $0x1, %edi
callq 0x5130
jmp 0x41700
movq -0x88(%rbp), %rdi
callq 0x41910
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rsi
leaq -0x8(%rbp), %rdx
leaq -0x90(%rbp), %rcx
callq 0x41940
movb -0x71(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movb -0x72(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
xorl %ecx, %eax
cmpl $0x0, %eax
je 0x417e8
movq -0x90(%rbp), %rdi
callq 0x41840
testb $0x1, %al
jne 0x41755
jmp 0x4177e
movq -0x88(%rbp), %rdi
callq 0x41860
movq -0x8(%rbp), %rdi
callq 0x1c7f0
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x417e6
movq -0x88(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0x1c670
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x90(%rbp)
movq $0x3, -0xb8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xb8(%rbp), %rsi
callq 0x1b780
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x1c7f0
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x417f4
movq -0x88(%rbp), %rdi
callq 0x41860
testb $0x1, -0x72(%rbp)
je 0x4181b
movq -0x90(%rbp), %rdi
callq 0x1c7f0
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x20(%rbp), %rax
movq -0x90(%rbp), %rcx
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)