// File: /workspace/github_cpp_makefile_star2_O1/nompelis[P]INTecplotLib/intecplot.cpp
// Function: inTec_Zone::ParseKeywords(char*)
int inTec_Zone::ParseKeywords( char *buf )
{
#ifdef _DEBUG_
   printf(" i Parsing zone keywords \n");
#endif
   size_t isize=0;
   while( buf[isize] != '\0' && buf[isize] != '\n' ) ++isize;

   char *data;
   // create a duplicate buffer
   data = (char *) malloc(((size_t) (isize+1))*sizeof(char));
   if( data == NULL ) return(-1);

   // copy line to buffer and add termination character
   memcpy( data, buf, isize );
   data[isize] = '\0';
#ifdef _DEBUG3_
   printf("DATA: %s\n",data);
#endif

   // keep parsing for keywords and values
   int np=0;
   int ipar=0, ibra=0, iquote=0, ikey=0, ierror=0, iparse=0;
   char *s=data, *es=NULL;
   size_t n=0;
   while( n <= isize ) {
#ifdef _DEBUG2_
      printf(" (key: %d, quote: %d)  ", ikey,iquote);
      printf("  %c   s: %c   ", data[n],s[0]);
  //  printf("  %c   s: %c    (key: %d, quote: %d)  ", data[n],s[0],ikey,iquote);
#endif
      // space or comma as keyword delimeter
      if( data[n] == ' ' || data[n] == ',' ) {
         if( ikey == 0 ) {
              s = &( data[n+1] );
         } else if( ikey == 1 ) {
            if( data[n] == ',' ) { ierror = 1;printf("This is in error! (1)"); }
         } else if( ikey == 2 ) {
            if( data[n] == ',' ) { ierror = 1;printf("This is in error! (1b)");}
         } else if( ikey == 3 ) {
            if( iquote == 1 || ibra == 1 || ipar == 1 ) {
               // we continue parsing because the quote/bracket/paren. is open
            } else {
               // this terminates the keyword
               ikey = 0;
               // parsing should take place
               iparse = 1;
            }
         }

      } else 

      // equal sign
      if( data[n] == '=' ) {
         if( ikey == 0 ) {
            ierror = 1; printf("This is in error! (2)");
         } else if( ikey == 1 ) {
            // we are moving to the second stage
            es = &( data[n] );
            ikey = 2;
#ifdef _DEBUG2_
            printf(" (equal sign) ");
#endif
         } else if( ikey == 2 ) {
            ierror = 1; printf("This is in error! (2b)");
         } else if( ikey == 3 ) {
            if( iquote == 1 || ibra == 1 || ipar == 1 ) {
               // we continue parsing because the quote/bracket/paren. is open
#ifdef _DEBUG2_
               printf(" (equal sign in key=3) ");
#endif
            } else {
               ierror = 1; printf("This is in error! (3)");
            }
         }
      } else

      // double quote
      if( data[n] == '\"' ) {
         if( ikey < 2 ) {
            ierror = 1; printf("This is in error! (4) (stray quote) ");
         } else if( ikey == 2 ) {
            // entering data section of this keyword
            ikey = 3;
#ifdef _DEBUG2_
            printf(" (start data of keyword) ");
#endif
            // open quote
            iquote = 1;
         } else {
            if( data[n-1] == '\\' ) {
               // simply pick it up as a character
            } else {
               // it is a functional quote (marker)
               if( iquote == 1 ) {
                  // close the quote
                  iquote = 0;
             //   // indicate that we can parse
             //   ikey = 0;
             //   iparse = 1;
                  // let the next encounter terminate the parsing
               } else {
                  ierror = 1; printf("This is in error! (4b) (stray quote) ");
               }
            }
         }
      } else 

      // newline or null
      if( data[n] == '\n' || data[n] == '\0' ) {
         if( ikey == 3 ) {
            if( iquote == 1 || ibra == 1 || ipar == 1 ) {
               ierror = 1;printf("This is in error! (5) (unterminated quote/bracket/paren.) ");
            } else {
               ikey = 0;
               iparse = 1;
#ifdef _DEBUG2_
               printf(" (parsing ending) ");
#endif
            }
         } else if( ikey == 2 ) {
               ierror = 1; printf("This is in error! (5b) (empty keyword) ");
         } else if( ikey == 1 ) {
               ierror = 1; printf("This is in error! (5b) (empty keyword) ");
         } else {
            // termination of parsing everything
#ifdef _DEBUG2_
            printf(" (parsing ending) ");
#endif
         }
      } else 

      // open bracket
      if( data[n] == '[' ) {
         if( ikey < 2 ) {
            ierror = 1; printf("This is in error! (6) (stray bracket) ");
         } else if( ikey == 2 ) {
            // entering data section of this keyword...
            ikey = 3;
            // ...with an open bracket
            ibra = 1;
#ifdef _DEBUG2_
            printf(" (start data of keyword with bracket) ");
#endif
         } else {
            // simply open bracket
            ibra = 1;
#ifdef _DEBUG2_
            printf(" (open bracket) ");
#endif
         }
      } else 

      // close bracket
      if( data[n] == ']' ) {
         if( ikey < 3 ) {
            ierror = 1; printf("This is in error! (7a) (stray bracket) ");
         } else {
            if( ibra != 1 ) {
               ierror = 1; printf("This is in error! (7b) (stray bracket) ");
            } else {
               // simply close bracket
               ibra = 0;
#ifdef _DEBUG2_
               printf(" (close bracket) ");
#endif
            }
         }
      } else

      // open parenthesis
      if( data[n] == '(' ) {
         if( ikey < 2 ) {
            ierror = 1; printf("This is in error! (8) (stray paren.) ");
         } else if( ikey == 2 ) {
            // entering data section of this keyword...
            ikey = 3;
            // ...with an open parenthesis
            ipar = 1;
#ifdef _DEBUG2_
            printf(" (start data of keyword with paren.) ");
#endif
         } else {
            // simply open parenthesis
            ipar = 1;
#ifdef _DEBUG2_
            printf(" (open paren.) ");
#endif
         }
      } else

      // close parenthesis
      if( data[n] == ')' ) {
         if( ikey < 3 ) {
            ierror = 1; printf("This is in error! (9) (stray paren.) ");
         } else {
            if( ipar != 1 ) {
               ierror = 1; printf("This is in error! (9b) (stray paren.) ");
            } else {
               // simply close parenthesis
               ipar = 0;
#ifdef _DEBUG2_
               printf(" (close paren.) ");
#endif
            }
         }
      } else

      // anything else
      {
         if( ikey == 0 ) {
            // check whether we are in a line of data
            if( CheckCharForNum( data[n] ) == 1 ) {
               // terminate parsing immediately; the zone header must be done
               free( data );
#ifdef _DEBUG2_
               printf(" (numerical string) \n");
#endif
               return( -100 );
            }

            // encountered keyword
            ikey = 1;
#ifdef _DEBUG2_
            printf(" (start keyword) ");
#endif
         } else if( ikey == 2 ) {
            // entering data section of this keyword
            ikey = 3;
#ifdef _DEBUG2_
            printf(" (start data of keyword) ");
#endif
         }
      }

      // provide some output
      if( iparse == 1 ) {
#ifdef _DEBUG2_
         printf(" (parsing now)");
#endif
         data[n+0] = '\0';//HACK

         int iret = HandleKeyword( s );
         // allow for the possibility of dealiing with this differently...
         if( iret == 0 ) ++np;

         iparse = 0;
      }

      ++n;
#ifdef _DEBUG2_
      printf("\n");
#endif
   }

   // drop duplicate buffer
   free( data );

   if( ierror == 0 ) {
      return( np );
   } else {
#ifdef _DEBUG_
      printf(" --- Error returned: %d \n", -10*ierror );
#endif
      return( -10*ierror );
   }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r12
movq %rdi, 0x20(%rsp)
leaq 0x8a90(%rip), %rdi      # 0xf0bf
callq 0x5580
xorl %r14d, %r14d
movzbl (%r12,%r14), %eax
testl %eax, %eax
je 0x664a
cmpl $0xa, %eax
je 0x664a
incq %r14
jmp 0x6637
leaq 0x1(%r14), %rdi
callq 0x54f0
testq %rax, %rax
je 0x6ac0
movq %rax, %r15
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x52f0
movb $0x0, (%r15,%r14)
xorl %r12d, %r12d
movq %r15, 0x18(%rsp)
movl $0x0, 0x8(%rsp)
xorl %ebx, %ebx
movl $0x0, 0xc(%rsp)
movl $0x0, 0x10(%rsp)
movl $0x0, 0x14(%rsp)
xorl %r13d, %r13d
movzbl (%r15,%r12), %eax
cmpl $0x2b, %eax
jg 0x66d8
leal -0x20(%rax), %ecx
cmpl $0x9, %ecx
ja 0x671c
leaq 0x7974(%rip), %rdx      # 0xe02c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
cmpl $0x1, %ebx
jg 0x6846
xorl %ebp, %ebp
leaq 0x7bf6(%rip), %rdi      # 0xe2c9
jmp 0x68d9
cmpl $0x5a, %eax
jg 0x678a
cmpl $0x2c, %eax
je 0x67af
cmpl $0x3d, %eax
jne 0x67dd
cmpl $0x3, %ebx
ja 0x69e9
movl %ebx, %eax
leaq 0x794f(%rip), %rcx      # 0xe054
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %ebx, %ebx
leaq 0x7b6f(%rip), %rdi      # 0xe286
jmp 0x69ac
testl %eax, %eax
je 0x6729
cmpl $0xa, %eax
jne 0x67dd
cmpl $0x1, %ebx
je 0x68b7
cmpl $0x2, %ebx
je 0x68a9
cmpl $0x3, %ebx
jne 0x69e9
cmpl $0x1, 0xc(%rsp)
sete %al
cmpl $0x1, 0x10(%rsp)
sete %cl
orb %al, %cl
cmpl $0x1, 0x14(%rsp)
sete %al
orb %cl, %al
cmpb $0x1, %al
jne 0x69bd
xorl %ebp, %ebp
leaq 0x7ba3(%rip), %rdi      # 0xe314
xorl %eax, %eax
callq 0x5060
movl $0x1, 0x8(%rsp)
movl $0x3, %ebx
jmp 0x69eb
cmpl $0x5b, %eax
je 0x681b
cmpl $0x5d, %eax
jne 0x67dd
xorl %ebp, %ebp
cmpl $0x2, %ebx
jg 0x6879
leaq 0x7bf4(%rip), %rdi      # 0xe39e
jmp 0x68d9
cmpl $0x3, %ebx
ja 0x69e9
movl %ebx, %ecx
leaq 0x78a3(%rip), %rdx      # 0xe064
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
leaq (%r15,%r12), %rax
incq %rax
movq %rax, 0x18(%rsp)
xorl %ebx, %ebx
jmp 0x69e9
testl %ebx, %ebx
je 0x693b
cmpl $0x2, %ebx
movl $0x3, %eax
cmovel %eax, %ebx
jmp 0x69e9
cmpl $0x1, %ebx
jg 0x682e
xorl %ebp, %ebp
leaq 0x7beb(%rip), %rdi      # 0xe3ee
jmp 0x68d9
xorl %ebp, %ebp
cmpl $0x2, %ebx
jg 0x6861
leaq 0x7bfe(%rip), %rdi      # 0xe414
jmp 0x68d9
cmpl $0x1, %ebx
jg 0x6891
xorl %ebp, %ebp
leaq 0x7b4e(%rip), %rdi      # 0xe377
jmp 0x68d9
cmpl $0x2, %ebx
movl $0x3, %eax
cmovel %eax, %ebx
movl $0x1, 0x14(%rsp)
jmp 0x69e9
cmpl $0x2, %ebx
jne 0x6966
movl $0x3, %ebx
movl $0x1, 0xc(%rsp)
jmp 0x69e9
cmpl $0x1, 0x14(%rsp)
jne 0x698c
movl $0x0, 0x14(%rsp)
jmp 0x69eb
cmpl $0x1, 0x10(%rsp)
jne 0x699d
movl $0x0, 0x10(%rsp)
jmp 0x69eb
cmpl $0x2, %ebx
movl $0x3, %eax
cmovel %eax, %ebx
movl $0x1, 0x10(%rsp)
jmp 0x69e9
xorl %ebp, %ebp
leaq 0x7a9d(%rip), %rdi      # 0xe34f
jmp 0x6a21
xorl %ebp, %ebp
leaq 0x7a8f(%rip), %rdi      # 0xe34f
jmp 0x692d
movl $0x2, %ebx
cmpl $0x2c, %eax
jne 0x69e9
xorl %ebp, %ebp
leaq 0x7996(%rip), %rdi      # 0xe26f
xorl %eax, %eax
callq 0x5060
movl $0x1, 0x8(%rsp)
jmp 0x69eb
cmpl $0x1, 0xc(%rsp)
sete %al
cmpl $0x1, 0x10(%rsp)
sete %cl
orb %al, %cl
cmpl $0x1, 0x14(%rsp)
sete %al
xorl %ebx, %ebx
orb %cl, %al
je 0x69dc
movl $0x3, %ebx
jmp 0x69e9
cmpl $0x2c, %eax
jne 0x69e4
xorl %ebp, %ebp
leaq 0x792c(%rip), %rdi      # 0xe259
xorl %eax, %eax
callq 0x5060
movl $0x1, %ebx
jmp 0x68e0
movl $0x1, %ebx
xorl %ebp, %ebp
cmpl $0x39, %eax
ja 0x69eb
movl %eax, %eax
movabsq $0x3ff680000000000, %rcx # imm = 0x3FF680000000000
btq %rax, %rcx
jae 0x69eb
jmp 0x6ac8
xorl %ebp, %ebp
cmpb $0x5c, -0x1(%r15,%r12)
je 0x69eb
cmpl $0x1, 0xc(%rsp)
je 0x6a7d
movl $0x0, 0xc(%rsp)
leaq 0x7964(%rip), %rdi      # 0xe2ee
jmp 0x69ac
movl $0x0, 0x14(%rsp)
leaq 0x7a9f(%rip), %rdi      # 0xe43a
jmp 0x69ac
movl $0x0, 0x10(%rsp)
leaq 0x7a1a(%rip), %rdi      # 0xe3c6
xorl %eax, %eax
callq 0x5060
movl $0x1, 0x8(%rsp)
jmp 0x69e9
movb $0x1, %bpl
movl $0x0, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
xorl %ebx, %ebx
jmp 0x69eb
movb $0x1, %bpl
jmp 0x6a6d
movl $0x1, %ebx
xorl %ebp, %ebp
testb %bpl, %bpl
je 0x6a0a
movb $0x0, (%r15,%r12)
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x5470
xorl $0x1, %eax
addl %eax, %r13d
incq %r12
cmpq %r14, %r12
jbe 0x669f
jmp 0x6a96
xorl %ebp, %ebp
leaq 0x787b(%rip), %rdi      # 0xe29c
xorl %eax, %eax
callq 0x5060
movl $0x1, 0x8(%rsp)
jmp 0x6a8c
cmpl $0x1, 0xc(%rsp)
sete %al
cmpl $0x1, 0x10(%rsp)
sete %cl
orb %al, %cl
cmpl $0x1, 0x14(%rsp)
sete %al
xorl %ebp, %ebp
orb %cl, %al
movl $0x3, %ebx
jne 0x69eb
leaq 0x7855(%rip), %rdi      # 0xe2b3
xorl %eax, %eax
callq 0x5060
movl $0x1, 0x8(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
jmp 0x69eb
xorl %ebp, %ebp
movl $0x2, %ebx
jmp 0x69eb
movq %r15, %rdi
callq 0x5430
cmpl $0x0, 0x8(%rsp)
je 0x6ad6
leaq 0x79b5(%rip), %rdi      # 0xe461
movl $0xfffffff6, %r13d      # imm = 0xFFFFFFF6
movl $0xfffffff6, %esi       # imm = 0xFFFFFFF6
xorl %eax, %eax
callq 0x5060
jmp 0x6ad6
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x6ad6
movq %r15, %rdi
callq 0x5430
movl $0xffffff9c, %r13d      # imm = 0xFFFFFF9C
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq