// File: /workspace/github_cpp_makefile_star2_O3/nompelis[P]INTecplotLib/intecplot.cpp
// Function: inTec_File::ParseComponent_HeaderVariables(char*)
int inTec_File::ParseComponent_HeaderVariables( char *buf )
{
#ifdef _DEBUG_
   printf(" i Inside \"ParseComponent_HeaderVariables\" \n");
#endif
   // make sure we had not picked up a variables line earlier
   // (this is a possibiliy, where we may have to pick a mixed number of
   // variables from the file; we will deal with this later...)
   if( variables.size() > 0 ) {
      printf(" i Encountered an extra variables line in the file \n");
      printf(" --- For now we simply ignore it and hope for the best \n");
      printf("     (We hope that the number of variables does not change!) \n");
      return(100);
      // Should the number of variables be the same as previously (very likely),
      // there will be no problem parsing other zones. But if we wanted to be
      // very general about this treatment, we would pick up the _new_ variables
      // in a new container, compare the ones that are existing ones, and have a
      // way of parsing all the new ones but maintaining only the old ones.
      // This sounds easier than it is, especially with the current framework.
   }

   size_t isize=0;
   while( buf[isize] != '\0' && buf[isize] != '\n' ) ++isize;

   char *data,*s1,*token,*sr;

   // 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';

   // first trap the equal sign
   s1 = data;
   token = strtok_r( s1, "=", &sr );
#ifdef _DEBUG3_
   printf("---> stok: |%s| \n",token);
   printf("---> data: |%s| \n",data);
#endif

   // individual variables parsing
   s1 = NULL;
#ifdef _DEBUG4_
   printf("Inner loop\n");
#endif
   for(int k=1; ; s1 = NULL, ++k) {
      token = strtok_r( s1, " ,", &sr );   // search delim either ' ' or ','
      if( token == NULL ) break;
#ifdef _DEBUG3_
      printf("---> starting inner stok: |%s| \n",token);
#endif

      if( token[0] == '\"' ) {
#ifdef _DEBUG4_
         int n=1,inum=1;
         while( token[n] != ' ' && token[n] != '\0' && token[n] != '\n' ) {
            if( token[n] == '\"' ) ++inum;
            ++n;
         }
         printf("   NUMBER OF DOUBLE-QUOTES FOUND: %d \n", inum);
         // show us where parsing stopped
      // sr[-1] = '?';   // put an actual marker
         printf("   TOKEN (temp)          -->%s<-- \n", token );
#endif
         // reset the changes...
         if( sr[-1] != '\"' )   // only in the 
            sr[-1] = ' ';       // reset farthest bound
         s1 = token;   //  s1 = &(token[1]);
#ifdef _DEBUG4_
         printf("   NEW STRING POINTER AT -->%s<-- \n", s1 );
#endif
         token = strtok_r( s1, "\"", &sr);
         if( token == NULL ) break;
//       if( token[0] == '\0' ) break;  // HACK
      }
#ifdef _DEBUG4_
      printf("Instance number %d: |%s|\n", k,token);
#endif

      // deal with string-token here...
      std::string sdum = token;
      variables.push_back( sdum );

#ifdef _DEBUG4_
printf("\n"); usleep(100000);
#endif
   }

   // drop duplicate buffer
   free( data );

   return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x3f04(%rip), %rdi      # 0xfb5b
callq 0x5570
movq 0x168(%rbx), %rax
cmpq 0x160(%rbx), %rax
je 0xbc9a
leaq 0x3f14(%rip), %rdi      # 0xfb87
callq 0x5570
leaq 0x3f3c(%rip), %rdi      # 0xfbbb
callq 0x5570
leaq 0x3f68(%rip), %rdi      # 0xfbf3
callq 0x5570
movl $0x64, %eax
jmp 0xbdc7
addq $0x160, %rbx            # imm = 0x160
xorl %r15d, %r15d
movzbl (%r14,%r15), %eax
testl %eax, %eax
je 0xbcb7
cmpl $0xa, %eax
je 0xbcb7
incq %r15
jmp 0xbca4
leaq 0x1(%r15), %rdi
callq 0x54e0
testq %rax, %rax
je 0xbdc2
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x52e0
movb $0x0, (%r12,%r15)
leaq 0x313a(%rip), %rsi      # 0xee20
leaq 0x8(%rsp), %r14
movq %r12, 0x10(%rsp)
movq %r12, %rdi
movq %r14, %rdx
callq 0x5680
leaq 0x2bdb(%rip), %rsi      # 0xe8dd
xorl %edi, %edi
movq %r14, %rdx
callq 0x5680
testq %rax, %rax
je 0xbdb4
movq %rax, %r14
leaq 0x28(%rsp), %r15
leaq 0x8(%rsp), %r13
leaq 0x18(%rsp), %rbp
leaq 0x2baf(%rip), %r12      # 0xe8dd
cmpb $0x22, (%r14)
jne 0xbd5d
movq 0x8(%rsp), %rax
cmpb $0x22, -0x1(%rax)
je 0xbd43
movb $0x20, -0x1(%rax)
movq %r14, %rdi
leaq 0x30d5(%rip), %rsi      # 0xee22
movq %r13, %rdx
callq 0x5680
movq %rax, %r14
testq %rax, %rax
je 0xbdb4
movq %r15, 0x18(%rsp)
movq %r14, %rdi
callq 0x5150
leaq (%rax,%r14), %rdx
movq %rbp, %rdi
movq %r14, %rsi
callq 0x5110
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x51b0
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0xbd9b
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5380
xorl %edi, %edi
movq %r12, %rsi
movq %r13, %rdx
callq 0x5680
movq %rax, %r14
testq %rax, %rax
jne 0xbd2e
movq 0x10(%rsp), %rdi
callq 0x5420
xorl %eax, %eax
jmp 0xbdc7
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0xbdf0
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5380
movq %rbx, %rdi
callq 0x5640