// File: /workspace/github_c_makefile_star2_O2/pocari[P]compilerbook-9cc/tokenize.c
// Function: tokenize
Token *tokenize(char *p) {
  Token head;
  head.next = NULL;
  Token *cur = &head;

  while (*p) {
    // fprintf(stderr, "*p ... %c\n", *p);
    if (isspace(*p)) {
      p++;
      continue;
    }

    if (starts_with(p, "//")) {
      p += 2;
      while (*p != '\n') {
        p++;
      }
      continue;
    }

    if (starts_with(p, "/*")) {
      char *q = strstr(p + 2, "*/");
      if (!q) {
        error_at(p, "ブロックコメントが閉じられていません");
      }
      p = q + 2;
      continue;
    }

    // fprintf(stderr, "c ... %c\n", *p);
    Keyword *key = tokenize_keyword(p);
    if (key) {
      int keyword_len = strlen(key->keyword);
      cur = new_token(key->kind, cur, p, keyword_len);
      assert(cur);
      p += keyword_len;
      continue;
    }

    int len = is_multi_char_operator(p);
    if (len) {
      cur = new_token(TK_RESERVED, cur, p, len);
      assert(cur);
      p += len;
      continue;
    }

    if (is_ident_first_char(*p)) {
      // fprintf(stderr, "tokenize ident(%c)\n", *p);
      char *s = p; // 識別子の先頭
      while (is_alnum(*p)) {
        p++;
      }

      cur = new_token(TK_IDENT, cur, s, p - s); //p - s で文字列長さになる
      assert(cur);
      continue;
    }

    if (*p == '"') {
      cur = tokenize_string_literal(cur, &p);
      assert(cur);
      continue;
    }
    if (*p == '\'') {
      cur = tokenize_char_literal(cur, &p);
      assert(cur);
      continue;
    }


    if (ispunct(*p)) {
      cur = new_token(TK_RESERVED, cur, p++, 1);
      assert(cur);
      continue;
    }

    if (isdigit(*p)) {
      cur = tokenize_number(cur, &p);
      assert(cur);
      continue;
    }


    error_at(p, "トークナイズできません");
  }
  new_token(TK_EOF, cur, p, 0);

  return head.next;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
leaq 0x8(%rsp), %rsi
movq %rdi, (%rsi)
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
andq $0x0, 0x8(%rax)
leaq 0x2ac1(%rip), %r14      # 0xae13
leaq 0x2abd(%rip), %r12      # 0xae16
movsbq (%rbx), %r15
testq %r15, %r15
je 0x87c2
callq 0x2200
movq (%rax), %rbp
movzwl (%rbp,%r15,2), %r13d
btl $0xd, %r13d
jb 0x839f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x824b
testb %al, %al
je 0x83a4
incq %rbx
movq %rbx, %rax
leaq 0x1(%rax), %rbx
cmpb $0xa, 0x1(%rax)
movq %rbx, %rax
jne 0x8390
jmp 0x8359
incq %rbx
jmp 0x8359
movq %rbx, %rdi
movq %r12, %rsi
callq 0x824b
testb %al, %al
je 0x83e8
leaq 0x2(%rbx), %rdi
leaq 0x2a5b(%rip), %rsi      # 0xae19
callq 0x21f0
movq %rax, %r13
testq %rax, %rax
jne 0x83dc
movq %rbx, %rdi
leaq 0x2a47(%rip), %rsi      # 0xae1c
xorl %eax, %eax
callq 0x46f0
addq $0x2, %r13
movq %r13, %rbx
jmp 0x8359
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
callq 0x8278
testq %rax, %rax
je 0x842e
movq %rax, %r12
movq (%rax), %rdi
callq 0x20b0
movq %rax, %r13
movl 0x8(%r12), %edi
movq (%rsp), %rsi
movq %rbx, %rdx
movl %r13d, %ecx
callq 0x8114
movq %rax, (%rsp)
testq %rax, %rax
je 0x87e7
movslq %r13d, %rax
jmp 0x845e
movq %rbx, %rdi
callq 0x82e8
testl %eax, %eax
je 0x8474
movl %eax, %r12d
pushq $0x1
popq %rdi
movq (%rsp), %rsi
movq %rbx, %rdx
movl %eax, %ecx
callq 0x8114
movq %rax, (%rsp)
testq %rax, %rax
je 0x8806
movslq %r12d, %rax
addq %rax, 0x8(%rsp)
leaq 0x29ac(%rip), %r12      # 0xae16
movq 0x8(%rsp), %rbx
jmp 0x8359
cmpb $0x5f, %r15b
je 0x84f2
movl %r15d, %eax
andb $-0x21, %al
addb $-0x41, %al
cmpb $0x19, %al
jbe 0x84f2
cmpb $0x27, %r15b
leaq 0x8(%rsp), %r12
je 0x853e
movzbl %r15b, %eax
cmpl $0x22, %eax
jne 0x8558
xorl %eax, %eax
callq 0x7ec8
movq %rax, %rbp
movq %rbx, %r15
leaq 0x2961(%rip), %r12      # 0xae16
movzbl 0x1(%r15), %eax
cmpl $0x5c, %eax
je 0x84d8
testl %eax, %eax
je 0x85eb
cmpl $0x22, %eax
je 0x85fc
incq %r15
movsbl %al, %esi
jmp 0x84e8
movsbl 0x2(%r15), %edi
addq $0x2, %r15
callq 0x8965
movl %eax, %esi
movq %rbp, %rdi
callq 0x7f00
jmp 0x84b5
leaq -0x1(%rbx), %r15
pushq $-0x1
popq %r13
movsbl 0x1(%r15), %edi
incq %r15
callq 0x8217
incl %r13d
testb %al, %al
jne 0x84fa
movq %r15, 0x8(%rsp)
pushq $0x2
popq %rdi
movq (%rsp), %rsi
movq %rbx, %rdx
movl %r13d, %ecx
callq 0x8114
movq %rax, (%rsp)
testq %rax, %rax
leaq 0x28e3(%rip), %r12      # 0xae16
jne 0x846a
jmp 0x8825
movsbl 0x1(%rbx), %ebp
cmpl $0x5c, %ebp
jne 0x8583
leaq 0x2(%rbx), %r15
movsbl 0x2(%rbx), %edi
callq 0x8965
movl %eax, %ebp
jmp 0x8587
testb $0x4, %r13b
jne 0x8664
btl $0xb, %r13d
jb 0x8697
movq %rbx, %rdi
leaq 0x2903(%rip), %rsi      # 0xae7a
xorl %eax, %eax
callq 0x46f0
jmp 0x8463
leaq 0x1(%rbx), %r15
leaq 0x2888(%rip), %r12      # 0xae16
movb 0x1(%r15), %al
testb %al, %al
jne 0x85ab
movq %r15, %rdi
leaq 0x29bd(%rip), %rsi      # 0xaf5d
xorl %eax, %eax
callq 0x46f0
movb 0x1(%r15), %al
cmpb $0x27, %al
je 0x85c1
leaq 0x1(%r15), %rdi
leaq 0x29c8(%rip), %rsi      # 0xaf82
xorl %eax, %eax
callq 0x46f0
addq $0x2, %r15
movq %r15, 0x8(%rsp)
pushq $0x3
popq %rdi
movq (%rsp), %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x8114
movslq %ebp, %rcx
movq %rax, (%rsp)
movq %rcx, 0x10(%rax)
jmp 0x846a
movq %rbx, %rdi
leaq 0x2940(%rip), %rsi      # 0xaf35
xorl %eax, %eax
callq 0x46f0
addq $0x2, %r15
movl %r15d, %ecx
subl %ebx, %ecx
pushq $0x14
popq %rdi
movq (%rsp), %rsi
movq %rbx, %rdx
callq 0x8114
movq %rax, %r13
movq %rbp, %rdi
xorl %esi, %esi
callq 0x7f00
movq %rbp, %rdi
callq 0x7f79
movq %rax, %rbx
movq %rbp, %rdi
callq 0x7f7d
movq %rbx, %rdi
movl %eax, %esi
callq 0x4903
movq %rax, 0x28(%r13)
movq %rbp, %rdi
callq 0x7f7d
movq %r13, (%rsp)
movl %eax, 0x30(%r13)
movq %rbp, %rdi
callq 0x7f42
movq %r15, 0x8(%rsp)
jmp 0x846a
leaq 0x1(%rbx), %rax
movq %rax, 0x8(%rsp)
pushq $0x1
popq %rcx
movl %ecx, %edi
movq (%rsp), %rsi
movq %rbx, %rdx
callq 0x8114
movq %rax, (%rsp)
testq %rax, %rax
leaq 0x278a(%rip), %r12      # 0xae16
jne 0x846a
jmp 0x8844
movq %rbx, %rdi
leaq 0x2907(%rip), %rsi      # 0xafa8
callq 0x824b
testb %al, %al
je 0x8724
leaq 0x2(%rbx), %r15
xorl %r12d, %r12d
movzbl (%r15), %eax
movl %eax, %ecx
addl $-0x41, %ecx
cmpl $0x25, %ecx
ja 0x86f9
movabsq $0x3f0000003f, %rdx     # imm = 0x3F0000003F
btq %rcx, %rdx
jae 0x86f9
leal -0x41(%rax), %edx
pushq $-0x37
popq %rcx
cmpb $0x6, %dl
jb 0x86dd
pushq $-0x30
popq %rcx
shlq $0x4, %r12
leal -0x61(%rax), %edx
cmpb $0x6, %dl
pushq $-0x57
popq %rdx
cmovbq %rdx, %rcx
addq %rax, %r12
addq %rcx, %r12
incq %r15
jmp 0x86b1
leal -0x30(%rax), %ecx
cmpb $0x9, %cl
jbe 0x86cf
pushq $0x3
popq %rdi
movq (%rsp), %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x8114
movq %rax, (%rsp)
movq %r12, 0x10(%rax)
movq %r15, 0x8(%rsp)
jmp 0x8463
movq %rbx, %rdi
leaq 0x287d(%rip), %rsi      # 0xafab
callq 0x824b
testb %al, %al
je 0x8758
leaq 0x2(%rbx), %r15
xorl %r12d, %r12d
movzbl (%r15), %eax
movl %eax, %ecx
andb $-0x2, %cl
cmpb $0x30, %cl
jne 0x8701
andl $0x1, %eax
leaq (%rax,%r12,2), %r12
incq %r15
jmp 0x873e
cmpb $0x30, %r15b
jne 0x876a
movsbq 0x1(%rbx), %rax
testb $0x8, 0x1(%rbp,%rax,2)
jne 0x879b
pushq $0x3
popq %rdi
movq (%rsp), %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x8114
movq %rax, %rbx
movq 0x8(%rsp), %rdi
movq %r12, %rsi
pushq $0xa
popq %rdx
callq 0x2140
movq %rbx, (%rsp)
movq %rax, 0x10(%rbx)
jmp 0x8463
leaq 0x1(%rbx), %r15
xorl %r12d, %r12d
movl %eax, %ecx
andb $-0x8, %cl
cmpb $0x30, %cl
jne 0x8701
andb $0x7, %al
movzbl %al, %eax
leaq (%rax,%r12,8), %r12
movb 0x1(%r15), %al
incq %r15
jmp 0x87a2
pushq $0x1e
popq %rdi
movq (%rsp), %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x8114
movq 0x18(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2665(%rip), %rdi      # 0xae53
leaq 0x2662(%rip), %rsi      # 0xae57
leaq 0x2666(%rip), %rcx      # 0xae62
movl $0x224, %edx            # imm = 0x224
callq 0x20d0
leaq 0x2646(%rip), %rdi      # 0xae53
leaq 0x2643(%rip), %rsi      # 0xae57
leaq 0x2647(%rip), %rcx      # 0xae62
movl $0x22c, %edx            # imm = 0x22C
callq 0x20d0
leaq 0x2627(%rip), %rdi      # 0xae53
leaq 0x2624(%rip), %rsi      # 0xae57
leaq 0x2628(%rip), %rcx      # 0xae62
movl $0x239, %edx            # imm = 0x239
callq 0x20d0
leaq 0x2608(%rip), %rdi      # 0xae53
leaq 0x2605(%rip), %rsi      # 0xae57
leaq 0x2609(%rip), %rcx      # 0xae62
movl $0x24b, %edx            # imm = 0x24B
callq 0x20d0