// File: /workspace/github_cpp_makefile_star2_O2/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 0x7a0c(%rip), %rdi      # 0x10157
callq 0x77b0
xorl %r14d, %r14d
movzbl (%r12,%r14), %eax
testl %eax, %eax
je 0x8766
cmpl $0xa, %eax
je 0x8766
incq %r14
jmp 0x8753
leaq 0x1(%r14), %rdi
callq 0x76e0
testq %rax, %rax
je 0x8b66
movq %rax, %rbp
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x73e0
movb $0x0, (%rbp,%r14)
movq %rbp, %r15
incq %r15
leaq 0x68c0(%rip), %r12      # 0xf05c
movl $0x0, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0x4(%rsp)
movl $0x0, (%rsp)
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %rbp, 0x10(%rsp)
movq %rbp, 0x18(%rsp)
xorl %ebp, %ebp
cmpq %r14, %rbp
ja 0x8b3f
movzbl -0x1(%r15), %eax
leal -0x20(%rax), %edx
movl %r13d, %ecx
cmpl $0x9, %edx
jbe 0x8814
testl %eax, %eax
je 0x8844
cmpl $0xa, %eax
je 0x8844
cmpl $0x5d, %eax
je 0x88f6
cmpl $0x3d, %eax
je 0x8922
cmpl $0x5b, %eax
je 0x890c
cmpl $0x2c, %eax
jne 0x889b
jmp 0x881d
movslq (%r12,%rdx,4), %rdx
addq %r12, %rdx
jmpq *%rdx
cmpl $0x3, %r13d
ja 0x8b34
leaq 0x6866(%rip), %rdx      # 0xf094
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
xorl %r13d, %r13d
movq %r15, 0x18(%rsp)
jmp 0x8b34
cmpl $0x1, %r13d
je 0x89d5
cmpl $0x2, %r13d
je 0x89c9
cmpl $0x3, %r13d
jne 0x8b34
cmpl $0x1, (%rsp)
sete %al
cmpl $0x1, 0x4(%rsp)
sete %cl
orb %al, %cl
cmpl $0x1, 0x8(%rsp)
sete %al
orb %cl, %al
cmpb $0x1, %al
jne 0x8a14
leaq 0x6b20(%rip), %rdi      # 0xf3ac
xorl %eax, %eax
callq 0x7060
pushq $0x1
popq %rbx
jmp 0x8af5
testl %r13d, %r13d
je 0x8a6d
cmpl $0x2, %r13d
pushq $0x3
popq %rax
cmovel %eax, %r13d
jmp 0x8b34
cmpl $0x2, %r13d
jg 0x894b
leaq 0x6be7(%rip), %rdi      # 0xf4ac
jmp 0x8b2a
cmpl $0x1, %r13d
jg 0x896a
leaq 0x6a86(%rip), %rdi      # 0xf361
jmp 0x8b2a
cmpl $0x1, %r13d
jg 0x8983
leaq 0x6b95(%rip), %rdi      # 0xf486
jmp 0x8b2a
cmpl $0x2, %r13d
jg 0x899a
leaq 0x6b2f(%rip), %rdi      # 0xf436
jmp 0x8b2a
cmpl $0x1, %r13d
jg 0x89b2
leaq 0x6af2(%rip), %rdi      # 0xf40f
jmp 0x8b2a
cmpl $0x3, %r13d
ja 0x8b34
leaq 0x6751(%rip), %rdx      # 0xf084
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
xorl %r13d, %r13d
leaq 0x69d8(%rip), %rdi      # 0xf31e
jmp 0x8b2a
cmpl $0x1, 0x8(%rsp)
je 0x8a41
movl $0x0, 0x8(%rsp)
leaq 0x6b6d(%rip), %rdi      # 0xf4d2
jmp 0x8b2a
cmpl $0x2, %r13d
jne 0x8a95
pushq $0x3
popq %r13
pushq $0x1
popq %rax
movl %eax, (%rsp)
jmp 0x8b34
cmpl $0x2, %r13d
pushq $0x3
popq %rax
cmovel %eax, %r13d
pushq $0x1
popq %rax
movl %eax, 0x8(%rsp)
jmp 0x8b34
cmpl $0x1, 0x4(%rsp)
jne 0x8ab2
movl $0x0, 0x4(%rsp)
jmp 0x8b34
cmpl $0x2, %r13d
pushq $0x3
popq %rax
cmovel %eax, %r13d
pushq $0x1
popq %rax
movl %eax, 0x4(%rsp)
jmp 0x8b34
leaq 0x6a17(%rip), %rdi      # 0xf3e7
jmp 0x8aca
leaq 0x6a0b(%rip), %rdi      # 0xf3e7
jmp 0x8a5a
cmpl $0x2c, %eax
jne 0x8ad4
leaq 0x6919(%rip), %rdi      # 0xf307
jmp 0x8aca
cmpl $0x1, (%rsp)
sete %al
cmpl $0x1, 0x4(%rsp)
sete %cl
orb %al, %cl
cmpl $0x1, 0x8(%rsp)
sete %al
orb %cl, %al
jne 0x8af5
movb $0x0, -0x1(%r15)
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x7610
xorl $0x1, %eax
addl %eax, 0xc(%rsp)
xorl %r13d, %r13d
movl $0x0, (%rsp)
movl $0x0, 0x4(%rsp)
movl $0x0, 0x8(%rsp)
jmp 0x8b34
cmpl $0x2c, %eax
jne 0x8a91
leaq 0x6897(%rip), %rdi      # 0xf2f1
xorl %eax, %eax
callq 0x7060
pushq $0x1
popq %r13
movl %r13d, %ebx
jmp 0x8b34
cmpl $0x39, %eax
ja 0x8a91
movl %eax, %eax
movabsq $0x3ff680000000000, %rcx # imm = 0x3FF680000000000
btq %rax, %rcx
pushq $0x1
popq %r13
jae 0x8b34
jmp 0x8b6a
pushq $0x1
jmp 0x8af7
cmpb $0x5c, -0x2(%r15)
je 0x8b34
cmpl $0x1, (%rsp)
jne 0x8b1c
movl $0x0, (%rsp)
jmp 0x8b34
movl $0x0, 0x4(%rsp)
leaq 0x699d(%rip), %rdi      # 0xf45e
jmp 0x8b2a
leaq 0x686a(%rip), %rdi      # 0xf334
xorl %eax, %eax
callq 0x7060
pushq $0x1
popq %rbx
pushq $0x2
jmp 0x8af7
cmpl $0x1, (%rsp)
sete %al
cmpl $0x1, 0x4(%rsp)
sete %cl
orb %al, %cl
cmpl $0x1, 0x8(%rsp)
sete %al
orb %cl, %al
je 0x8afb
pushq $0x3
popq %r13
jmp 0x8b34
movl $0x0, (%rsp)
leaq 0x6842(%rip), %rdi      # 0xf34b
xorl %eax, %eax
callq 0x7060
pushq $0x1
popq %rbx
pushq $0x3
popq %r13
jmp 0x8a39
movl $0x0, (%rsp)
leaq 0x685c(%rip), %rdi      # 0xf386
xorl %eax, %eax
callq 0x7060
pushq $0x1
popq %rbx
incq %rbp
incq %r15
jmp 0x87cc
movq 0x10(%rsp), %rdi
callq 0x75c0
testl %ebx, %ebx
movl 0xc(%rsp), %ebx
je 0x8b77
leaq 0x69a1(%rip), %rdi      # 0xf4f9
pushq $-0xa
popq %rbx
movl %ebx, %esi
xorl %eax, %eax
callq 0x7060
jmp 0x8b77
pushq $-0x1
jmp 0x8b76
movq 0x10(%rsp), %rdi
callq 0x75c0
pushq $-0x64
popq %rbx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq