// File: /workspace/github_c_makefile_star2_O3/Edilbert[P]BS9/bs9.c
// Function: ParseRealData
char *ParseRealData(char *p, int ldq)
{

   int v;
   int i,mansize;
   int Sign,Exponent;
   double d;

   mansize = 3; // default mantissa size

   p = SkipSpace(p);
   memset(Operand,0,sizeof(Operand));

   if (*p == '$')
   {
      ++p;
      for (i=0 ; i <= mansize ; ++i, p+=2)
      {
          v = Hex2Byte(p);
          if (v < 0) break;
          Operand[i] = v;
      }
   }
   else
   {
      if (!StrNCaseCmp(p,"cosd(",5))
      {
         d = strtod(p+5,NULL);
         d = cos(M_PI * d / 180.0);
      }
      else d = strtod(p,NULL);
      if (d != 0)
      {
         Sign = 0;
         if (d < 0)
         {
            Sign = 0x80;
            d = -d;
         }
         d = frexp(d,&Exponent);
         Exponent += 0x80;
         if (Exponent < 1 || Exponent > 255)
         {
            ErrorMsg("Exponent %d out of range\n",Exponent);
            ++ErrNum;
            return p+strlen(p);;
         }
         Operand[0] = Exponent;
         d *= 256;
         v = d;
         Operand[1] = (v & 127) | Sign;
         d -= v;

         for (i=2 ; i < 6 ; ++i)
         {
            d *= 256;
            Operand[i] = v = d;
            d -= v;
         }
      }
   }

   // Round

   if (Operand[mansize+1] & 0x80) // rounding bit set
   {
      for (i=mansize ; i > 1 ; --i)
      {
         if (++Operand[i]) break; // no carry
      }
      if (i == 1) // carry was propagated
      {
         if (Operand[1] == 0x7f) // highest positive value
         {
            ++Operand[0];        // Increment exponent
              Operand[1] = 0;
         }
         else if (Operand[1] == 0xff)
         {
            ++Operand[0];        // Increment exponent
              Operand[1] = 0x80;
         }
         else ++Operand[1];
      }
   }

   if (!ldq)
   {
      if (!Pass)
      {
         for (i=0 ; i < mansize+1 ; ++i) PutByte(pc+i,Operand[i]);
         if (ListOn)
         {
            PrintPC();
            fprintf(lf," %2.2x %2.2x%2.2x%2.2x  ",
               Operand[0],Operand[1],Operand[2],Operand[3]);
            fprintf(lf," %s\n",Line);
         }
      }
      pc += mansize+1;
   }
   return p + strlen(p);;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x28, %rsp
movl %esi, %ebp
movq %rdi, %rbx
cmpb $0x0, (%rdi)
je 0x4544
callq 0x2320
movq (%rax), %rax
decq %rbx
movsbq 0x1(%rbx), %rcx
incq %rbx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x4535
leaq 0x80b25(%rip), %r14     # 0x85070
movl $0x100, %edx            # imm = 0x100
movq %r14, %rdi
xorl %esi, %esi
callq 0x2180
cmpb $0x24, (%rbx)
jne 0x458b
incq %rbx
xorl %r15d, %r15d
movq %rbx, %rdi
callq 0x44a3
testl %eax, %eax
js 0x469a
movb %al, (%r15,%r14)
incq %r15
addq $0x2, %rbx
cmpq $0x4, %r15
jne 0x4565
jmp 0x469a
leaq 0x7ed9(%rip), %rsi      # 0xc46b
movq %rbx, %rdi
movl $0x5, %edx
callq 0x2c53
testl %eax, %eax
je 0x45af
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20e0
jmp 0x45cf
leaq 0x5(%rbx), %rdi
xorl %esi, %esi
callq 0x20e0
mulsd 0x7a46(%rip), %xmm0     # 0xc008
divsd 0x7a46(%rip), %xmm0     # 0xc010
callq 0x2190
movapd %xmm0, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x45e3
jnp 0x469a
movapd 0x7a35(%rip), %xmm0     # 0xc020
xorpd %xmm1, %xmm0
movapd %xmm1, 0x10(%rsp)
maxsd %xmm1, %xmm0
leaq 0xc(%rsp), %r15
movq %r15, %rdi
callq 0x21d0
movl (%r15), %eax
leal 0x80(%rax), %esi
addl $-0x80, %eax
cmpl $0xffffff00, %eax       # imm = 0xFFFFFF00
ja 0x4632
leaq 0x7e51(%rip), %rdi      # 0xc471
xorl %eax, %eax
callq 0x2e72
incl 0x213ff(%rip)           # 0x25a2c
jmp 0x477a
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd 0x10(%rsp), %xmm1
seta %al
shll $0x7, %eax
movb %sil, 0x80a25(%rip)     # 0x85070
mulsd 0x79c5(%rip), %xmm0     # 0xc018
cvttsd2si %xmm0, %ecx
andl $0x7f, %ecx
orl %eax, %ecx
cvttpd2dq %xmm0, %xmm1
cvtdq2pd %xmm1, %xmm1
movb %cl, 0x80a07(%rip)      # 0x85071
subsd %xmm1, %xmm0
xorl %eax, %eax
movsd 0x79a0(%rip), %xmm1     # 0xc018
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
cvttpd2dq %xmm0, %xmm2
cvtdq2pd %xmm2, %xmm2
movb %cl, 0x2(%rax,%r14)
subsd %xmm2, %xmm0
incq %rax
cmpq $0x4, %rax
jne 0x4678
cmpb $0x0, 0x809d3(%rip)     # 0x85074
jns 0x46e4
movl $0x4, %eax
decl %eax
incb (%rax,%r14)
jne 0x46e4
cmpl $0x2, %eax
ja 0x46a8
movzbl 0x809b5(%rip), %eax     # 0x85071
cmpl $0xff, %eax
je 0x46d2
cmpl $0x7f, %eax
jne 0x46dc
incb 0x809a2(%rip)           # 0x85070
xorl %eax, %eax
jmp 0x46de
incb 0x80998(%rip)           # 0x85070
movb $-0x80, %al
jmp 0x46de
incb %al
movb %al, 0x8098d(%rip)      # 0x85071
testl %ebp, %ebp
jne 0x477a
cmpl $0x0, 0x21325(%rip)     # 0x25a18
movl 0x1003b(%rip), %eax     # 0x14734
jne 0x4771
movslq %eax, %rcx
leaq 0x1054b(%rip), %rdx     # 0x14c50
movl 0x80965(%rip), %esi     # 0x85070
movl %esi, (%rcx,%rdx)
cmpl $0x0, 0xdaa3(%rip)      # 0x121b8
je 0x4771
callq 0x3014
movq 0x212e5(%rip), %rdi     # 0x25a08
movzbl 0x80946(%rip), %edx     # 0x85070
movzbl 0x80940(%rip), %ecx     # 0x85071
movzbl 0x80939(%rip), %r8d     # 0x85072
movzbl 0x80932(%rip), %r9d     # 0x85073
leaq 0x7d43(%rip), %rsi      # 0xc48b
xorl %eax, %eax
callq 0x2210
movq 0x212b2(%rip), %rdi     # 0x25a08
leaq 0x7b33(%rip), %rsi      # 0xc290
leaq 0x2073c(%rip), %rdx     # 0x24ea0
xorl %eax, %eax
callq 0x2210
movl 0xffc3(%rip), %eax      # 0x14734
addl $0x4, %eax
movl %eax, 0xffba(%rip)      # 0x14734
movq %rbx, %rdi
callq 0x2110
addq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq