// File: alan0201tw[P]RayTracer/include/tiny_obj_loader.h
// Function: tinyobj::ParseTextureNameAndOption(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, tinyobj::texture_option_t*, char const*)
bool ParseTextureNameAndOption(std::string *texname, texture_option_t *texopt,
                               const char *linebuf) {
  // @todo { write more robust lexer and parser. }
  bool found_texname = false;
  std::string texture_name;

  const char *token = linebuf;  // Assume line ends with NULL

  while (!IS_NEW_LINE((*token))) {
    token += strspn(token, " \t");  // skip space
    if ((0 == strncmp(token, "-blendu", 7)) && IS_SPACE((token[7]))) {
      token += 8;
      texopt->blendu = parseOnOff(&token, /* default */ true);
    } else if ((0 == strncmp(token, "-blendv", 7)) && IS_SPACE((token[7]))) {
      token += 8;
      texopt->blendv = parseOnOff(&token, /* default */ true);
    } else if ((0 == strncmp(token, "-clamp", 6)) && IS_SPACE((token[6]))) {
      token += 7;
      texopt->clamp = parseOnOff(&token, /* default */ true);
    } else if ((0 == strncmp(token, "-boost", 6)) && IS_SPACE((token[6]))) {
      token += 7;
      texopt->sharpness = parseReal(&token, 1.0);
    } else if ((0 == strncmp(token, "-bm", 3)) && IS_SPACE((token[3]))) {
      token += 4;
      texopt->bump_multiplier = parseReal(&token, 1.0);
    } else if ((0 == strncmp(token, "-o", 2)) && IS_SPACE((token[2]))) {
      token += 3;
      parseReal3(&(texopt->origin_offset[0]), &(texopt->origin_offset[1]),
                 &(texopt->origin_offset[2]), &token);
    } else if ((0 == strncmp(token, "-s", 2)) && IS_SPACE((token[2]))) {
      token += 3;
      parseReal3(&(texopt->scale[0]), &(texopt->scale[1]), &(texopt->scale[2]),
                 &token, 1.0, 1.0, 1.0);
    } else if ((0 == strncmp(token, "-t", 2)) && IS_SPACE((token[2]))) {
      token += 3;
      parseReal3(&(texopt->turbulence[0]), &(texopt->turbulence[1]),
                 &(texopt->turbulence[2]), &token);
    } else if ((0 == strncmp(token, "-type", 5)) && IS_SPACE((token[5]))) {
      token += 5;
      texopt->type = parseTextureType((&token), TEXTURE_TYPE_NONE);
    } else if ((0 == strncmp(token, "-imfchan", 8)) && IS_SPACE((token[8]))) {
      token += 9;
      token += strspn(token, " \t");
      const char *end = token + strcspn(token, " \t\r");
      if ((end - token) == 1) {  // Assume one char for -imfchan
        texopt->imfchan = (*token);
      }
      token = end;
    } else if ((0 == strncmp(token, "-mm", 3)) && IS_SPACE((token[3]))) {
      token += 4;
      parseReal2(&(texopt->brightness), &(texopt->contrast), &token, 0.0, 1.0);
    } else if ((0 == strncmp(token, "-colorspace", 11)) &&
               IS_SPACE((token[11]))) {
      token += 12;
      texopt->colorspace = parseString(&token);
    } else {
// Assume texture filename
#if 0
      size_t len = strcspn(token, " \t\r");  // untile next space
      texture_name = std::string(token, token + len);
      token += len;

      token += strspn(token, " \t");  // skip space
#else
      // Read filename until line end to parse filename containing whitespace
      // TODO(syoyo): Support parsing texture option flag after the filename.
      texture_name = std::string(token);
      token += texture_name.length();
#endif

      found_texname = true;
    }
  }

  if (found_texname) {
    (*texname) = texture_name;
    return true;
  } else {
    return false;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movb $0x0, -0x21(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x7690
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0xd, %ecx
movb %al, -0xb1(%rbp)
je 0x1b5a7
movq -0x50(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0xa, %ecx
movb %al, -0xb1(%rbp)
je 0x1b5a7
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
sete %al
movb %al, -0xb1(%rbp)
movb -0xb1(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x1b5b8
jmp 0x1bc20
movq -0x50(%rbp), %rdi
leaq 0x62fdd(%rip), %rsi     # 0x7e5a0
callq 0x71d0
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
leaq 0x62fc8(%rip), %rsi     # 0x7e5a3
movl $0x7, %edx
callq 0x7240
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x1b64f
movq -0x50(%rbp), %rax
movsbl 0x7(%rax), %eax
cmpl $0x20, %eax
je 0x1b607
movq -0x50(%rbp), %rax
movsbl 0x7(%rax), %eax
cmpl $0x9, %eax
jne 0x1b64f
movq -0x50(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x50(%rbp)
leaq -0x50(%rbp), %rdi
movl $0x1, %esi
callq 0x1bc80
movb %al, -0xb2(%rbp)
jmp 0x1b629
movb -0xb2(%rbp), %cl
movq -0x18(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x36(%rax)
jmp 0x1bc1b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x1bc6a
movq -0x50(%rbp), %rdi
leaq 0x62f51(%rip), %rsi     # 0x7e5ab
movl $0x7, %edx
callq 0x7240
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x1b6bd
movq -0x50(%rbp), %rax
movsbl 0x7(%rax), %eax
cmpl $0x20, %eax
je 0x1b686
movq -0x50(%rbp), %rax
movsbl 0x7(%rax), %eax
cmpl $0x9, %eax
jne 0x1b6bd
movq -0x50(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x50(%rbp)
leaq -0x50(%rbp), %rdi
movl $0x1, %esi
callq 0x1bc80
movb %al, -0xb3(%rbp)
jmp 0x1b6a8
movb -0xb3(%rbp), %cl
movq -0x18(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x37(%rax)
jmp 0x1bc19
movq -0x50(%rbp), %rdi
leaq 0x62eeb(%rip), %rsi     # 0x7e5b3
movl $0x6, %edx
callq 0x7240
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x1b72b
movq -0x50(%rbp), %rax
movsbl 0x6(%rax), %eax
cmpl $0x20, %eax
je 0x1b6f4
movq -0x50(%rbp), %rax
movsbl 0x6(%rax), %eax
cmpl $0x9, %eax
jne 0x1b72b
movq -0x50(%rbp), %rax
addq $0x7, %rax
movq %rax, -0x50(%rbp)
leaq -0x50(%rbp), %rdi
movl $0x1, %esi
callq 0x1bc80
movb %al, -0xb4(%rbp)
jmp 0x1b716
movb -0xb4(%rbp), %cl
movq -0x18(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x34(%rax)
jmp 0x1bc17
movq -0x50(%rbp), %rdi
leaq 0x62e84(%rip), %rsi     # 0x7e5ba
movl $0x6, %edx
callq 0x7240
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x1b79f
movq -0x50(%rbp), %rax
movsbl 0x6(%rax), %eax
cmpl $0x20, %eax
je 0x1b762
movq -0x50(%rbp), %rax
movsbl 0x6(%rax), %eax
cmpl $0x9, %eax
jne 0x1b79f
movq -0x50(%rbp), %rax
addq $0x7, %rax
movq %rax, -0x50(%rbp)
leaq -0x50(%rbp), %rdi
movsd 0x62cfe(%rip), %xmm0    # 0x7e478
callq 0x1bd50
movss %xmm0, -0xb8(%rbp)
jmp 0x1b789
movss -0xb8(%rbp), %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0x4(%rax)
jmp 0x1bc15
movq -0x50(%rbp), %rdi
leaq 0x62e17(%rip), %rsi     # 0x7e5c1
movl $0x3, %edx
callq 0x7240
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x1b813
movq -0x50(%rbp), %rax
movsbl 0x3(%rax), %eax
cmpl $0x20, %eax
je 0x1b7d6
movq -0x50(%rbp), %rax
movsbl 0x3(%rax), %eax
cmpl $0x9, %eax
jne 0x1b813
movq -0x50(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x50(%rbp)
leaq -0x50(%rbp), %rdi
movsd 0x62c8a(%rip), %xmm0    # 0x7e478
callq 0x1bd50
movss %xmm0, -0xbc(%rbp)
jmp 0x1b7fd
movss -0xbc(%rbp), %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0x38(%rax)
jmp 0x1bc13
movq -0x50(%rbp), %rdi
leaq 0x62da7(%rip), %rsi     # 0x7e5c5
movl $0x2, %edx
callq 0x7240
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x1b885
movq -0x50(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x20, %eax
je 0x1b84a
movq -0x50(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x9, %eax
jne 0x1b885
movq -0x50(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rdx
movq %rdx, %rdi
addq $0x10, %rdi
movq %rdx, %rsi
addq $0x14, %rsi
addq $0x18, %rdx
leaq -0x50(%rbp), %rcx
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x1bdf0
jmp 0x1b880
jmp 0x1bc11
movq -0x50(%rbp), %rdi
leaq 0x62d38(%rip), %rsi     # 0x7e5c8
movl $0x2, %edx
callq 0x7240
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x1b8fc
movq -0x50(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x20, %eax
je 0x1b8bc
movq -0x50(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x9, %eax
jne 0x1b8fc
movq -0x50(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rdx
movq %rdx, %rdi
addq $0x1c, %rdi
movq %rdx, %rsi
addq $0x20, %rsi
addq $0x24, %rdx
leaq -0x50(%rbp), %rcx
movsd 0x62b8e(%rip), %xmm2    # 0x7e478
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x1bdf0
jmp 0x1b8f7
jmp 0x1bc0f
movq -0x50(%rbp), %rdi
leaq 0x62cc4(%rip), %rsi     # 0x7e5cb
movl $0x2, %edx
callq 0x7240
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x1b96e
movq -0x50(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x20, %eax
je 0x1b933
movq -0x50(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x9, %eax
jne 0x1b96e
movq -0x50(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rdx
movq %rdx, %rdi
addq $0x28, %rdi
movq %rdx, %rsi
addq $0x2c, %rsi
addq $0x30, %rdx
leaq -0x50(%rbp), %rcx
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x1bdf0
jmp 0x1b969
jmp 0x1bc0d
movq -0x50(%rbp), %rdi
leaq 0x62c55(%rip), %rsi     # 0x7e5ce
movl $0x5, %edx
callq 0x7240
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x1b9d5
movq -0x50(%rbp), %rax
movsbl 0x5(%rax), %eax
cmpl $0x20, %eax
je 0x1b9a5
movq -0x50(%rbp), %rax
movsbl 0x5(%rax), %eax
cmpl $0x9, %eax
jne 0x1b9d5
movq -0x50(%rbp), %rax
addq $0x5, %rax
movq %rax, -0x50(%rbp)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x1be60
movl %eax, -0xc0(%rbp)
jmp 0x1b9c4
movl -0xc0(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
jmp 0x1bc0b
movq -0x50(%rbp), %rdi
leaq 0x62bf4(%rip), %rsi     # 0x7e5d4
movl $0x8, %edx
callq 0x7240
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x1ba8b
movq -0x50(%rbp), %rax
movsbl 0x8(%rax), %eax
cmpl $0x20, %eax
je 0x1ba10
movq -0x50(%rbp), %rax
movsbl 0x8(%rax), %eax
cmpl $0x9, %eax
jne 0x1ba8b
movq -0x50(%rbp), %rax
addq $0x9, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
leaq 0x62b79(%rip), %rsi     # 0x7e5a0
callq 0x71d0
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x50(%rbp), %rdi
leaq 0x63164(%rip), %rsi     # 0x7ebae
callq 0x7060
movq %rax, %rcx
movq -0xc8(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq -0x50(%rbp), %rcx
subq %rcx, %rax
cmpq $0x1, %rax
jne 0x1ba7e
movq -0x50(%rbp), %rax
movb (%rax), %cl
movq -0x18(%rbp), %rax
movb %cl, 0x35(%rax)
movq -0x68(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x1bc09
movq -0x50(%rbp), %rdi
leaq 0x62b47(%rip), %rsi     # 0x7e5dd
movl $0x3, %edx
callq 0x7240
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x1baf8
movq -0x50(%rbp), %rax
movsbl 0x3(%rax), %eax
cmpl $0x20, %eax
je 0x1bac2
movq -0x50(%rbp), %rax
movsbl 0x3(%rax), %eax
cmpl $0x9, %eax
jne 0x1baf8
movq -0x50(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rsi
movq %rsi, %rdi
addq $0x8, %rdi
addq $0xc, %rsi
leaq -0x50(%rbp), %rdx
xorps %xmm0, %xmm0
movsd 0x6298c(%rip), %xmm1    # 0x7e478
callq 0x1c010
jmp 0x1baf3
jmp 0x1bc07
movq -0x50(%rbp), %rdi
leaq 0x62ade(%rip), %rsi     # 0x7e5e1
movl $0xb, %edx
callq 0x7240
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x1bb72
movq -0x50(%rbp), %rax
movsbl 0xb(%rax), %eax
cmpl $0x20, %eax
je 0x1bb2f
movq -0x50(%rbp), %rax
movsbl 0xb(%rax), %eax
cmpl $0x9, %eax
jne 0x1bb72
movq -0x50(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x50(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x1c060
jmp 0x1bb4d
movq -0x18(%rbp), %rdi
addq $0x40, %rdi
leaq -0x88(%rbp), %rsi
callq 0x75f0
leaq -0x88(%rbp), %rdi
callq 0x72e0
jmp 0x1bc05
movq -0x50(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0xa9(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x7870
movq -0xd8(%rbp), %rsi
movq -0xd0(%rbp), %rdx
leaq -0xa8(%rbp), %rdi
callq 0x2b020
jmp 0x1bbac
leaq -0x48(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x75f0
leaq -0xa8(%rbp), %rdi
callq 0x72e0
leaq -0xa9(%rbp), %rdi
callq 0x7560
leaq -0x48(%rbp), %rdi
callq 0x7720
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movb $0x1, -0x21(%rbp)
jmp 0x1bc05
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xa9(%rbp), %rdi
callq 0x7560
jmp 0x1bc6a
jmp 0x1bc07
jmp 0x1bc09
jmp 0x1bc0b
jmp 0x1bc0d
jmp 0x1bc0f
jmp 0x1bc11
jmp 0x1bc13
jmp 0x1bc15
jmp 0x1bc17
jmp 0x1bc19
jmp 0x1bc1b
jmp 0x1b56c
testb $0x1, -0x21(%rbp)
je 0x1bc45
movq -0x10(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x7050
jmp 0x1bc35
movb $0x1, -0x1(%rbp)
movl $0x1, -0xb0(%rbp)
jmp 0x1bc53
movb $0x0, -0x1(%rbp)
movl $0x1, -0xb0(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x72e0
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xe0, %rsp
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0x72e0
movq -0x58(%rbp), %rdi
callq 0x7860
nopl (%rax)