// File: /workspace/github_c_makefile_star2_O1/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 0x44d2
callq 0x2320
movq (%rax), %rax
decq %rbx
movsbq 0x1(%rbx), %rcx
incq %rbx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x44c3
leaq 0x80b97(%rip), %r14     # 0x85070
movl $0x100, %edx            # imm = 0x100
movq %r14, %rdi
xorl %esi, %esi
callq 0x2180
cmpb $0x24, (%rbx)
jne 0x4519
incq %rbx
xorl %r15d, %r15d
movq %rbx, %rdi
callq 0x4431
testl %eax, %eax
js 0x4631
movb %al, (%r15,%r14)
incq %r15
addq $0x2, %rbx
cmpq $0x4, %r15
jne 0x44f3
jmp 0x4631
leaq 0x7f5f(%rip), %rsi      # 0xc47f
movq %rbx, %rdi
movl $0x5, %edx
callq 0x2c50
testl %eax, %eax
je 0x453d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20e0
jmp 0x455d
leaq 0x5(%rbx), %rdi
xorl %esi, %esi
callq 0x20e0
mulsd 0x7ab8(%rip), %xmm0     # 0xc008
divsd 0x7ab8(%rip), %xmm0     # 0xc010
callq 0x2190
movapd %xmm0, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x4571
jnp 0x4631
movapd 0x7aa7(%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
movl %esi, (%r15)
addl $-0x80, %eax
cmpl $0xffffff00, %eax       # imm = 0xFFFFFF00
ja 0x45c9
leaq 0x7ed4(%rip), %rdi      # 0xc485
xorl %eax, %eax
callq 0x2e63
movl $0x1, %ebp
leaq 0x21468(%rip), %r14     # 0x25a2c
jmp 0x4719
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd 0x10(%rsp), %xmm1
seta %al
shll $0x7, %eax
movb %sil, 0x80a8e(%rip)     # 0x85070
mulsd 0x7a2e(%rip), %xmm0     # 0xc018
cvttsd2si %xmm0, %ecx
andl $0x7f, %ecx
orl %eax, %ecx
cvttpd2dq %xmm0, %xmm1
cvtdq2pd %xmm1, %xmm1
movb %cl, 0x80a70(%rip)      # 0x85071
subsd %xmm1, %xmm0
xorl %eax, %eax
movsd 0x7a09(%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 0x460f
cmpb $0x0, 0x80a3c(%rip)     # 0x85074
jns 0x4688
movl $0x4, %eax
leal -0x1(%rax), %ecx
incb (%rcx,%r14)
jne 0x4654
decl %eax
cmpl $0x2, %eax
ja 0x463f
movl $0x1, %ecx
cmpl $0x1, %ecx
jne 0x4688
movzbl 0x80a11(%rip), %eax     # 0x85071
cmpl $0xff, %eax
je 0x4676
cmpl $0x7f, %eax
jne 0x4680
incb 0x809fe(%rip)           # 0x85070
xorl %eax, %eax
jmp 0x4682
incb 0x809f4(%rip)           # 0x85070
movb $-0x80, %al
jmp 0x4682
incb %al
movb %al, 0x809e9(%rip)      # 0x85071
testl %ebp, %ebp
jne 0x471c
movl $0x4, %ebp
leaq 0x10098(%rip), %r14     # 0x14734
cmpl $0x0, 0x21375(%rip)     # 0x25a18
jne 0x4719
movslq 0x10088(%rip), %rax     # 0x14734
leaq 0x1059d(%rip), %rcx     # 0x14c50
movl 0x809b7(%rip), %edx     # 0x85070
movl %edx, (%rax,%rcx)
cmpl $0x0, 0xdaf5(%rip)      # 0x121b8
je 0x4719
callq 0x3005
movq 0x21337(%rip), %rdi     # 0x25a08
movzbl 0x80998(%rip), %edx     # 0x85070
movzbl 0x80992(%rip), %ecx     # 0x85071
movzbl 0x8098b(%rip), %r8d     # 0x85072
movzbl 0x80984(%rip), %r9d     # 0x85073
leaq 0x7da9(%rip), %rsi      # 0xc49f
xorl %eax, %eax
callq 0x2210
movq 0x21304(%rip), %rdi     # 0x25a08
leaq 0x7b99(%rip), %rsi      # 0xc2a4
leaq 0x2078e(%rip), %rdx     # 0x24ea0
xorl %eax, %eax
callq 0x2210
addl %ebp, (%r14)
movq %rbx, %rdi
callq 0x2110
addq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq