// File: /workspace/github_cpp_makefile_star2_O3/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 0x1f7daf(%rip), %r15    # 0x21b228
cmpl $0x3e7, (%r15)          # imm = 0x3E7
jne 0x2348f
leaq 0x3183a3(%rip), %rax    # 0x33b82c
movl $0x1, (%rax)
movl $0x0, 0x31f8b7(%rip)    # 0x342d50
leaq 0x31be40(%rip), %rax    # 0x33f2e0
cmpb $0x0, (%rax)
je 0x234fc
leaq 0x31837c(%rip), %rax    # 0x33b828
movl $0x1, (%rax)
callq 0x72683
leaq 0x31be22(%rip), %rbx    # 0x33f2e0
movq %rbx, %rdi
callq 0x986c
leaq 0x318363(%rip), %rdi    # 0x33b830
movq %rbx, %rsi
callq 0x9340
leaq 0x318768(%rip), %rax    # 0x33bc44
movl $0x0, (%rax)
leaq 0xea52e(%rip), %rsi     # 0x10da17
movq %rbx, %rdi
callq 0x9090
testq %rax, %rax
jne 0x23767
jmp 0x2352d
leaq 0x2e92a5(%rip), %rax    # 0x30c7a8
cmpb $0x0, (%rax)
je 0x2350d
callq 0x238a8
leaq 0x318314(%rip), %rax    # 0x33b828
xorl %ebx, %ebx
movl %ebx, (%rax)
callq 0x72683
callq 0x23977
movl %ebx, 0x3211f0(%rip)    # 0x344718
jmp 0x23796
leaq 0x31850c(%rip), %rbx    # 0x33ba40
movb $0x0, (%rbx)
callq 0x810b1
testl %eax, %eax
je 0x23767
xorl %r13d, %r13d
leaq 0x3182de(%rip), %r12    # 0x33b82c
leaq 0x2(%rbx), %r14
movzwl (%rbx), %eax
cmpw $0x3f, %ax
je 0x2356b
cmpl $0x3e7, (%r15)          # imm = 0x3E7
jne 0x2356b
movl %r13d, (%r15)
movl %r13d, (%r12)
cmpl $0x0, 0x31f7de(%rip)    # 0x342d50
jne 0x23734
movl 0x31f7ce(%rip), %ecx    # 0x342d4c
cmpl $0x2, %ecx
jl 0x2358d
decl %ecx
movl %ecx, 0x31f7c1(%rip)    # 0x342d4c
jmp 0x235a6
cmpl $0x1, %ecx
jne 0x2359e
movl $0x0, 0x31f7b0(%rip)    # 0x342d4c
jmp 0x235f8
testl %ecx, %ecx
js 0x23767
cmpb $0x2e, %al
setne %dl
movzwl %ax, %ecx
cmpl $0x100, %ecx            # imm = 0x100
setb %sil
orb %dl, %sil
je 0x235e3
cmpl $0x100, %ecx            # imm = 0x100
setb %dl
cmpb $0x2b, %al
setne %sil
orb %dl, %sil
je 0x235e3
cmpl $0x100, %ecx            # imm = 0x100
setb %cl
cmpb $0x2d, %al
setne %dl
orb %cl, %dl
jne 0x2360a
movq %rbx, %rdi
callq 0x24709
testl %eax, %eax
je 0x23740
callq 0x24800
callq 0x810b1
testl %eax, %eax
jne 0x23552
jmp 0x23767
movsbl %al, %ecx
addl $-0x30, %ecx
cmpl $0x9, %ecx
ja 0x23641
movl %eax, %ecx
shrl $0x8, %ecx
cmpb $0x30, %al
setne %dl
cmpw $0x78, %cx
setne %sil
orb %dl, %sil
jne 0x236ca
movq %r14, %rdi
callq 0x24604
testl %eax, %eax
jne 0x235f3
jmp 0x237a7
callq 0x2498e
testl %eax, %eax
jne 0x235f8
callq 0x254b5
testl %eax, %eax
jne 0x235f8
movzwl (%rbx), %eax
cmpw $0x3f, %ax
je 0x2371a
movl (%rbx), %ecx
movl $0x706c6568, %edx       # imm = 0x706C6568
xorl %edx, %ecx
movzbl 0x4(%rbx), %edx
orl %ecx, %edx
je 0x2371a
movq (%rbx), %rcx
movabsq $0x73666564776f6873, %rdx # imm = 0x73666564776F6873
xorq %rdx, %rcx
movzbl 0x8(%rbx), %edx
orq %rcx, %rdx
je 0x23727
movl (%rbx), %ecx
movl $0x6d6f6f7a, %edx       # imm = 0x6D6F6F7A
xorl %edx, %ecx
movzbl 0x4(%rbx), %edx
orl %ecx, %edx
jne 0x237da
movl $0x1b, %edi
callq 0xd4c8
movl $0x7a, %edi
callq 0xd4c8
movl $0x60, %edi
callq 0xd4c8
jmp 0x235f8
cmpb $0x30, %al
setne %dl
cmpw $0x6f, %cx
setne %sil
orb %dl, %sil
jne 0x236f1
movq %r14, %rdi
callq 0x24667
testl %eax, %eax
jne 0x235f3
jmp 0x237b7
cmpb $0x30, %al
setne %al
cmpw $0x62, %cx
setne %cl
orb %al, %cl
jne 0x235e3
movq %r14, %rdi
callq 0x246b8
testl %eax, %eax
jne 0x235f3
jmp 0x237c7
movl $0x1, (%r12)
jmp 0x235f8
movl $0x2, (%r12)
jmp 0x235f8
movl $0x0, 0x31f612(%rip)    # 0x342d50
jmp 0x23767
leaq 0x318ad9(%rip), %rbx    # 0x33c220
leaq 0xea2cc(%rip), %rsi     # 0x10da1a
leaq 0x3182eb(%rip), %rdx    # 0x33ba40
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9060
movq %rbx, %rdi
callq 0x20e5c
movl $0x0, 0x31f5db(%rip)    # 0x342d4c
callq 0x23977
testl %eax, %eax
jne 0x2352d
callq 0x241f6
leaq 0x31809e(%rip), %rax    # 0x33b828
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl 0x320f82(%rip), %ebx    # 0x344718
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x318a72(%rip), %rbx    # 0x33c220
leaq 0xea278(%rip), %rsi     # 0x10da2d
jmp 0x2374e
leaq 0x318a62(%rip), %rbx    # 0x33c220
leaq 0xea281(%rip), %rsi     # 0x10da46
jmp 0x2374e
leaq 0x318a52(%rip), %rbx    # 0x33c220
leaq 0xea28c(%rip), %rsi     # 0x10da61
jmp 0x2374e
testb %al, %al
je 0x23767
leaq 0x318a3b(%rip), %rbx    # 0x33c220
leaq 0xea29f(%rip), %rsi     # 0x10da8b
jmp 0x2374e