// File: /workspace/github_c_makefile_star2_O2/mbitsnbites[P]SoftFP/softfloat.c
// Function: roundAndPackFloat16
static float32 roundAndPackFloat16(flag zSign, int_fast16_t zExp,
                                   uint32_t zSig, flag ieee,
                                   float_status *status)
{
    int maxexp = ieee ? 29 : 30;
    uint32_t mask;
    uint32_t increment;
    bool rounding_bumps_exp;
    bool is_tiny = false;

    /* Calculate the mask of bits of the mantissa which are not
     * representable in half-precision and will be lost.
     */
    if (zExp < 1) {
        /* Will be denormal in halfprec */
        mask = 0x00ffffff;
        if (zExp >= -11) {
            mask >>= 11 + zExp;
        }
    } else {
        /* Normal number in halfprec */
        mask = 0x00001fff;
    }

    switch (status->float_rounding_mode) {
    case float_round_nearest_even:
        increment = (mask + 1) >> 1;
        if ((zSig & mask) == increment) {
            increment = zSig & (increment << 1);
        }
        break;
    case float_round_ties_away:
        increment = (mask + 1) >> 1;
        break;
    case float_round_up:
        increment = zSign ? 0 : mask;
        break;
    case float_round_down:
        increment = zSign ? mask : 0;
        break;
    default: /* round_to_zero */
        increment = 0;
        break;
    }

    rounding_bumps_exp = (zSig + increment >= 0x01000000);

    if (zExp > maxexp || (zExp == maxexp && rounding_bumps_exp)) {
        if (ieee) {
            float_raise(float_flag_overflow | float_flag_inexact, status);
            return packFloat16(zSign, 0x1f, 0);
        } else {
            float_raise(float_flag_invalid, status);
            return packFloat16(zSign, 0x1f, 0x3ff);
        }
    }

    if (zExp < 0) {
        /* Note that flush-to-zero does not affect half-precision results */
        is_tiny =
            (status->float_detect_tininess == float_tininess_before_rounding)
            || (zExp < -1)
            || (!rounding_bumps_exp);
    }
    if (zSig & mask) {
        float_raise(float_flag_inexact, status);
        if (is_tiny) {
            float_raise(float_flag_underflow, status);
        }
    }

    zSig += increment;
    if (rounding_bumps_exp) {
        zSig >>= 1;
        zExp++;
    }

    if (zExp < -10) {
        return packFloat16(zSign, 0, 0);
    }
    if (zExp < 0) {
        zSig >>= -zExp;
        zExp = 0;
    }
    return packFloat16(zSign, zExp, zSig >> 13);
}

// Assembly:
movl %ecx, %eax
movl $0x1fff, %r10d          # imm = 0x1FFF
testq %rsi, %rsi
jg 0xc50e
movl $0xffffff, %r10d        # imm = 0xFFFFFF
cmpq $-0xb, %rsi
jl 0xc50e
leal 0xb(%rsi), %ecx
movl $0xffffff, %r10d        # imm = 0xFFFFFF
shrl %cl, %r10d
movzbl 0x1(%r8), %ecx
xorl %r9d, %r9d
cmpq $0x4, %rcx
ja 0xc56a
leaq 0x82e9(%rip), %r11      # 0x1480c
movslq (%r11,%rcx,4), %rcx
addq %r11, %rcx
jmpq *%rcx
leal 0x1(%r10), %ecx
movl %ecx, %r9d
shrl %r9d
movl %r10d, %r11d
andl %edx, %r11d
cmpl %r9d, %r11d
jne 0xc56a
andl %edx, %ecx
andl $-0x2, %ecx
movl %ecx, %r9d
jmp 0xc56a
xorl %r9d, %r9d
testb %dil, %dil
cmovel %r10d, %r9d
jmp 0xc56a
xorl %r9d, %r9d
testb %dil, %dil
cmovnel %r10d, %r9d
jmp 0xc56a
leal 0x1(%r10), %r9d
shrl %r9d
addl %edx, %r9d
cmpl $0x1000000, %r9d        # imm = 0x1000000
setb %cl
xorl %r11d, %r11d
cmpb $0x1, %al
adcq $0x1d, %r11
cmpq %rsi, %r11
setne %r11b
jl 0xc597
orb %cl, %r11b
je 0xc597
testq %rsi, %rsi
js 0xc5ca
xorl %eax, %eax
jmp 0xc5e8
movzbl %dil, %ecx
shll $0xf, %ecx
movb 0x2(%r8), %dl
testb %al, %al
je 0xc5b8
orb $0x28, %dl
movb %dl, 0x2(%r8)
orl $0x7c00, %ecx           # imm = 0x7C00
jmp 0xc655
orb $0x1, %dl
movb %dl, 0x2(%r8)
orl $0x7fff, %ecx           # imm = 0x7FFF
jmp 0xc655
cmpl $0x1000000, %r9d        # imm = 0x1000000
setb %cl
cmpb $0x1, (%r8)
sete %r11b
cmpq $-0x1, %rsi
setne %al
orb %cl, %al
orb %r11b, %al
testl %edx, %r10d
je 0xc605
movb 0x2(%r8), %cl
movl %ecx, %edx
orb $0x20, %dl
movb %dl, 0x2(%r8)
testb %al, %al
je 0xc605
orb $0x30, %cl
movb %cl, 0x2(%r8)
xorl %ecx, %ecx
cmpl $0x1000000, %r9d        # imm = 0x1000000
setae %cl
movq %rcx, %rax
addq %rsi, %rax
cmpq $-0xb, %rax
jg 0xc626
movzbl %dil, %ecx
shll $0xf, %ecx
jmp 0xc655
shrl %cl, %r9d
movl %eax, %edx
negb %dl
movq %rax, %rcx
sarq $0x3f, %rcx
andb %dl, %cl
shrl %cl, %r9d
xorl %ecx, %ecx
testq %rax, %rax
cmovgq %rax, %rcx
shrl $0xd, %r9d
movzbl %dil, %eax
shll $0xf, %eax
shll $0xa, %ecx
addl %eax, %ecx
addl %r9d, %ecx
movzwl %cx, %eax
retq