// File: /workspace/github_c_makefile_star2_O1/takoeight0821[P]hoc_nyan/src/token.c
// Function: next_token
static Token* next_token(void) {
  if (*cur == '\0') {
    return NULL;
  }

  if (start_with("/*", cur)) {
    while (!start_with("*/", cur)) {
      consume();
    }
    consume();
    consume();
    return next_token();
  }

  if (start_with("//", cur)) {
    consume();
    consume();
    while (*cur != '\n') {
      consume();
    }
    return next_token();
  }

  if (bol && *cur == '#') {
    consume();
    if (start_with("define", cur)) {
      Token* token = new_token(TDIRECTIVE, cur);
      token->bol = true;
      cur += strlen("define");
      token->ident = "define";
      return token;
    } else if (start_with("include", cur)) {
      Token* token = new_token(TDIRECTIVE, cur);
      token->bol = true;
      cur += strlen("include");
      token->ident = "include";
      whitespace();
      token->str = read_include_path();
      return token;
    } else if (start_with("ifdef", cur)) {
      Token* token = new_token(TDIRECTIVE, cur);
      token->bol = true;
      cur += strlen("ifdef");
      token->ident = "ifdef";
      return token;
    } else if (start_with("ifndef", cur)) {
      Token* token = new_token(TDIRECTIVE, cur);
      token->bol = true;
      cur += strlen("ifndef");
      token->ident = "ifndef";
      return token;
    } else if (start_with("endif", cur)) {
      Token* token = new_token(TDIRECTIVE, cur);
      token->bol = true;
      cur += strlen("endif");
      token->ident = "endif";
      return token;
    } else {
      print_line(src, cur);
      error("invalid preprocessing directive\n");
    }
  } else if (*cur == '#') {
    print_line(src, cur);
    error("invalid #\n");
  }

  if (strchr(" \t\n\r", *cur)) {
    whitespace();
    return next_token();
  }

  if (strchr("0123456789", *cur)) {
    return integer(cur);
  }

  for (int i = 0; i < (sizeof(punctuators) / sizeof(char*)); i++) {
    if (start_with(punctuators[i], cur)) {
      Token* t = new_reserved(cur, punctuators[i]);
      cur += strlen(punctuators[i]);
      return t;
    }
  }

  for (int i = 0; i < (sizeof(keywords) / sizeof(char*)); i++) {
    if (start_with(keywords[i], cur)) {
      Token* t = new_reserved(cur, keywords[i]);
      cur += strlen(keywords[i]);
      if (isalnum(*cur) || *cur == '_') {
        cur -= strlen(keywords[i]);
      } else {
        return t;
      }
    }
  }

  if ('\"' == *cur) {
    char* start = cur;
    consume();
    StringBuilder* sb = new_sb();
    while (*cur != '\"') {
      sb_putc(sb, read_char());
    }
    consume();
    Token* tok = new_token(TSTRING, start);
    tok->str = sb_run(sb);
    return tok;
  }

  if ('\'' == *cur) {
    consume();
    Token* t = new_token(TINT, cur - 1);
    t->integer = read_char();
    if (*cur != '\'') {
      print_line(src, cur);
      error("expected ' but actual %c\n", *cur);
    }
    consume();
    return t;
  }

  if (isalpha(*cur) || *cur == '_') {
    return ident(cur);
  }

  print_line(src, cur);
  error("invalid character: %c\n", *cur);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x25c7(%rip), %rbp      # 0xf4d1
leaq 0x25bd(%rip), %rbx      # 0xf4ce
leaq 0x25bc(%rip), %r15      # 0xf4d4
movabsq $0x100002600, %r13      # imm = 0x100002600
movq 0x628f(%rip), %r14      # 0x131b8
movsbl (%r14), %r12d
testl %r12d, %r12d
je 0xd032
movslq %r12d, %rsi
movb $0x2f, %cl
xorl %eax, %eax
movb (%r14,%rax), %dl
testb %dl, %dl
je 0xcf56
cmpb %dl, %cl
jne 0xcf91
movb 0x1(%rax,%rbx), %cl
incq %rax
cmpq $0x2, %rax
jne 0xcf3d
movb $0x2a, %cl
movq 0x6259(%rip), %rax      # 0x131b8
xorl %edx, %edx
movb (%rax,%rdx), %sil
testb %sil, %sil
je 0xcf85
cmpb %sil, %cl
jne 0xcf7e
movb 0x1(%rdx,%rbp), %cl
incq %rdx
cmpq $0x2, %rdx
jne 0xcf61
jmp 0xcf85
callq 0xd7ac
jmp 0xcf56
callq 0xd7ac
callq 0xd7ac
jmp 0xcf22
movb $0x2f, %cl
xorl %eax, %eax
movb (%r14,%rax), %dl
testb %dl, %dl
je 0xcfaf
cmpb %dl, %cl
jne 0xcfca
movb 0x1(%rax,%r15), %cl
incq %rax
cmpq $0x2, %rax
jne 0xcf95
callq 0xd7ac
callq 0xd7ac
movq 0x61f8(%rip), %rax      # 0x131b8
cmpb $0xa, (%rax)
jne 0xcfb4
jmp 0xcf22
movb 0x61f0(%rip), %cl       # 0x131c0
cmpb $0x23, %r12b
setne %al
orb %cl, %al
testb $0x1, %al
je 0xd046
movb %cl, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
cmpb $0x23, %r12b
je 0xd536
movl $0x5, %edx
leaq 0x2507(%rip), %rdi      # 0xf503
movl %r12d, %esi
callq 0x20e0
testq %rax, %rax
je 0xd0ba
movq 0x61a4(%rip), %rax      # 0x131b8
movzbl (%rax), %eax
cmpq $0x20, %rax
ja 0xcf22
btq %rax, %r13
jae 0xcf22
callq 0xd7ac
jmp 0xd00d
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xd7ac
movb $0x64, %cl
xorl %eax, %eax
movq 0x6162(%rip), %r14      # 0x131b8
leaq 0xfaf(%rip), %rbx       # 0xe00c
movb (%r14,%rax), %dl
testb %dl, %dl
je 0xd07a
cmpb %dl, %cl
jne 0xd313
movb 0x1(%rax,%rbx), %cl
incq %rax
cmpq $0x6, %rax
jne 0xd05d
movl $0x1, %edi
movl $0x38, %esi
callq 0x20f0
movq %rax, %rbp
movl $0x4, 0x8(%rax)
movq 0x6116(%rip), %rax      # 0x131b0
movq %rax, 0x20(%rbp)
movq %r14, 0x28(%rbp)
movb $0x1, 0x30(%rbp)
addq $0x6, %r14
movq %r14, 0x6107(%rip)      # 0x131b8
movq %rbx, 0x10(%rbp)
jmp 0xd034
leaq 0x2447(%rip), %rdi      # 0xf508
movl $0xb, %edx
movl %r12d, %esi
callq 0x20e0
testq %rax, %rax
je 0xd152
movl $0x1, %edi
movl $0x38, %esi
callq 0x20f0
movq %rax, %rbp
xorl %ebx, %ebx
movl %ebx, 0x8(%rax)
movq 0x60bf(%rip), %rax      # 0x131b0
movq %rax, 0x20(%rbp)
movq %r14, 0x28(%rbp)
movb 0x8(%rsp), %al
notb %al
andb $0x1, %al
movb %al, 0x30(%rbp)
movl %ebx, 0xc(%rbp)
callq 0x2190
movq %rax, %r14
movq (%rax), %rax
movq 0x10(%rsp), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0xd034
movsbl %r12b, %eax
leal (%rbx,%rbx,4), %ecx
leal (%rax,%rcx,2), %ebx
addl $-0x30, %ebx
callq 0xd7ac
movq (%r14), %rax
movq 0x607a(%rip), %rcx      # 0x131b8
movsbq (%rcx), %r12
testb $0x8, 0x1(%rax,%r12,2)
jne 0xd122
movl %ebx, 0xc(%rbp)
jmp 0xd034
xorl %ecx, %ecx
leaq 0x59c5(%rip), %rax      # 0x12b20
xorl %ebx, %ebx
movq (%rax,%rcx,8), %r15
movb (%r15), %dl
testb %dl, %dl
je 0xd19c
xorl %esi, %esi
movb (%r14,%rsi), %dil
testb %dil, %dil
je 0xd19c
cmpb %dil, %dl
jne 0xd186
movb 0x1(%r15,%rsi), %dl
incq %rsi
testb %dl, %dl
jne 0xd16a
jmp 0xd19c
cmpq $0x2d, %rcx
leaq 0x1(%rcx), %rdx
setae %bl
movq %rdx, %rcx
cmpq $0x2e, %rdx
jne 0xd15d
jmp 0xd1b9
movq %r14, %rdi
movq %r15, %rsi
callq 0xd624
movq %rax, %rbp
movq %r15, %rdi
callq 0x2080
addq %rax, 0x5fff(%rip)      # 0x131b8
testb $0x1, %bl
je 0xd034
movq 0x5fef(%rip), %r12      # 0x131b8
movq 0x5fe0(%rip), %rax      # 0x131b0
movq %rax, 0x8(%rsp)
movb 0x5fe5(%rip), %al       # 0x131c0
xorb $0x1, %al
movb %al, 0x7(%rsp)
xorl %r13d, %r13d
xorl %ebx, %ebx
leaq 0x5aa3(%rip), %rax      # 0x12c90
movq (%rax,%r13,8), %r15
movb (%r15), %al
testb %al, %al
je 0xd216
xorl %ecx, %ecx
movb (%r12,%rcx), %dl
testb %dl, %dl
je 0xd216
cmpb %dl, %al
jne 0xd2a0
movb 0x1(%r15,%rcx), %al
incq %rcx
testb %al, %al
jne 0xd1fa
movq %rbp, 0x10(%rsp)
movl $0x1, %edi
movl $0x38, %esi
callq 0x20f0
movq %rax, %r14
movl $0x3, 0x8(%rax)
movq 0x8(%rsp), %rax
movq %rax, 0x20(%r14)
movq %r12, 0x28(%r14)
movb 0x7(%rsp), %al
movb %al, 0x30(%r14)
movq %r15, 0x10(%r14)
movq %r15, %rdi
callq 0x2080
movq %rax, %r15
leaq (%r12,%rax), %rbp
movq %rbp, 0x5f55(%rip)      # 0x131b8
callq 0x2190
movq (%rax), %rax
movsbq (%r12,%r15), %rcx
cmpq $0x5f, %rcx
sete %dl
movb (%rax,%rcx,2), %al
andb $0x8, %al
shrb $0x3, %al
orb %dl, %al
cmpb $0x1, %al
jne 0xd294
movq %r12, 0x5f2c(%rip)      # 0x131b8
movq %r12, %rbp
movq 0x10(%rsp), %r14
movq %rbp, %r12
movq %r14, %rbp
testb %al, %al
jne 0xd2a3
jmp 0xd2bb
movq %rbp, %r14
cmpq $0x2a, %r13
leaq 0x1(%r13), %rax
setae %bl
movq %rax, %r13
cmpq $0x2b, %rax
jne 0xd1e6
movq %r14, %rbp
testb $0x1, %bl
je 0xd034
movq 0x5eea(%rip), %r14      # 0x131b8
movzbl (%r14), %ebx
cmpl $0x27, %ebx
je 0xd46c
cmpl $0x22, %ebx
jne 0xd4d3
callq 0xd7ac
callq 0xd963
movq %rax, %r15
movq 0x5ec0(%rip), %rax      # 0x131b8
cmpb $0x22, (%rax)
je 0xd427
callq 0xd66b
movsbl %al, %esi
movq %r15, %rdi
callq 0xd99d
jmp 0xd2f1
movb $0x69, %cl
xorl %eax, %eax
leaq 0xd00(%rip), %rbx       # 0xe01e
movb (%r14,%rax), %dl
testb %dl, %dl
je 0xd337
cmpb %dl, %cl
jne 0xd39d
movb 0x1(%rax,%rbx), %cl
incq %rax
cmpq $0x7, %rax
jne 0xd31e
movl $0x1, %edi
movl $0x38, %esi
callq 0x20f0
movq %rax, %rbp
movl $0x4, 0x8(%rax)
movq 0x5e59(%rip), %rax      # 0x131b0
movq %rax, 0x20(%rbp)
movq %r14, 0x28(%rbp)
movb $0x1, 0x30(%rbp)
addq $0x7, %r14
movq %r14, 0x5e4a(%rip)      # 0x131b8
movq %rbx, 0x10(%rbp)
movq 0x5e3f(%rip), %rax      # 0x131b8
movzbl (%rax), %eax
cmpq $0x20, %rax
ja 0xd38f
btq %rax, %r13
jae 0xd38f
callq 0xd7ac
jmp 0xd372
callq 0xd5b1
movq %rax, 0x18(%rbp)
jmp 0xd034
movb $0x69, %cl
xorl %eax, %eax
leaq 0xc7e(%rip), %rbx       # 0xe026
movb (%r14,%rax), %dl
testb %dl, %dl
je 0xd3c1
cmpb %dl, %cl
jne 0xd3f6
movb 0x1(%rax,%rbx), %cl
incq %rax
cmpq $0x5, %rax
jne 0xd3a8
movl $0x1, %edi
movl $0x38, %esi
callq 0x20f0
movq %rax, %rbp
movl $0x4, 0x8(%rax)
movq 0x5dcf(%rip), %rax      # 0x131b0
movq %rax, 0x20(%rbp)
movq %r14, 0x28(%rbp)
movb $0x1, 0x30(%rbp)
addq $0x5, %r14
jmp 0xd0aa
movb $0x69, %cl
xorl %eax, %eax
leaq 0xc2b(%rip), %rbx       # 0xe02c
movb (%r14,%rax), %dl
testb %dl, %dl
je 0xd07a
cmpb %dl, %cl
jne 0xd509
movb 0x1(%rax,%rbx), %cl
incq %rax
cmpq $0x6, %rax
jne 0xd401
jmp 0xd07a
callq 0xd7ac
movl $0x1, %edi
movl $0x38, %esi
callq 0x20f0
movq %rax, %rbp
movl $0x1, 0x8(%rax)
movq 0x5d64(%rip), %rax      # 0x131b0
movq %rax, 0x20(%rbp)
movq %r14, 0x28(%rbp)
movb 0x5d66(%rip), %al       # 0x131c0
xorb $0x1, %al
movb %al, 0x30(%rbp)
movq %r15, %rdi
callq 0xda17
jmp 0xd394
callq 0xd7ac
movq 0x5d40(%rip), %rbx      # 0x131b8
decq %rbx
movl $0x1, %edi
movl $0x38, %esi
callq 0x20f0
movq %rax, %rbp
movl $0x0, 0x8(%rax)
movq 0x5d15(%rip), %rax      # 0x131b0
movq %rax, 0x20(%rbp)
movq %rbx, 0x28(%rbp)
movb 0x5d17(%rip), %al       # 0x131c0
xorb $0x1, %al
movb %al, 0x30(%rbp)
callq 0xd66b
movsbl %al, %eax
movl %eax, 0xc(%rbp)
movq 0x5cf8(%rip), %rsi      # 0x131b8
cmpb $0x27, (%rsi)
jne 0xd56b
callq 0xd7ac
jmp 0xd034
callq 0x2190
cmpb $0x5f, %bl
je 0xd4f3
movsbq %bl, %rcx
movq (%rax), %rax
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
je 0xd58a
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd71d
movb $0x65, %cl
xorl %eax, %eax
leaq 0xb1f(%rip), %rbx       # 0xe033
movb (%r14,%rax), %dl
testb %dl, %dl
je 0xd3c1
cmpb %dl, %cl
jne 0xd553
movb 0x1(%rax,%rbx), %cl
incq %rax
cmpq $0x5, %rax
jne 0xd514
jmp 0xd3c1
movq 0x5c73(%rip), %rdi      # 0x131b0
movq %r14, %rsi
callq 0xcd82
leaq 0x1fac(%rip), %rdi      # 0xf4f8
xorl %eax, %eax
callq 0xd8b8
movq 0x5c56(%rip), %rdi      # 0x131b0
movq %r14, %rsi
callq 0xcd82
leaq 0x1f6e(%rip), %rdi      # 0xf4d7
jmp 0xd54c
movq 0x5c3e(%rip), %rdi      # 0x131b0
callq 0xcd82
movq 0x5c3a(%rip), %rax      # 0x131b8
movsbl (%rax), %esi
leaq 0x1f8b(%rip), %rdi      # 0xf513
jmp 0xd5aa
movq 0x5c1f(%rip), %rdi      # 0x131b0
movq %r14, %rsi
callq 0xcd82
movq 0x5c18(%rip), %rax      # 0x131b8
movsbl (%rax), %esi
leaq 0x1f83(%rip), %rdi      # 0xf52d
xorl %eax, %eax
callq 0xd8b8