// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x54(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x8ec5(%rip), %rsi      # 0x156fe
leaq -0x30(%rbp), %rdx
leaq -0x48(%rbp), %rcx
movb $0x0, %al
callq 0x2230
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0xc85d
movl $0x0, -0x4(%rbp)
jmp 0xca31
movl -0x48(%rbp), %ecx
movq -0x10(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xc880
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xc8c7
jp 0xc8c7
movq -0x28(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0xca31
movsd -0x30(%rbp), %xmm0
leaq -0x4c(%rbp), %rdi
callq 0x2190
movsd %xmm0, -0x38(%rbp)
cmpl $-0x80, -0x4c(%rbp)
jl 0xc8e6
cmpl $0x7f, -0x4c(%rbp)
jle 0xc8f2
movl $0x0, -0x4(%rbp)
jmp 0xca31
movl -0x4c(%rbp), %eax
addl $0x80, %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
andl $0xff, %eax
movl %eax, -0x50(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x38(%rbp), %xmm0
jbe 0xc93a
movl $0x8000, -0x54(%rbp)    # imm = 0x8000
movsd -0x38(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movsd 0x8d09(%rip), %xmm1     # 0x15650
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x8cf6(%rip), %xmm1     # 0x15658
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x40(%rbp)
cmpl $0x4, -0x1c(%rbp)
jge 0xc9b3
movabsq $0x80000000, %rax       # imm = 0x80000000
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movabsq $0x200000000000, %rax   # imm = 0x200000000000
cmpq %rax, -0x40(%rbp)
jbe 0xc9b1
movq -0x40(%rbp), %rax
shrq %rax
movq %rax, -0x40(%rbp)
movl -0x50(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0xc9b3
movl -0x54(%rbp), %eax
movl -0x50(%rbp), %ecx
shll $0x7, %ecx
orl %ecx, %eax
movl %eax, %eax
movq -0x40(%rbp), %rcx
shrq $0x30, %rcx
andq $0x7f, %rcx
orq %rcx, %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x1, -0x1c(%rbp)
jle 0xca2a
movq -0x40(%rbp), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
cmpl $0x2, -0x1c(%rbp)
jle 0xca28
movq -0x40(%rbp), %rax
shrq $0x10, %rax
andq $0xffff, %rax           # imm = 0xFFFF
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x40(%rbp), %rax
shrq $0x0, %rax
andq $0xffff, %rax           # imm = 0xFFFF
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0xca2a
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)