// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathui.cpp
// Function: rpn_define(int)
int rpn_define(int skip_first)
{
int i, j;
int def_col;
char *s;
int old_mode;

   // create a user define command

   if(num_rpn_defs >= MAX_RPN_DEFS) {
      edit_error("Too many DEFINE commands seen!");
      return 1;
   }
   old_mode = rpn_mode;
   rpn_mode = 1;   // make sure get_msg_field() works

   def_col = msg_col;
   rpn_break = 1;
   if(skip_first) {
      get_msg_field();
      def_col = msg_col;
   }

   if(get_msg_field()) {
      if(!isalpha(msg_field[0])) {
         edit_error("DEFINE name must start with a letter!");
         rpn_mode = old_mode;
         return 2;
      }
      if(!strcmp(msg_field, "define")) {
         edit_error("Cannot re-define the DEFINE command!");
         rpn_mode = old_mode;
         return 22;
      }

      i = find_rpn_def(msg_field);
      if(i >= 0) {  // redefine
         if(rpn_defs[i]) {      // delete old define
            free(rpn_defs[i]);
            rpn_defs[i] = 0;
         }
         if(num_rpn_defs) {
            for(j=i; j<num_rpn_defs; j++) {
               rpn_defs[j] = rpn_defs[j+1];
            }
            --num_rpn_defs;
         }
         if(nmea_msg[msg_col]) {
            goto do_define;
         }
      }
      else if(i == (-1)) {  // new define
         do_define:
         if(nmea_msg[msg_col]) {
            s = (char *) (void *) calloc(strlen(&nmea_msg[def_col])+1, sizeof(char));
            if(s) {
               strcpy(s, &nmea_msg[def_col]);
               if(s[0] == 0) strcat(s, " ");
               rpn_defs[num_rpn_defs] = s;
               ++num_rpn_defs;
            }
            else {
               edit_error("Could not allocate DEFINE memory!");
               rpn_mode = old_mode;
               return 4;
            }
         }
         else {
            edit_error("No operations specified for DEFINE!");
            rpn_mode = old_mode;
            return 7;
         }
      }
      else {
         rpn_mode = old_mode;
         return 5;  // should never happen
      }
   }
   else {
      edit_error("DEFINE name missing!");
      rpn_mode = old_mode;
      return 6;
   }

   rpn_mode = old_mode;
   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpl $0x64, 0x320275(%rip)   # 0x343088
jl 0x22e2b
leaq 0xea800(%rip), %rdi     # 0x10d61c
callq 0x23027
movl $0x1, %eax
jmp 0x23018
leaq 0x3189f6(%rip), %r15    # 0x33b828
movl (%r15), %r12d
movl $0x1, %eax
movl %eax, (%r15)
leaq 0x318e00(%rip), %r13    # 0x33bc44
movl (%r13), %r14d
movl %eax, 0x31ff02(%rip)    # 0x342d50
testl %edi, %edi
je 0x22e5b
callq 0x810b1
movl (%r13), %r14d
callq 0x810b1
testl %eax, %eax
je 0x22f88
leaq 0x318bd1(%rip), %rbx    # 0x33ba40
movsbl (%rbx), %edi
callq 0x9640
testl %eax, %eax
je 0x22f9e
movl $0x69666564, %eax       # imm = 0x69666564
xorl (%rbx), %eax
movl $0x656e69, %ecx         # imm = 0x656E69
xorl 0x3(%rbx), %ecx
orl %eax, %ecx
je 0x22fb4
leaq 0x318ba3(%rip), %rdi    # 0x33ba40
callq 0x22d88
movl %eax, %ebx
testl %eax, %eax
js 0x22fca
movl %ebx, %r15d
leaq 0x31feaa(%rip), %rcx    # 0x342d60
movq (%rcx,%r15,8), %rdi
testq %rdi, %rdi
je 0x22ed3
callq 0x9440
leaq 0x31fe95(%rip), %rcx    # 0x342d60
movq $0x0, (%rcx,%r15,8)
movl 0x3201af(%rip), %eax    # 0x343088
testl %eax, %eax
je 0x22f02
cmpl %eax, %ebx
jge 0x22efa
leaq (%rcx,%r15,8), %rcx
addq $0x8, %rcx
movq (%rcx), %rdx
movq %rdx, -0x8(%rcx)
addq $0x8, %rcx
incl %ebx
cmpl %ebx, %eax
jg 0x22ee9
decl %eax
movl %eax, 0x320186(%rip)    # 0x343088
movslq (%r13), %rax
leaq 0x318923(%rip), %rcx    # 0x33b830
cmpb $0x0, (%rcx,%rax)
leaq 0x318910(%rip), %r15    # 0x33b828
je 0x22f7e
movslq %r14d, %r14
addq 0x12cf5c(%rip), %r14    # 0x14fe80
movq %r14, %rdi
callq 0x9120
leaq 0x1(%rax), %rdi
movl $0x1, %esi
callq 0x9230
testq %rax, %rax
je 0x22fd9
movq %rax, %rbx
movq %rax, %rdi
movq %r14, %rsi
callq 0x9340
cmpb $0x0, (%rbx)
jne 0x22f64
movq %rbx, %rdi
callq 0x9120
movw $0x20, (%rbx,%rax)
movslq 0x32011d(%rip), %rax    # 0x343088
leaq 0x31fdee(%rip), %rcx    # 0x342d60
movq %rbx, (%rcx,%rax,8)
incl %eax
movl %eax, 0x32010a(%rip)    # 0x343088
movl %r12d, (%r15)
xorl %eax, %eax
jmp 0x23018
leaq 0xea744(%rip), %rdi     # 0x10d6d3
callq 0x23027
movl %r12d, (%r15)
movl $0x6, %eax
jmp 0x23018
leaq 0xea696(%rip), %rdi     # 0x10d63b
callq 0x23027
movl %r12d, (%r15)
movl $0x2, %eax
jmp 0x23018
leaq 0xea6ad(%rip), %rdi     # 0x10d668
callq 0x23027
movl %r12d, (%r15)
movl $0x16, %eax
jmp 0x23018
cmpl $-0x1, %ebx
je 0x22fef
movl %r12d, (%r15)
movl $0x5, %eax
jmp 0x23018
leaq 0xea6ad(%rip), %rdi     # 0x10d68d
callq 0x23027
movl %r12d, (%r15)
movl $0x4, %eax
jmp 0x23018
movslq (%r13), %rax
leaq 0x318836(%rip), %rcx    # 0x33b830
cmpb $0x0, (%rcx,%rax)
jne 0x22f1a
leaq 0xea6a4(%rip), %rdi     # 0x10d6af
callq 0x23027
movl %r12d, (%r15)
movl $0x7, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq