// File: sundale[P]gcode/rs274ngc/interp_read.cc
// Function: Interp::read_real_expression(char*, int*, double*, double*)
int Interp::read_real_expression(char *line,     //!< string: line of RS274/NGC code being processed
                                int *counter,   //!< pointer to a counter for position on the line 
                                double *value,  //!< pointer to double to be computed              
                                double *parameters)     //!< array of system parameters                    
{
  double values[MAX_STACK];
  int operators[MAX_STACK];
  int stack_index;

  CHKS((line[*counter] != '['), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
  *counter = (*counter + 1);
  CHP(read_real_value(line, counter, values, parameters));
  CHP(read_operation(line, counter, operators));
  stack_index = 1;
  for (; operators[0] != RIGHT_BRACKET;) {
    CHP(read_real_value(line, counter, values + stack_index, parameters));
    CHP(read_operation(line, counter, operators + stack_index));
    if (precedence(operators[stack_index]) >
        precedence(operators[stack_index - 1]))
      stack_index++;
    else {                      /* precedence of latest operator is <= previous precedence */

      for (; precedence(operators[stack_index]) <=
           precedence(operators[stack_index - 1]);) {
        CHP(execute_binary((values + stack_index - 1),
                           operators[stack_index - 1],
                           (values + stack_index)));
        operators[stack_index - 1] = operators[stack_index];
        if ((stack_index > 1) &&
            (precedence(operators[stack_index - 1]) <=
             precedence(operators[stack_index - 2])))
          stack_index--;
        else
          break;
      }
    }
  }
  *value = values[0];
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq (%rcx), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5b, %eax
je 0x5d24a
jmp 0x5d174
leaq 0x1f26a(%rip), %rdi     # 0x7c3e5
callq 0x10380
movq -0xb0(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x29dc8(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x29db7(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x29da9(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x214be(%rip), %rsi     # 0x7e68a
movl $0x50, %edx
callq 0x10840
movq 0x29d83(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x29d75(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x29d5d(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x29d4d(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x29d40(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x29d32(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x5d8cb
jmp 0x5d24c
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0xb0(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x70(%rbp), %rcx
movq -0x30(%rbp), %r8
callq 0x118a0
movl %eax, -0x98(%rbp)
cmpl $0x0, -0x98(%rbp)
je 0x5d34a
jmp 0x5d28c
movq 0x29ccd(%rip), %rax     # 0x86f60
cmpl $0x31, 0xd670(%rax)
jge 0x5d33c
movq 0x29cb9(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x29cab(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x213c0(%rip), %rsi     # 0x7e68a
movl $0x50, %edx
callq 0x10840
movq 0x29c85(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x29c77(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x29c5f(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x29c4f(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x29c42(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x29c34(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl -0x98(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5d8cb
jmp 0x5d34c
jmp 0x5d34e
movq -0xb0(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x90(%rbp), %rcx
callq 0x11a30
movl %eax, -0x9c(%rbp)
cmpl $0x0, -0x9c(%rbp)
je 0x5d43c
jmp 0x5d37e
movq 0x29bdb(%rip), %rax     # 0x86f60
cmpl $0x31, 0xd670(%rax)
jge 0x5d42e
movq 0x29bc7(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x29bb9(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x212ce(%rip), %rsi     # 0x7e68a
movl $0x50, %edx
callq 0x10840
movq 0x29b93(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x29b85(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x29b6d(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x29b5d(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x29b50(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x29b42(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl -0x9c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5d8cb
jmp 0x5d43e
movl $0x1, -0x94(%rbp)
cmpl $0xa, -0x90(%rbp)
je 0x5d8b7
jmp 0x5d457
movq -0xb0(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x70(%rbp), %rcx
movslq -0x94(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rcx
movq -0x30(%rbp), %r8
callq 0x118a0
movl %eax, -0xa0(%rbp)
cmpl $0x0, -0xa0(%rbp)
je 0x5d554
jmp 0x5d496
movq 0x29ac3(%rip), %rax     # 0x86f60
cmpl $0x31, 0xd670(%rax)
jge 0x5d546
movq 0x29aaf(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x29aa1(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x211b6(%rip), %rsi     # 0x7e68a
movl $0x50, %edx
callq 0x10840
movq 0x29a7b(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x29a6d(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x29a55(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x29a45(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x29a38(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x29a2a(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl -0xa0(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5d8cb
jmp 0x5d556
jmp 0x5d558
movq -0xb0(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x90(%rbp), %rcx
movslq -0x94(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rcx
callq 0x11a30
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
je 0x5d654
jmp 0x5d596
movq 0x299c3(%rip), %rax     # 0x86f60
cmpl $0x31, 0xd670(%rax)
jge 0x5d646
movq 0x299af(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x299a1(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x210b6(%rip), %rsi     # 0x7e68a
movl $0x50, %edx
callq 0x10840
movq 0x2997b(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x2996d(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x29955(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x29945(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x29938(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x2992a(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl -0xa4(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5d8cb
jmp 0x5d656
movq -0xb0(%rbp), %rdi
movslq -0x94(%rbp), %rax
movl -0x90(%rbp,%rax,4), %esi
callq 0x101f0
movq -0xb0(%rbp), %rdi
movl %eax, -0xb4(%rbp)
movl -0x94(%rbp), %eax
subl $0x1, %eax
cltq
movl -0x90(%rbp,%rax,4), %esi
callq 0x101f0
movl %eax, %ecx
movl -0xb4(%rbp), %eax
cmpl %ecx, %eax
jle 0x5d6b4
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x5d8b2
jmp 0x5d6b6
movq -0xb0(%rbp), %rdi
movslq -0x94(%rbp), %rax
movl -0x90(%rbp,%rax,4), %esi
callq 0x101f0
movq -0xb0(%rbp), %rdi
movl %eax, -0xb8(%rbp)
movl -0x94(%rbp), %eax
subl $0x1, %eax
cltq
movl -0x90(%rbp,%rax,4), %esi
callq 0x101f0
movl %eax, %ecx
movl -0xb8(%rbp), %eax
cmpl %ecx, %eax
jg 0x5d8b0
jmp 0x5d706
movq -0xb0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movslq -0x94(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
addq $-0x8, %rsi
movl -0x94(%rbp), %eax
subl $0x1, %eax
cltq
movl -0x90(%rbp,%rax,4), %edx
leaq -0x70(%rbp), %rcx
movslq -0x94(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rcx
callq 0x10420
movl %eax, -0xa8(%rbp)
cmpl $0x0, -0xa8(%rbp)
je 0x5d81f
jmp 0x5d761
movq 0x297f8(%rip), %rax     # 0x86f60
cmpl $0x31, 0xd670(%rax)
jge 0x5d811
movq 0x297e4(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x297d6(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x20eeb(%rip), %rsi     # 0x7e68a
movl $0x50, %edx
callq 0x10840
movq 0x297b0(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x297a2(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x2978a(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x2977a(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x2976d(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x2975f(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl -0xa8(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5d8cb
jmp 0x5d821
movslq -0x94(%rbp), %rax
movl -0x90(%rbp,%rax,4), %ecx
movl -0x94(%rbp), %eax
subl $0x1, %eax
cltq
movl %ecx, -0x90(%rbp,%rax,4)
cmpl $0x1, -0x94(%rbp)
jle 0x5d8a9
movq -0xb0(%rbp), %rdi
movl -0x94(%rbp), %eax
subl $0x1, %eax
cltq
movl -0x90(%rbp,%rax,4), %esi
callq 0x101f0
movq -0xb0(%rbp), %rdi
movl %eax, -0xbc(%rbp)
movl -0x94(%rbp), %eax
subl $0x2, %eax
cltq
movl -0x90(%rbp,%rax,4), %esi
callq 0x101f0
movl %eax, %ecx
movl -0xbc(%rbp), %eax
cmpl %ecx, %eax
jg 0x5d8a9
movl -0x94(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x5d8ab
jmp 0x5d8b0
jmp 0x5d6b6
jmp 0x5d8b2
jmp 0x5d448
movsd -0x70(%rbp), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopw (%rax,%rax)