// File: /workspace/github_c_makefile_star2_O0/pahihu[P]mixal/cell.c
// Function: divide
void divide(Cell n1, Cell n0, Cell d, Cell *quotient, Cell *remainder)
{
    long magn1 = magnitude(n1);
    long magd = magnitude(d);
    if (magd == 0) {
        overflow = true;
        *quotient = *remainder = zero;  /* just so they have -some- valid value */
    } else if (magn1 == 0) {    /* special-cased for speed */
        *quotient = (sign_bit(n1) ^ sign_bit(d)) | (magnitude(n0) / magd);
        *remainder = sign_bit(n1) | (magnitude(n0) % magd);
    } else if (magd <= magn1) {
        overflow = true;
        *quotient = *remainder = zero;
    } else {
        long q = magnitude(n0);
        long r = magn1;
        unsigned i;
        for (i = 30; i != 0; --i) {
            r <<= 1;
            if (q & (1L << 29))
                ++r;
            q = (q << 1) & ((1L << 30) - 1);
            if (magd <= r)
                ++q, r -= magd;
        }
        *quotient = (sign_bit(n1) ^ sign_bit(d)) | q;
        *remainder = sign_bit(n1) | r;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rax
andq $0x3fffffff, %rax       # imm = 0x3FFFFFFF
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
andq $0x3fffffff, %rax       # imm = 0x3FFFFFFF
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x3f30
movl $0x1, 0xec3b(%rip)      # 0x12b50
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
jmp 0x408c
cmpq $0x0, -0x30(%rbp)
jne 0x3f93
movq -0x8(%rbp), %rcx
andq $0x40000000, %rcx       # imm = 0x40000000
movq -0x18(%rbp), %rax
andq $0x40000000, %rax       # imm = 0x40000000
xorq %rax, %rcx
movq -0x10(%rbp), %rax
andq $0x3fffffff, %rax       # imm = 0x3FFFFFFF
cqto
idivq -0x38(%rbp)
orq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rcx
andq $0x40000000, %rcx       # imm = 0x40000000
movq -0x10(%rbp), %rax
andq $0x3fffffff, %rax       # imm = 0x3FFFFFFF
cqto
idivq -0x38(%rbp)
orq %rdx, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
jmp 0x408a
movq -0x38(%rbp), %rax
cmpq -0x30(%rbp), %rax
jg 0x3fc2
movl $0x1, 0xeba9(%rip)      # 0x12b50
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
jmp 0x4088
movq -0x10(%rbp), %rax
andq $0x3fffffff, %rax       # imm = 0x3FFFFFFF
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x1e, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x404f
movq -0x48(%rbp), %rax
shlq %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
andq $0x20000000, %rax       # imm = 0x20000000
cmpq $0x0, %rax
je 0x400c
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
shlq %rax
andq $0x3fffffff, %rax       # imm = 0x3FFFFFFF
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
jg 0x4042
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
jmp 0x4044
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x3fdf
movq -0x8(%rbp), %rcx
andq $0x40000000, %rcx       # imm = 0x40000000
movq -0x18(%rbp), %rax
andq $0x40000000, %rax       # imm = 0x40000000
xorq %rax, %rcx
orq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rcx
andq $0x40000000, %rcx       # imm = 0x40000000
orq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
jmp 0x408a
jmp 0x408c
popq %rbp
retq
nop