// File: /workspace/github_c_makefile_star2_O3/ejunjsh[P]mycc/scan.c
// Function: scan
int scan(struct token *t) {
  int c, tokentype;

  // 如果有个向前看的token，返回这个token
  if (Peektoken.token != 0) {
    t->token = Peektoken.token;
    t->tokstr = Peektoken.tokstr;
    t->intvalue = Peektoken.intvalue;
    Peektoken.token = 0;
    return (1);
  }

  // 跳过空格
  c = skip();

  // 判断token是什么样的token
  switch (c) {
    case EOF:
      t->token = T_EOF;
      return (0);
    case '+':
      if ((c = next()) == '+') {
	    t->token = T_INC;
      } else if (c == '=') {
	    t->token = T_ASPLUS;
      } else {
        putback(c);
        t->token = T_PLUS;
      }
      break;
    case '-':
      if ((c = next()) == '-') {
	    t->token = T_DEC;
      } else if (c == '>') {
	    t->token = T_ARROW;
      } else if (c == '=') {
	    t->token = T_ASMINUS;
      } else if (isdigit(c)) {	// 负数
	    t->intvalue = -scanint(c);
	    t->token = T_INTLIT;
      } else {
        putback(c);
        t->token = T_MINUS;
      }
      break;
    case '*':
      if ((c = next()) == '=') {
	    t->token = T_ASSTAR;
      } else {
        putback(c);
        t->token = T_STAR;
      }
      break;
    case '/':
      if ((c = next()) == '=') {
	    t->token = T_ASSLASH;
      } else {
        putback(c);
        t->token = T_SLASH;
      }
      break;
    case '%':
      if ((c = next()) == '=') {
	    t->token = T_ASMOD;
      } else {
        putback(c);
        t->token = T_MOD;
      }
      break;
    case ';':
      t->token = T_SEMI;
      break;
    case '{':
      t->token = T_LBRACE;
      break;
    case '}':
      t->token = T_RBRACE;
      break;
    case '(':
      t->token = T_LPAREN;
      break;
    case ')':
      t->token = T_RPAREN;
      break;
    case '[':
      t->token = T_LBRACKET;
      break;
    case ']':
      t->token = T_RBRACKET;
      break;
    case '~':
      t->token = T_INVERT;
      break;
    case '^':
      t->token = T_XOR;
      break;
    case ',':
      t->token = T_COMMA;
      break;
    case '.':
      t->token = T_DOT;
      break;
    case ':':
      t->token = T_COLON;
      break;
    case '?':
      t->token = T_QUESTION;
      break;
    case '=':
      if ((c = next()) == '=') {
	    t->token = T_EQ;
      } else {
        putback(c);
        t->token = T_ASSIGN;
      }
      break;
    case '!':
      if ((c = next()) == '=') {
	    t->token = T_NE;
      } else {
        putback(c);
        t->token = T_LOGNOT;
      }
      break;
    case '<':
      if ((c = next()) == '=') {
	    t->token = T_LE;
      } else if (c == '<') {
	    t->token = T_LSHIFT;
      } else {
        putback(c);
        t->token = T_LT;
      }
      break;
    case '>':
      if ((c = next()) == '=') {
	    t->token = T_GE;
      } else if (c == '>') {
	    t->token = T_RSHIFT;
      } else {
        putback(c);
        t->token = T_GT;
      }
      break;
    case '&':
      if ((c = next()) == '&') {
	    t->token = T_LOGAND;
      } else {
        putback(c);
        t->token = T_AMPER;
      }
      break;
    case '|':
      if ((c = next()) == '|') {
	    t->token = T_LOGOR;
      } else {
        putback(c);
        t->token = T_OR;
      }
      break;
    case '\'':
      // 如果是单引号，那就是要扫描字符了
      t->intvalue = scanch();
      t->token = T_INTLIT;
      if (next() != '\'')
	    fatal("Expected '\\'' at end of char literal");
      break;
    case '"':
      // 扫描字符串
      scanstr(Text);
      t->token = T_STRLIT;
      break;
    default:
      // 如果是数字，就扫描为字面量整型
      if (isdigit(c)) {
        t->intvalue = scanint(c);
        t->token = T_INTLIT;
        break;
      } else if (isalpha(c) || '_' == c) {
        // 读入关键字或标识符
        scanident(c, Text, TEXTLEN);

        // 如果是关键字，返回关键字的token
        if ((tokentype = keyword(Text)) != 0) {
            t->token = tokentype;
            break;
        }

        // 如果不是关键字，那就肯定是标识符
        t->token = T_IDENT;
        break;
      }

      // 到这里，就代表不是认识的token了，报错
      fatalc("Unrecognised character", c);
  }

  // 找到token啦
  t->tokstr = Tstring[t->token];
  return (1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x8884(%rip), %rax      # 0xf3b8
movl (%rax), %ecx
testl %ecx, %ecx
je 0x6b55
movl %ecx, (%rbx)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rbx)
movl 0x10(%rax), %ecx
movl %ecx, 0x10(%rbx)
movl $0x0, (%rax)
jmp 0x6f7f
leaq 0x4ab4(%rip), %r15      # 0xb610
callq 0x6f8f
movl %eax, %r14d
cmpl $0x5a, %eax
jg 0x6b94
leal -0x9(%r14), %eax
cmpl $0x36, %eax
ja 0x6be3
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
callq 0x6f8f
cmpl $0x3d, %eax
jne 0x6e93
movl $0xe, (%rbx)
jmp 0x6f6d
cmpl $0x7a, %r14d
jle 0x6bbe
leal -0x7b(%r14), %eax
cmpl $0x3, %eax
ja 0x6bf6
leaq 0x4b42(%rip), %rcx      # 0xb6ec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x37, (%rbx)
jmp 0x6f6d
cmpl $0x5b, %r14d
je 0x6e0e
cmpl $0x5d, %r14d
je 0x6ddf
cmpl $0x5e, %r14d
jne 0x6bf6
movl $0xb, (%rbx)
jmp 0x6f6d
cmpl $-0x1, %r14d
jne 0x6bf6
movl $0x0, (%rbx)
xorl %eax, %eax
jmp 0x6f84
callq 0x21a0
movq (%rax), %rax
movslq %r14d, %rcx
movzwl (%rax,%rcx,2), %eax
btl $0xb, %eax
jb 0x6e19
cmpl $0x5f, %r14d
je 0x6f0f
andl $0x400, %eax            # imm = 0x400
jne 0x6f0f
leaq 0x4c07(%rip), %rdi      # 0xb832
movl %r14d, %esi
callq 0x69ee
jmp 0x6f6d
movl $0x7, (%rbx)
jmp 0x6f6d
callq 0x6f8f
cmpl $0x3c, %eax
je 0x6ebb
cmpl $0x3d, %eax
jne 0x6ec6
movl $0x11, (%rbx)
jmp 0x6f6d
callq 0x6f8f
cmpl $0x3d, %eax
je 0x6eda
cmpl $0x2b, %eax
jne 0x6ee5
movl $0x1a, (%rbx)
jmp 0x6f6d
callq 0x6f8f
cmpl $0x3d, %eax
jne 0x6e2f
movl $0x4, (%rbx)
jmp 0x6f6d
movl $0x3a, (%rbx)
jmp 0x6f6d
movl $0x3e, (%rbx)
jmp 0x6f6d
callq 0x6f8f
cmpl $0x26, %eax
jne 0x6e43
movl $0x9, (%rbx)
jmp 0x6f6d
movl $0x40, (%rbx)
jmp 0x6f6d
callq 0x6f8f
cmpl $0x3d, %eax
jne 0x6e57
movl $0xd, (%rbx)
jmp 0x6f6d
callq 0x6f8f
cmpl $0x3d, %eax
jne 0x6e6b
movl $0x5, (%rbx)
jmp 0x6f6d
callq 0x717d
movl %eax, 0x10(%rbx)
movl $0x33, (%rbx)
callq 0x6f8f
cmpl $0x27, %eax
je 0x6f6d
leaq 0x4ade(%rip), %rdi      # 0xb80d
callq 0x6937
jmp 0x6f6d
callq 0x6f8f
cmpl $0x3e, %eax
je 0x6f2c
movl %eax, %r14d
cmpl $0x3d, %eax
je 0x6f24
cmpl $0x2d, %r14d
jne 0x6f34
movl $0x1b, (%rbx)
jmp 0x6f6d
callq 0x6f8f
cmpl $0x3d, %eax
jne 0x6e7f
movl $0x6, (%rbx)
jmp 0x6f6d
callq 0x7355
movl $0x34, (%rbx)
jmp 0x6f6d
movl $0x3d, (%rbx)
jmp 0x6f6d
callq 0x6f8f
cmpl $0x3e, %eax
je 0x6ef6
cmpl $0x3d, %eax
jne 0x6efe
movl $0x12, (%rbx)
jmp 0x6f6d
movl $0x39, (%rbx)
jmp 0x6f6d
movl $0x35, (%rbx)
jmp 0x6f6d
movl $0x38, (%rbx)
jmp 0x6f6d
movl $0x3c, (%rbx)
jmp 0x6f6d
movl $0x1c, (%rbx)
jmp 0x6f6d
callq 0x6f8f
cmpl $0x7c, %eax
jne 0x6ea7
movl $0x8, (%rbx)
jmp 0x6f6d
movl $0x3b, (%rbx)
jmp 0x6f6d
movl %r14d, %edi
callq 0x70d0
movl %eax, 0x10(%rbx)
movl $0x33, (%rbx)
jmp 0x6f6d
leaq 0x853a(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0x17, (%rbx)
jmp 0x6f6d
leaq 0x8526(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0xc, (%rbx)
jmp 0x6f6d
leaq 0x8512(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0x1, (%rbx)
jmp 0x6f6d
leaq 0x84fe(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0x18, (%rbx)
jmp 0x6f6d
leaq 0x84ea(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0x19, (%rbx)
jmp 0x6f6d
leaq 0x84d6(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0x1d, (%rbx)
jmp 0x6f6d
leaq 0x84c2(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0xa, (%rbx)
jmp 0x6f6d
movl $0x13, (%rbx)
jmp 0x6f6d
leaq 0x84a3(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0xf, (%rbx)
jmp 0x6f6d
movl $0x2, (%rbx)
jmp 0x6f6d
leaq 0x8484(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0x15, (%rbx)
jmp 0x6f6d
movl $0x14, (%rbx)
jmp 0x6f6d
leaq 0x846b(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0x10, (%rbx)
jmp 0x6f6d
movl %r14d, %edi
callq 0x7399
callq 0x7430
testl %eax, %eax
je 0x6f67
movl %eax, (%rbx)
jmp 0x6f6d
movl $0x3, (%rbx)
jmp 0x6f6d
movl $0x3f, (%rbx)
jmp 0x6f6d
callq 0x21a0
movq (%rax), %rax
movslq %r14d, %rcx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x6f58
leaq 0x8423(%rip), %rax      # 0xf370
movl %r14d, (%rax)
movl $0x16, (%rbx)
jmp 0x6f6d
movl %r14d, %edi
callq 0x70d0
negl %eax
jmp 0x6e21
movl $0x36, (%rbx)
movslq (%rbx), %rax
leaq 0x8189(%rip), %rcx      # 0xf100
movq (%rcx,%rax,8), %rax
movq %rax, 0x8(%rbx)
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq