// File: /workspace/github_c_makefile_star2_O2/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
callq 0x2675
movq %rax, %rbx
leaq 0x80289(%rip), %r14     # 0x84070
movl $0x100, %edx            # imm = 0x100
movq %r14, %rdi
xorl %esi, %esi
callq 0x2180
cmpb $0x24, (%rbx)
jne 0x3e28
incq %rbx
xorl %r15d, %r15d
cmpq $0x4, %r15
je 0x3f37
movq %rbx, %rdi
callq 0x3d9d
testl %eax, %eax
js 0x3f37
movb %al, (%r15,%r14)
incq %r15
addq $0x2, %rbx
jmp 0x3e01
leaq 0x75cc(%rip), %rsi      # 0xb3fb
pushq $0x5
popq %rdx
movq %rbx, %rdi
callq 0x291a
movq %rbx, %rdi
testl %eax, %eax
je 0x3e4a
xorl %esi, %esi
callq 0x20e0
jmp 0x3e6a
addq $0x5, %rdi
xorl %esi, %esi
callq 0x20e0
mulsd 0x71ab(%rip), %xmm0     # 0xb008
divsd 0x71ab(%rip), %xmm0     # 0xb010
callq 0x2190
movapd %xmm0, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x3e7e
jnp 0x3f37
movapd 0x719a(%rip), %xmm0     # 0xb020
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 0x3ecd
leaq 0x7546(%rip), %rdi      # 0xb401
xorl %eax, %eax
callq 0x2af7
incl 0x20b64(%rip)           # 0x24a2c
jmp 0x402d
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd 0x10(%rsp), %xmm1
seta %al
shll $0x7, %eax
movb %sil, 0x8018a(%rip)     # 0x84070
mulsd 0x712a(%rip), %xmm0     # 0xb018
cvttsd2si %xmm0, %ecx
andl $0x7f, %ecx
orl %eax, %ecx
cvttpd2dq %xmm0, %xmm1
cvtdq2pd %xmm1, %xmm1
movb %cl, 0x8016c(%rip)      # 0x84071
subsd %xmm1, %xmm0
xorl %eax, %eax
movsd 0x7105(%rip), %xmm1     # 0xb018
cmpq $0x4, %rax
je 0x3f37
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movb %cl, 0x2(%rax,%r14)
cvttpd2dq %xmm0, %xmm2
cvtdq2pd %xmm2, %xmm2
subsd %xmm2, %xmm0
incq %rax
jmp 0x3f13
cmpb $0x0, 0x80136(%rip)     # 0x84074
jns 0x3f83
pushq $0x3
popq %rax
cmpl $0x2, %eax
jb 0x3f54
movl %eax, %ecx
decl %eax
incb (%rcx,%r14)
je 0x3f43
jmp 0x3f83
movzbl 0x80116(%rip), %eax     # 0x84071
cmpl $0xff, %eax
je 0x3f71
cmpl $0x7f, %eax
jne 0x3f7b
incb 0x80103(%rip)           # 0x84070
xorl %eax, %eax
jmp 0x3f7d
incb 0x800f9(%rip)           # 0x84070
movb $-0x80, %al
jmp 0x3f7d
incb %al
movb %al, 0x800ee(%rip)      # 0x84071
testl %ebp, %ebp
jne 0x402d
cmpl $0x0, 0x20a86(%rip)     # 0x24a18
movl 0xf79c(%rip), %eax      # 0x13734
jne 0x4024
movslq %eax, %rcx
xorl %edx, %edx
leaq 0xfca6(%rip), %rsi      # 0x13c50
cmpq $0x4, %rdx
je 0x3fc1
movb (%rdx,%r14), %dil
leaq (%rcx,%rdx), %r8
movb %dil, (%rsi,%r8)
incq %rdx
jmp 0x3faa
cmpl $0x0, 0xd1f0(%rip)      # 0x111b8
je 0x4024
callq 0x2c8c
movq 0x20a32(%rip), %rdi     # 0x24a08
movzbl 0x80093(%rip), %edx     # 0x84070
movzbl 0x8008d(%rip), %ecx     # 0x84071
movzbl 0x80086(%rip), %r8d     # 0x84072
movzbl 0x8007f(%rip), %r9d     # 0x84073
leaq 0x7420(%rip), %rsi      # 0xb41b
xorl %eax, %eax
callq 0x2210
movq 0x209ff(%rip), %rdi     # 0x24a08
leaq 0x7210(%rip), %rsi      # 0xb220
leaq 0x1fe89(%rip), %rdx     # 0x23ea0
xorl %eax, %eax
callq 0x2210
movl 0xf710(%rip), %eax      # 0x13734
addl $0x4, %eax
movl %eax, 0xf707(%rip)      # 0x13734
movq %rbx, %rdi
callq 0x2110
addq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq