// File: /workspace/github_c_makefile_star2_O2/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, %r12
andq %rax, %r12
movq %rsi, %r15
andq %rax, %r15
cmpl %ecx, %r13d
jne 0x6161
movabsq $0x7ff8000000000000, %rax # imm = 0x7FF8000000000000
movabsq $0x7ff0000000000000, %rcx # imm = 0x7FF0000000000000
testq %r12, %r12
je 0x61bc
setne %dl
andq %rax, %rdi
cmpq %rcx, %rdi
sete %dil
testb %dl, %dil
jne 0x6209
jmp 0x61f2
pushq $0xc
popq %r8
testl %edx, %edx
je 0x6211
cmpl $0x7ff, %edx            # imm = 0x7FF
jne 0x6232
testq %r15, %r15
je 0x62c1
movabsq $0x7ff8000000000000, %rax # imm = 0x7FF8000000000000
andq %rax, %rdi
movabsq $0x7ff0000000000000, %rcx # imm = 0x7FF0000000000000
cmpq %rcx, %rdi
setne %dl
testq %r12, %r12
sete %dil
orb %dl, %dil
andq %rax, %rsi
cmpq %rcx, %rsi
setne %cl
testb %cl, %dil
je 0x6209
jmp 0x62d1
movq %rsi, %rdi
notq %rdi
testq %rdi, %rcx
setne %dil
testq %r15, %r15
sete %r8b
orb %dil, %r8b
je 0x61f2
cmpl $0x7ff, %edx            # imm = 0x7FF
je 0x6209
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
andq %rax, %r14
orq %rcx, %r14
jmp 0x62ce
andq %rax, %rsi
cmpq %rcx, %rsi
setne %cl
testq %r15, %r15
sete %dl
orb %cl, %dl
jne 0x62d1
orb $0x10, (%rbx)
jmp 0x62d1
testq %r15, %r15
je 0x62e0
bsrq %r15, %rsi
xorl $0x3f, %esi
movl $0xfffffff5, %ecx       # imm = 0xFFFFFFF5
addl %esi, %ecx
movl %r8d, %edx
subl %esi, %edx
shlq %cl, %r15
jmp 0x6238
addq %rax, %r15
incq %r15
testl %r13d, %r13d
je 0x6245
addq %rax, %r12
incq %r12
jmp 0x6261
testq %r12, %r12
je 0x62c1
bsrq %r12, %rax
xorl $0x3f, %eax
movl $0xfffffff5, %ecx       # imm = 0xFFFFFFF5
addl %eax, %ecx
subl %eax, %r8d
shlq %cl, %r12
movl %r8d, %r13d
subl %edx, %r13d
shrq $0x3f, %r14
addl $0x3ff, %r13d           # imm = 0x3FF
shlq $0x2, %r15
xorl %edi, %edi
movq %r12, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x13440
movq %rax, %rcx
movq %rdx, %rsi
mulq %r15
imulq %r15, %rsi
addq %rsi, %rdx
negq %rax
sbbq %rdx, %r12
xorl %edx, %edx
orq %rax, %r12
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 0x5a35
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 %r12, %r12
setne %dl
movl (%rbx), %ecx
orb %al, %dl
jne 0x6303
movabsq $0x7ff8000000000000, %rax # imm = 0x7FF8000000000000
orl $0x10, %ecx
movl %ecx, (%rbx)
jmp 0x62d1
orl $0x8, %ecx
movl %ecx, (%rbx)
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
andq %rax, %r14
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
orq %r14, %rax
jmp 0x62d1