// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/crossassemblers/macro11/parse.c
// Function: parse_float
int parse_float(
    char *cp,
    char **endp,
    int size,
    unsigned *flt)
{
    double          d;          /* value */
    double          frac;       /* fractional value */
    ulong64         ufrac;      /* fraction converted to 49 bit
                                   unsigned integer */
    int             i;          /* Number of fields converted by sscanf */
    int             n;          /* Number of characters converted by sscanf */
    int             sexp;       /* Signed exponent */
    unsigned        uexp;       /* Unsigned excess-128 exponent */
    unsigned        sign = 0;   /* Sign mask */

    i = sscanf(cp, "%lf%n", &d, &n);
    if (i == 0)
        return 0;                      /* Wasn't able to convert */

    cp += n;
    if (endp)
        *endp = cp;

    if (d == 0.0) {
        flt[0] = flt[1] = flt[2] = flt[3] = 0;  /* All-bits-zero equals zero */
        return 1;                      /* Good job. */
    }

    frac = frexp(d, &sexp);            /* Separate into exponent and mantissa */
    if (sexp < -128 || sexp > 127)
        return 0;                      /* Exponent out of range. */

    uexp = sexp + 128;                  /* Make excess-128 mode */
    uexp &= 0xff;                       /* express in 8 bits */

    if (frac < 0) {
        sign = 0100000;                /* Negative sign */
        frac = -frac;                  /* fix the mantissa */
    }

    /* The following big literal is 2 to the 49th power: */
    ufrac = (ulong64) (frac * 72057594037927936.0);     /* Align fraction bits */

    /* Round from FLT4 to FLT2 */
    if (size < 4) {
        ufrac += 0x80000000;           /* Round to nearest 32-bit
                                          representation */

        if (ufrac > 0x200000000000) {  /* Overflow? */
            ufrac >>= 1;               /* Normalize */
            uexp--;
        }
    }

    flt[0] = (unsigned) (sign | (uexp << 7) | ((ufrac >> 48) & 0x7F));
    if (size > 1) {
        flt[1] = (unsigned) ((ufrac >> 32) & 0xffff);
        if (size > 2) {
            flt[2] = (unsigned) ((ufrac >> 16) & 0xffff);
            flt[3] = (unsigned) ((ufrac >> 0) & 0xffff);
        }
    }

    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rcx, %rbx
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %r12
leaq 0x74d6(%rip), %rsi      # 0x10626
xorl %r14d, %r14d
leaq 0x10(%rsp), %rdx
leaq 0xc(%rsp), %rcx
xorl %eax, %eax
callq 0x2240
testl %eax, %eax
je 0x9265
testq %r15, %r15
je 0x917c
movslq 0xc(%rsp), %rax
addq %rax, %r12
movq %r12, (%r15)
movsd 0x10(%rsp), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x91a1
jp 0x91a1
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx)
movl $0x1, %r14d
jmp 0x9265
leaq 0x1c(%rsp), %r15
movq %r15, %rdi
callq 0x21b0
movl (%r15), %eax
movsbl %al, %ecx
cmpl %eax, %ecx
jne 0x9265
movzbl %al, %eax
xorl $0x80, %eax
movapd 0x73e4(%rip), %xmm1     # 0x105b0
xorpd %xmm0, %xmm1
xorl %edx, %edx
ucomisd %xmm0, %xmm1
seta %dl
maxsd %xmm0, %xmm1
mulsd 0x73db(%rip), %xmm1     # 0x105c0
shll $0xf, %edx
cvttsd2si %xmm1, %rsi
movq %rsi, %rdi
subsd 0x73d0(%rip), %xmm1     # 0x105c8
cvttsd2si %xmm1, %rcx
sarq $0x3f, %rdi
andq %rdi, %rcx
orq %rsi, %rcx
cmpl $0x3, %ebp
jg 0x9227
subq $-0x80000000, %rcx      # imm = 0x80000000
movabsq $0x200000000001, %rsi   # imm = 0x200000000001
cmpq %rsi, %rcx
jb 0x9227
shrq %rcx
decl %eax
shll $0x7, %eax
orl %edx, %eax
movq %rcx, %rdx
shrq $0x30, %rdx
andl $0x7f, %edx
orl %eax, %edx
movl %edx, (%rbx)
movl $0x1, %r14d
cmpl $0x2, %ebp
jl 0x9265
movq %rcx, %rax
shrq $0x20, %rax
movzwl %ax, %eax
movl %eax, 0x4(%rbx)
cmpl $0x2, %ebp
je 0x9265
movl %ecx, %eax
shrl $0x10, %eax
movl %eax, 0x8(%rbx)
movzwl %cx, %eax
movl %eax, 0xc(%rbx)
movl %r14d, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq