// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathui.cpp
// Function: rpn_calc()
int rpn_calc()
{
   // rpn calculator
   if(last_touch_key == 999) {  // ? command sent from touch keyboard
      show_rpn_help = 1;
   }

   rpn_break = 0;
   if(edit_buffer[0] == 0) {  // empty line, exit calculator
      if(zoom_screen) remove_zoom();
      rpn_mode = 0;
      show_version_header();
      rpn_unnest();
      rpn_err_flag = 0;
      return 0;
   }

// rpn_err_flag = 0;
   rpn_mode = 1;
   show_version_header();
   strlwr(edit_buffer);
   strcpy(nmea_msg, edit_buffer);  // prepare to parse the line
   msg_col = 0;

if(strstr(edit_buffer, "z`")) goto poop;

   // process the line of calculator commands (separated by spaces)
   rpn_again:
   msg_field[0] = 0;
   while(get_msg_field()) {
//      if(!strcmp(msg_field, "?") == 0) {
      if(strcmp(msg_field, "?")) {
         if(last_touch_key == 999) { last_touch_key = 0; show_rpn_help = 0;}
      }

      if(rpn_break) {   // stop parsing line on any errors or "break" command
         rpn_break = 0;
         skip_next_rpn = 0;
         break;
      }

      if(skip_next_rpn > 1) {  // conditional was true skip second operand
         --skip_next_rpn;
      }
      else if(skip_next_rpn == 1) {  // skip next command
         skip_next_rpn = 0;
         continue;
      }
      else if(skip_next_rpn < 0) {  // skip rest of line
         skip_next_rpn = 0;
         break;
      }

      // see what we just got
      if((msg_field[0] == '.') && msg_field[1]) {  // floating point number
         if(valid_num(msg_field)) get_rpn_num();
         else {
            sprintf(out, "Invalid number: %s", msg_field);
            rpn_error(out);
            break;
         }
      }
      else if((msg_field[0] == '+') && msg_field[1]) { // signed number
         if(valid_num(msg_field)) get_rpn_num();
         else {
            sprintf(out, "Invalid number: %s", msg_field);
            rpn_error(out);
            break;
         }
      }
      else if((msg_field[0] == '-') && msg_field[1]) { // signed number
         if(valid_num(msg_field)) get_rpn_num();
         else {
            sprintf(out, "Invalid number: %s", msg_field);
            rpn_error(out);
            break;
         }
      }
      else if(isdigit(msg_field[0])) { // possible number
         if((msg_field[0] == '0') && (msg_field[1] == 'x')) {  // hex number
            if(valid_hex(&msg_field[2])) get_rpn_num();
            else {
               sprintf(out, "Invalid hex constant: %s", msg_field);
               rpn_error(out);
               break;
            }
         }
         else if((msg_field[0] == '0') && (msg_field[1] == 'o')) {  // octal number
            if(valid_octal(&msg_field[2])) get_rpn_num();
            else {
               sprintf(out, "Invalid octal constant: %s", msg_field);
               rpn_error(out);
               break;
            }
         }
         else if((msg_field[0] == '0') && (msg_field[1] == 'b')) {  // binary number
            if(valid_binary(&msg_field[2])) get_rpn_num();
            else {
               sprintf(out, "Invalid binary constant: %s", msg_field);
               rpn_error(out);
               break;
            }
         }
         else if(valid_num(msg_field)) {  // decimal number
            get_rpn_num();
         }
         else {
            sprintf(out, "Invalid number: %s", msg_field);
            rpn_error(out);
            break;
         }
      }
      else if(rpn_const()) ;   // calculator operations (constants, etc - rpn_const() must be called before rpn_math)
      else if(rpn_math()) ;    // calculator operations (math, etc)
      else if(!strcmp(msg_field, "?"))    { show_rpn_help = 1; }
      else if(!strcmp(msg_field, "help")) { show_rpn_help = 1; }
      else if(!strcmp(msg_field, "showdefs")) { show_rpn_help = 2; }
      else if(!strcmp(msg_field, "zoom")) {
         add_kbd(ESC_CHAR);
         start_calc_zoom(10);
      }
      else if(msg_field[0]) {
         sprintf(out, "Unknown operation: (%s)", msg_field);
         rpn_error(out);
         break;
      }
      else break;  // end of line
   }

poop:
   skip_next_rpn = 0;
   if(rpn_unnest()) {  // we got to the end of a user defined command, go back to where we were
      goto rpn_again;
   }

   rpn_show(); // show the rpn stack
   rpn_mode = (-1);

   return rpn_err_flag;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x1f7b73(%rip), %r15    # 0x21b228
cmpl $0x3e7, (%r15)          # imm = 0x3E7
jne 0x236cb
leaq 0x318167(%rip), %rax    # 0x33b82c
movl $0x1, (%rax)
movl $0x0, 0x31f67b(%rip)    # 0x342d50
leaq 0x31bc04(%rip), %rax    # 0x33f2e0
cmpb $0x0, (%rax)
je 0x23738
leaq 0x318140(%rip), %rax    # 0x33b828
movl $0x1, (%rax)
callq 0x727c3
leaq 0x31bbe6(%rip), %rbx    # 0x33f2e0
movq %rbx, %rdi
callq 0x986c
leaq 0x318127(%rip), %rdi    # 0x33b830
movq %rbx, %rsi
callq 0x9340
leaq 0x31852c(%rip), %rax    # 0x33bc44
movl $0x0, (%rax)
leaq 0xea25e(%rip), %rsi     # 0x10d983
movq %rbx, %rdi
callq 0x9090
testq %rax, %rax
jne 0x23992
jmp 0x23769
leaq 0x2e9069(%rip), %rax    # 0x30c7a8
cmpb $0x0, (%rax)
je 0x23749
callq 0x23ad7
leaq 0x3180d8(%rip), %rax    # 0x33b828
xorl %ebx, %ebx
movl %ebx, (%rax)
callq 0x727c3
callq 0x23ba6
movl %ebx, 0x320fb4(%rip)    # 0x344718
jmp 0x239c1
leaq 0x3182d0(%rip), %rbx    # 0x33ba40
movb $0x0, (%rbx)
callq 0x811da
testl %eax, %eax
je 0x23992
xorl %r13d, %r13d
leaq 0x3180a2(%rip), %r12    # 0x33b82c
leaq 0x2(%rbx), %r14
cmpw $0x3f, (%rbx)
je 0x237a4
cmpl $0x3e7, (%r15)          # imm = 0x3E7
jne 0x237a4
movl %r13d, (%r15)
movl %r13d, (%r12)
cmpl $0x0, 0x31f5a5(%rip)    # 0x342d50
jne 0x2394f
movl 0x31f595(%rip), %eax    # 0x342d4c
cmpl $0x2, %eax
jl 0x237c6
decl %eax
movl %eax, 0x31f588(%rip)    # 0x342d4c
jmp 0x237df
cmpl $0x1, %eax
jne 0x237d7
movl $0x0, 0x31f577(%rip)    # 0x342d4c
jmp 0x23837
testl %eax, %eax
js 0x23988
movsbl (%rbx), %eax
cmpl $0x2e, %eax
sete %dl
movb 0x1(%rbx), %cl
testb %cl, %cl
setne %sil
andb %dl, %sil
cmpb $0x1, %sil
je 0x23822
testb %cl, %cl
setne %dl
cmpb $0x2b, %al
sete %sil
andb %dl, %sil
cmpb $0x1, %sil
je 0x23822
testb %cl, %cl
setne %dl
cmpb $0x2d, %al
sete %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x23849
movq %rbx, %rdi
callq 0x248f6
testl %eax, %eax
je 0x2395f
callq 0x249ed
callq 0x811da
testl %eax, %eax
jne 0x2378e
jmp 0x23992
leal -0x30(%rax), %edx
cmpl $0x9, %edx
ja 0x23871
xorb $0x30, %al
movl %ecx, %edx
xorb $0x78, %dl
orb %al, %dl
jne 0x238f7
movq %r14, %rdi
callq 0x247f1
testl %eax, %eax
jne 0x23832
jmp 0x239d2
callq 0x24b7b
testl %eax, %eax
jne 0x23837
callq 0x256a8
testl %eax, %eax
jne 0x23837
cmpw $0x3f, (%rbx)
je 0x23935
movl (%rbx), %eax
movl $0x706c6568, %ecx       # imm = 0x706C6568
xorl %ecx, %eax
movzbl 0x4(%rbx), %ecx
orl %eax, %ecx
je 0x23935
movq (%rbx), %rax
movabsq $0x73666564776f6873, %rcx # imm = 0x73666564776F6873
xorq %rcx, %rax
movzbl 0x8(%rbx), %ecx
orq %rax, %rcx
je 0x23942
movl (%rbx), %eax
movl $0x6d6f6f7a, %ecx       # imm = 0x6D6F6F7A
xorl %ecx, %eax
movzbl 0x4(%rbx), %ecx
orl %eax, %ecx
jne 0x23a08
movl $0x1b, %edi
callq 0xd4e7
movl $0x7a, %edi
callq 0xd4e7
movl $0x60, %edi
callq 0xd4e7
jmp 0x23837
movl %ecx, %edx
xorb $0x6f, %dl
orb %al, %dl
jne 0x23915
movq %r14, %rdi
callq 0x24854
testl %eax, %eax
jne 0x23832
jmp 0x239e2
xorb $0x62, %cl
orb %cl, %al
jne 0x23822
movq %r14, %rdi
callq 0x248a5
testl %eax, %eax
jne 0x23832
jmp 0x239f5
movl $0x1, (%r12)
jmp 0x23837
movl $0x2, (%r12)
jmp 0x23837
xorl %eax, %eax
movl %eax, 0x31f3f9(%rip)    # 0x342d50
movl %eax, 0x31f3ef(%rip)    # 0x342d4c
jmp 0x23992
leaq 0x3188ba(%rip), %rbx    # 0x33c220
leaq 0xea019(%rip), %rsi     # 0x10d986
leaq 0x3180cc(%rip), %rdx    # 0x33ba40
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9060
movq %rbx, %rdi
callq 0x20e91
jmp 0x23992
movl $0x0, 0x31f3ba(%rip)    # 0x342d4c
movl $0x0, 0x31f3b0(%rip)    # 0x342d4c
callq 0x23ba6
testl %eax, %eax
jne 0x23769
callq 0x243e3
leaq 0x317e73(%rip), %rax    # 0x33b828
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl 0x320d57(%rip), %ebx    # 0x344718
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x318847(%rip), %rbx    # 0x33c220
leaq 0xe9fb9(%rip), %rsi     # 0x10d999
jmp 0x2396d
leaq 0x318837(%rip), %rbx    # 0x33c220
leaq 0xe9fc2(%rip), %rsi     # 0x10d9b2
jmp 0x2396d
leaq 0x318824(%rip), %rbx    # 0x33c220
leaq 0xe9fca(%rip), %rsi     # 0x10d9cd
jmp 0x2396d
cmpb $0x0, (%rbx)
je 0x23992
leaq 0x31880c(%rip), %rbx    # 0x33c220
leaq 0xe9fdc(%rip), %rsi     # 0x10d9f7
jmp 0x2396d