// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
leaq 0x32f2(%rip), %r15      # 0xd4ce
leaq 0x32ee(%rip), %r12      # 0xd4d1
leaq 0x32ea(%rip), %r13      # 0xd4d4
pushq $0x5
popq %rbx
movq 0x7fc4(%rip), %r14      # 0x121b8
movsbl (%r14), %ebp
testl %ebp, %ebp
je 0xa296
movq %r15, %rdi
movq %r14, %rsi
callq 0xa6cf
testb %al, %al
je 0xa22f
movq %r12, %rdi
movq %r14, %rsi
callq 0xa6cf
movl %eax, %ebp
callq 0xa7e3
testb %bpl, %bpl
jne 0xa256
movq 0x7f8b(%rip), %r14      # 0x121b8
jmp 0xa20f
movq %r13, %rdi
movq %r14, %rsi
callq 0xa6cf
testb %al, %al
je 0xa25d
callq 0xa7e3
callq 0xa7e3
movq 0x7f69(%rip), %rax      # 0x121b8
cmpb $0xa, (%rax)
jne 0xa243
jmp 0xa1ed
callq 0xa7e3
jmp 0xa1ed
cmpb $0x23, %bpl
jne 0xa26c
testb $0x1, 0x7f56(%rip)      # 0x121c0
je 0xa2ab
cmpb $0x23, %bpl
je 0xa654
leaq 0x3286(%rip), %rdi      # 0xd503
movl %ebp, %esi
movq %rbx, %rdx
callq 0x20e0
testq %rax, %rax
je 0xa2f0
callq 0xa816
jmp 0xa1ed
xorl %r13d, %r13d
movq %r13, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xa7e3
movq 0x7f01(%rip), %rbx      # 0x121b8
leaq 0x1d4e(%rip), %r14      # 0xc00c
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa6cf
testb %al, %al
je 0xa352
pushq $0x4
popq %rdi
movq %rbx, %rsi
callq 0xa6f0
movq %rax, %r13
movb $0x1, 0x30(%rax)
addq $0x6, 0x7ecd(%rip)      # 0x121b8
jmp 0xa4be
leaq 0x3211(%rip), %rdi      # 0xd508
pushq $0xb
popq %rdx
movl %ebp, %esi
callq 0x20e0
testq %rax, %rax
je 0xa407
xorl %ebp, %ebp
xorl %edi, %edi
movq %r14, %rsi
callq 0xa6f0
movq %rax, %r13
andl $0x0, 0xc(%rax)
callq 0x2190
movq %rax, %rbx
movq (%rbx), %rcx
movq 0x7e89(%rip), %rax      # 0x121b8
movsbq (%rax), %rax
testb $0x8, 0x1(%rcx,%rax,2)
je 0xa299
imull $0xa, %ebp, %ecx
leal (%rcx,%rax), %ebp
addl $-0x30, %ebp
movl %ebp, 0xc(%r13)
callq 0xa7e3
jmp 0xa325
leaq 0x1cc5(%rip), %r14      # 0xc01e
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa6cf
testb %al, %al
je 0xa45a
pushq $0x4
popq %rdi
movq %rbx, %rsi
callq 0xa6f0
movq %rax, %r13
movb $0x1, 0x30(%rax)
addq $0x7, 0x7e32(%rip)      # 0x121b8
movq %r14, 0x10(%rax)
callq 0xa816
callq 0xaa4f
movq %rax, %rbx
movq 0x7e1a(%rip), %rsi      # 0x121b8
movzbl (%rsi), %eax
cmpl $0x3c, %eax
je 0xa3d8
cmpl $0x22, %eax
je 0xa3d8
movq 0x7dfe(%rip), %rdi      # 0x121b0
callq 0xa06e
movq 0x7dfa(%rip), %rax      # 0x121b8
movsbl (%rax), %esi
leaq 0x317c(%rip), %rdi      # 0xd544
jmp 0xa6c8
movsbl %al, %esi
movq %rbx, %rdi
callq 0xaa85
callq 0xa7e3
movq 0x7dd4(%rip), %rax      # 0x121b8
movzbl (%rax), %eax
cmpl $0x22, %eax
je 0xa3f1
cmpl $0x3e, %eax
jne 0xa3cd
callq 0xa7e3
movq %rbx, %rdi
callq 0xaaf4
movq %rax, 0x18(%r13)
jmp 0xa299
xorl %r15d, %r15d
leaq 0x770f(%rip), %r12      # 0x11b20
cmpq $0x170, %r15            # imm = 0x170
je 0xa4c7
movq (%r15,%r12), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa6cf
addq $0x8, %r15
testb %al, %al
je 0xa411
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa728
movq %rax, %r14
movq %rbx, %rdi
callq 0x2080
addq %rax, 0x7d66(%rip)      # 0x121b8
movq %r14, %rax
jmp 0xa29c
leaq 0x1bc5(%rip), %r14      # 0xc026
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa6cf
testb %al, %al
jne 0xa4a4
leaq 0x1bb5(%rip), %r14      # 0xc02c
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa6cf
testb %al, %al
jne 0xa2d1
leaq 0x1ba2(%rip), %r14      # 0xc033
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa6cf
testb %al, %al
je 0xa671
pushq $0x4
popq %rdi
movq %rbx, %rsi
callq 0xa6f0
movq %rax, %r13
movb $0x1, 0x30(%rax)
addq $0x5, 0x7cfa(%rip)      # 0x121b8
movq %r14, 0x10(%rax)
jmp 0xa299
xorl %r15d, %r15d
leaq 0x77bf(%rip), %r12      # 0x11c90
cmpq $0x158, %r15            # imm = 0x158
je 0xa544
movq (%r15,%r12), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa6cf
testb %al, %al
je 0xa53e
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa728
movq %rax, %r13
movq %rbx, %rdi
callq 0x2080
movq %rax, %rbx
movq 0x7cab(%rip), %r14      # 0x121b8
addq %r14, %rax
movq %rax, 0x7ca1(%rip)      # 0x121b8
callq 0x2190
movsbq (%r14,%rbx), %rcx
cmpq $0x5f, %rcx
je 0xa537
movq (%rax), %rax
movzwl (%rax,%rcx,2), %eax
andl $0x8, %eax
je 0xa299
movq %r14, 0x7c7a(%rip)      # 0x121b8
addq $0x8, %r15
jmp 0xa4d1
movzbl (%r14), %r15d
cmpl $0x27, %r15d
je 0xa59b
cmpl $0x22, %r15d
jne 0xa5da
callq 0xa7e3
callq 0xaa4f
movq %rax, %rbx
movq 0x7c4c(%rip), %rax      # 0x121b8
cmpb $0x22, (%rax)
je 0xa583
callq 0xa73d
movsbl %al, %esi
movq %rbx, %rdi
callq 0xaa85
jmp 0xa565
callq 0xa7e3
pushq $0x1
popq %rdi
movq %r14, %rsi
callq 0xa6f0
movq %rax, %r13
jmp 0xa3f6
callq 0xa7e3
movq 0x7c11(%rip), %rsi      # 0x121b8
decq %rsi
xorl %edi, %edi
callq 0xa6f0
movq %rax, %r13
callq 0xa73d
movsbl %al, %eax
movl %eax, 0xc(%r13)
movq 0x7bf1(%rip), %rsi      # 0x121b8
cmpb $0x27, (%rsi)
jne 0xa6ab
callq 0xa7e3
jmp 0xa299
callq 0x2190
movq %rax, %rbx
cmpb $0x5f, %r15b
je 0xa5fe
movsbq %r15b, %rax
movq (%rbx), %rcx
movzwl (%rcx,%rax,2), %eax
andl $0x400, %eax            # imm = 0x400
je 0xa689
pushq $0x2
popq %rdi
movq %r14, %rsi
callq 0xa6f0
movq %rax, %r13
callq 0xaa4f
movq %rax, %r14
movq 0x7b9d(%rip), %rax      # 0x121b8
movsbq (%rax), %rax
cmpq $0x5f, %rax
je 0xa631
movq (%rbx), %rcx
movzwl (%rcx,%rax,2), %ecx
andl $0x8, %ecx
je 0xa643
movsbl %al, %esi
movq %r14, %rdi
callq 0xaa85
callq 0xa7e3
jmp 0xa614
movq %r14, %rdi
callq 0xaaf4
movq %rax, 0x10(%r13)
jmp 0xa299
movq 0x7b55(%rip), %rdi      # 0x121b0
movq %r14, %rsi
callq 0xa06e
leaq 0x2e8e(%rip), %rdi      # 0xd4f8
xorl %eax, %eax
callq 0xa90e
movq 0x7b38(%rip), %rdi      # 0x121b0
movq %rbx, %rsi
callq 0xa06e
leaq 0x2e50(%rip), %rdi      # 0xd4d7
jmp 0xa66a
movq 0x7b20(%rip), %rdi      # 0x121b0
movq %r14, %rsi
callq 0xa06e
movq 0x7b19(%rip), %rax      # 0x121b8
movsbl (%rax), %esi
leaq 0x2e84(%rip), %rdi      # 0xd52d
jmp 0xa6c8
movq 0x7afe(%rip), %rdi      # 0x121b0
callq 0xa06e
movq 0x7afa(%rip), %rax      # 0x121b8
movsbl (%rax), %esi
leaq 0x2e4b(%rip), %rdi      # 0xd513
xorl %eax, %eax
callq 0xa90e