// File: /workspace/github_c_makefile_star2_O3/mbitsnbites[P]SoftFP/./softfp_template.h
// Function: div_sf64
F_UINT div_sf(F_UINT a, F_UINT b, RoundingModeEnum rm,
              uint32_t *pfflags)
{
    uint32_t a_sign, b_sign, r_sign;
    int32_t a_exp, b_exp, r_exp;
    F_UINT a_mant, b_mant, r_mant, r;

    a_sign = a >> (F_SIZE - 1);
    b_sign = b >> (F_SIZE - 1);
    r_sign = a_sign ^ b_sign;
    a_exp = (a >> MANT_SIZE) & EXP_MASK;
    b_exp = (b >> MANT_SIZE) & EXP_MASK;
    a_mant = a & MANT_MASK;
    b_mant = b & MANT_MASK;
    if (a_exp == EXP_MASK) {
        if (a_mant != 0 || isnan_sf(b)) {
            if (issignan_sf(a) || issignan_sf(b)) {
                *pfflags |= FFLAG_INVALID_OP;
            }
            return F_QNAN;
        } else if (b_exp == EXP_MASK) {
            *pfflags |= FFLAG_INVALID_OP;
            return F_QNAN;
        } else {
            return pack_sf(r_sign, EXP_MASK, 0);
        }
    } else if (b_exp == EXP_MASK) {
        if (b_mant != 0) {
            if (issignan_sf(a) || issignan_sf(b)) {
                *pfflags |= FFLAG_INVALID_OP;
            }
            return F_QNAN;
        } else {
            return pack_sf(r_sign, 0, 0);
        }
    }

    if (b_exp == 0) {
        if (b_mant == 0) { 
            /* zero */
            if (a_exp == 0 && a_mant == 0) {
                *pfflags |= FFLAG_INVALID_OP;
                return F_QNAN;
            } else {
                *pfflags |= FFLAG_DIVIDE_ZERO;
                return pack_sf(r_sign, EXP_MASK, 0);
            }
        }
        b_mant = normalize_subnormal_sf(&b_exp, b_mant);
    } else {
        b_mant |= (F_UINT)1 << MANT_SIZE;
    }
    if (a_exp == 0) {
        if (a_mant == 0)
            return pack_sf(r_sign, 0, 0); /* zero */
        a_mant = normalize_subnormal_sf(&a_exp, a_mant);
    } else {
        a_mant |= (F_UINT)1 << MANT_SIZE;
    }
    r_exp = a_exp - b_exp + (1 << (EXP_SIZE - 1)) - 1;
    r_mant = divrem_u(&r, a_mant, 0, b_mant << 2);
    if (r != 0)
        r_mant |= 1;
    return normalize_sf(r_sign, r_exp, r_mant, rm, pfflags);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %rbx
movl %edx, %ebp
movabsq $0xfffffffffffff, %rax  # imm = 0xFFFFFFFFFFFFF
movq %rsi, %r14
xorq %rdi, %r14
movq %rdi, %r13
shrq $0x34, %r13
movl $0x7ff, %ecx            # imm = 0x7FF
andl %ecx, %r13d
movq %rsi, %rdx
shrq $0x34, %rdx
andl %ecx, %edx
movq %rdi, %r15
andq %rax, %r15
movq %rsi, %r12
andq %rax, %r12
cmpl %ecx, %r13d
jne 0x6a96
movabsq $0x7ff8000000000000, %rax # imm = 0x7FF8000000000000
movabsq $0x7ff0000000000000, %rcx # imm = 0x7FF0000000000000
testq %r15, %r15
je 0x6aed
andq %rax, %rdi
cmpq %rcx, %rdi
je 0x6b3a
jmp 0x6b23
testl %edx, %edx
je 0x6b42
cmpl $0x7ff, %edx            # imm = 0x7FF
jne 0x6b65
testq %r12, %r12
je 0x6bf7
movabsq $0x7ff8000000000000, %rax # imm = 0x7FF8000000000000
andq %rax, %rdi
movabsq $0x7ff0000000000000, %rcx # imm = 0x7FF0000000000000
cmpq %rcx, %rdi
setne %dl
testq %r15, %r15
sete %dil
orb %dl, %dil
andq %rax, %rsi
cmpq %rcx, %rsi
setne %cl
testb %cl, %dil
je 0x6b3a
jmp 0x6c07
movq %rsi, %rdi
notq %rdi
testq %rdi, %rcx
setne %dil
testq %r12, %r12
sete %r8b
orb %dil, %r8b
je 0x6b23
cmpl $0x7ff, %edx            # imm = 0x7FF
je 0x6b3a
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
andq %rax, %r14
orq %rcx, %r14
jmp 0x6c04
andq %rax, %rsi
cmpq %rcx, %rsi
setne %cl
testq %r12, %r12
sete %dl
orb %cl, %dl
jne 0x6c07
orb $0x10, (%rbx)
jmp 0x6c07
testq %r12, %r12
je 0x6c16
bsrq %r12, %rsi
xorl $0x3f, %esi
movl $0xfffffff5, %ecx       # imm = 0xFFFFFFF5
addl %esi, %ecx
movl $0xc, %edx
subl %esi, %edx
shlq %cl, %r12
jmp 0x6b6b
addq %rax, %r12
incq %r12
testl %r13d, %r13d
je 0x6b78
addq %rax, %r15
incq %r15
jmp 0x6b97
testq %r15, %r15
je 0x6bf7
bsrq %r15, %rax
xorl $0x3f, %eax
movl $0xfffffff5, %ecx       # imm = 0xFFFFFFF5
addl %eax, %ecx
movl $0xc, %r13d
subl %eax, %r13d
shlq %cl, %r15
subl %edx, %r13d
shrq $0x3f, %r14
addl $0x3ff, %r13d           # imm = 0x3FF
shlq $0x2, %r12
xorl %edi, %edi
movq %r15, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x157a0
movq %rax, %rcx
movq %rdx, %rsi
mulq %r12
imulq %r12, %rsi
addq %rsi, %rdx
negq %rax
sbbq %rdx, %r15
xorl %edx, %edx
orq %rax, %r15
setne %dl
orq %rcx, %rdx
movl %r14d, %edi
movl %r13d, %esi
movl %ebp, %ecx
movq %rbx, %r8
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6347
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
andq %rax, %r14
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %r13d, %r13d
setne %al
testq %r15, %r15
setne %dl
movl (%rbx), %ecx
orb %al, %dl
jne 0x6c39
movabsq $0x7ff8000000000000, %rax # imm = 0x7FF8000000000000
orl $0x10, %ecx
movl %ecx, (%rbx)
jmp 0x6c07
orl $0x8, %ecx
movl %ecx, (%rbx)
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
andq %rax, %r14
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
orq %r14, %rax
jmp 0x6c07