// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %cl, %al
movb %dil, %cl
movb %cl, -0x5(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movb %al, -0x15(%rbp)
movq %r8, -0x20(%rbp)
movzbl -0x15(%rbp), %edx
movl $0x1e, %eax
movl $0x1d, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x24(%rbp)
movb $0x0, -0x2e(%rbp)
cmpq $0x1, -0x10(%rbp)
jge 0x173f0
movl $0xffffff, -0x28(%rbp)  # imm = 0xFFFFFF
cmpq $-0xb, -0x10(%rbp)
jl 0x173ee
movq -0x10(%rbp), %rcx
addq $0xb, %rcx
movl -0x28(%rbp), %eax
shrl %cl, %eax
movl %eax, -0x28(%rbp)
jmp 0x173f7
movl $0x1fff, -0x28(%rbp)    # imm = 0x1FFF
movq -0x20(%rbp), %rax
movsbl 0x1(%rax), %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x4, %eax
ja 0x17492
movq -0x38(%rbp), %rax
leaq 0xe4b3(%rip), %rcx      # 0x258cc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x28(%rbp), %eax
addl $0x1, %eax
shrl %eax
movl %eax, -0x2c(%rbp)
movl -0x14(%rbp), %eax
andl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0x17445
movl -0x14(%rbp), %eax
movl -0x2c(%rbp), %ecx
shll %ecx
andl %ecx, %eax
movl %eax, -0x2c(%rbp)
jmp 0x17499
movl -0x28(%rbp), %eax
addl $0x1, %eax
shrl %eax
movl %eax, -0x2c(%rbp)
jmp 0x17499
movzbl -0x5(%rbp), %eax
cmpl $0x0, %eax
je 0x17464
xorl %eax, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1746a
movl -0x28(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x17499
movzbl -0x5(%rbp), %eax
cmpl $0x0, %eax
je 0x17483
movl -0x28(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x1748a
xorl %eax, %eax
movl %eax, -0x40(%rbp)
jmp 0x1748a
movl -0x40(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x17499
movl $0x0, -0x2c(%rbp)
movl -0x14(%rbp), %eax
addl -0x2c(%rbp), %eax
cmpl $0x1000000, %eax        # imm = 0x1000000
setae %al
andb $0x1, %al
movb %al, -0x2d(%rbp)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpq %rcx, %rax
jg 0x174cc
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpq %rcx, %rax
jne 0x17527
testb $0x1, -0x2d(%rbp)
je 0x17527
cmpb $0x0, -0x15(%rbp)
je 0x174fb
movq -0x20(%rbp), %rsi
movl $0x28, %edi
callq 0x11080
movl $0x1f, %esi
xorl %edx, %edx
movzbl -0x5(%rbp), %edi
callq 0x17300
movzwl %ax, %eax
movl %eax, -0x4(%rbp)
jmp 0x17608
movq -0x20(%rbp), %rsi
movl $0x1, %edi
callq 0x11080
movl $0x1f, %esi
movl $0x3ff, %edx            # imm = 0x3FF
movzbl -0x5(%rbp), %edi
callq 0x17300
movzwl %ax, %eax
movl %eax, -0x4(%rbp)
jmp 0x17608
cmpq $0x0, -0x10(%rbp)
jge 0x1755b
movq -0x20(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x1, %ecx
movb %al, -0x41(%rbp)
je 0x17553
movb $0x1, %al
cmpq $-0x1, -0x10(%rbp)
movb %al, -0x41(%rbp)
jl 0x17553
movb -0x2d(%rbp), %al
xorb $-0x1, %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
andb $0x1, %al
movb %al, -0x2e(%rbp)
movl -0x14(%rbp), %eax
andl -0x28(%rbp), %eax
cmpl $0x0, %eax
je 0x1758a
movq -0x20(%rbp), %rsi
movl $0x20, %edi
callq 0x11080
testb $0x1, -0x2e(%rbp)
je 0x17588
movq -0x20(%rbp), %rsi
movl $0x10, %edi
callq 0x11080
jmp 0x1758a
movl -0x2c(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
testb $0x1, -0x2d(%rbp)
je 0x175ad
movl -0x14(%rbp), %eax
shrl %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
cmpq $-0xa, -0x10(%rbp)
jge 0x175cb
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
movzbl -0x5(%rbp), %edi
callq 0x17300
movzwl %ax, %eax
movl %eax, -0x4(%rbp)
jmp 0x17608
cmpq $0x0, -0x10(%rbp)
jge 0x175ea
xorl %eax, %eax
movl %eax, %ecx
subq -0x10(%rbp), %rcx
movl -0x14(%rbp), %eax
shrl %cl, %eax
movl %eax, -0x14(%rbp)
movq $0x0, -0x10(%rbp)
movb -0x5(%rbp), %cl
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %eax
shrl $0xd, %eax
movzbl %cl, %edi
movzwl %ax, %edx
callq 0x17300
movzwl %ax, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)