// File: /workspace/github_c_makefile_star2_O1/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 0x892c(%rip), %rax      # 0xf3b8
movl (%rax), %ecx
testl %ecx, %ecx
je 0x6aad
movl %ecx, (%rbx)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rbx)
movl 0x10(%rax), %ecx
movl %ecx, 0x10(%rbx)
movl $0x0, (%rax)
jmp 0x6ed7
leaq 0x4b5c(%rip), %r15      # 0xb610
callq 0x6ee7
movl %eax, %r14d
cmpl $0x5a, %eax
jg 0x6aec
leal -0x9(%r14), %eax
cmpl $0x36, %eax
ja 0x6b3b
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
callq 0x6ee7
cmpl $0x3d, %eax
jne 0x6deb
movl $0xe, (%rbx)
jmp 0x6ec5
cmpl $0x7a, %r14d
jle 0x6b16
leal -0x7b(%r14), %eax
cmpl $0x3, %eax
ja 0x6b4e
leaq 0x4bea(%rip), %rcx      # 0xb6ec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x37, (%rbx)
jmp 0x6ec5
cmpl $0x5b, %r14d
je 0x6d66
cmpl $0x5d, %r14d
je 0x6d37
cmpl $0x5e, %r14d
jne 0x6b4e
movl $0xb, (%rbx)
jmp 0x6ec5
cmpl $-0x1, %r14d
jne 0x6b4e
movl $0x0, (%rbx)
xorl %eax, %eax
jmp 0x6edc
callq 0x21a0
movq (%rax), %rax
movslq %r14d, %rcx
movzwl (%rax,%rcx,2), %eax
btl $0xb, %eax
jb 0x6d71
cmpl $0x5f, %r14d
je 0x6e67
andl $0x400, %eax            # imm = 0x400
jne 0x6e67
leaq 0x4caf(%rip), %rdi      # 0xb832
movl %r14d, %esi
callq 0x6946
jmp 0x6ec5
movl $0x7, (%rbx)
jmp 0x6ec5
callq 0x6ee7
cmpl $0x3c, %eax
je 0x6e13
cmpl $0x3d, %eax
jne 0x6e1e
movl $0x11, (%rbx)
jmp 0x6ec5
callq 0x6ee7
cmpl $0x3d, %eax
je 0x6e32
cmpl $0x2b, %eax
jne 0x6e3d
movl $0x1a, (%rbx)
jmp 0x6ec5
callq 0x6ee7
cmpl $0x3d, %eax
jne 0x6d87
movl $0x4, (%rbx)
jmp 0x6ec5
movl $0x3a, (%rbx)
jmp 0x6ec5
movl $0x3e, (%rbx)
jmp 0x6ec5
callq 0x6ee7
cmpl $0x26, %eax
jne 0x6d9b
movl $0x9, (%rbx)
jmp 0x6ec5
movl $0x40, (%rbx)
jmp 0x6ec5
callq 0x6ee7
cmpl $0x3d, %eax
jne 0x6daf
movl $0xd, (%rbx)
jmp 0x6ec5
callq 0x6ee7
cmpl $0x3d, %eax
jne 0x6dc3
movl $0x5, (%rbx)
jmp 0x6ec5
callq 0x70d6
movl %eax, 0x10(%rbx)
movl $0x33, (%rbx)
callq 0x6ee7
cmpl $0x27, %eax
je 0x6ec5
leaq 0x4b86(%rip), %rdi      # 0xb80d
callq 0x688f
jmp 0x6ec5
callq 0x6ee7
cmpl $0x3e, %eax
je 0x6e84
movl %eax, %r14d
cmpl $0x3d, %eax
je 0x6e7c
cmpl $0x2d, %r14d
jne 0x6e8c
movl $0x1b, (%rbx)
jmp 0x6ec5
callq 0x6ee7
cmpl $0x3d, %eax
jne 0x6dd7
movl $0x6, (%rbx)
jmp 0x6ec5
callq 0x72b6
movl $0x34, (%rbx)
jmp 0x6ec5
movl $0x3d, (%rbx)
jmp 0x6ec5
callq 0x6ee7
cmpl $0x3e, %eax
je 0x6e4e
cmpl $0x3d, %eax
jne 0x6e56
movl $0x12, (%rbx)
jmp 0x6ec5
movl $0x39, (%rbx)
jmp 0x6ec5
movl $0x35, (%rbx)
jmp 0x6ec5
movl $0x38, (%rbx)
jmp 0x6ec5
movl $0x3c, (%rbx)
jmp 0x6ec5
movl $0x1c, (%rbx)
jmp 0x6ec5
callq 0x6ee7
cmpl $0x7c, %eax
jne 0x6dff
movl $0x8, (%rbx)
jmp 0x6ec5
movl $0x3b, (%rbx)
jmp 0x6ec5
movl %r14d, %edi
callq 0x7023
movl %eax, 0x10(%rbx)
movl $0x33, (%rbx)
jmp 0x6ec5
leaq 0x85e2(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0x17, (%rbx)
jmp 0x6ec5
leaq 0x85ce(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0xc, (%rbx)
jmp 0x6ec5
leaq 0x85ba(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0x1, (%rbx)
jmp 0x6ec5
leaq 0x85a6(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0x18, (%rbx)
jmp 0x6ec5
leaq 0x8592(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0x19, (%rbx)
jmp 0x6ec5
leaq 0x857e(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0x1d, (%rbx)
jmp 0x6ec5
leaq 0x856a(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0xa, (%rbx)
jmp 0x6ec5
movl $0x13, (%rbx)
jmp 0x6ec5
leaq 0x854b(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0xf, (%rbx)
jmp 0x6ec5
movl $0x2, (%rbx)
jmp 0x6ec5
leaq 0x852c(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0x15, (%rbx)
jmp 0x6ec5
movl $0x14, (%rbx)
jmp 0x6ec5
leaq 0x8513(%rip), %rcx      # 0xf370
movl %eax, (%rcx)
movl $0x10, (%rbx)
jmp 0x6ec5
movl %r14d, %edi
callq 0x72fa
callq 0x7391
testl %eax, %eax
je 0x6ebf
movl %eax, (%rbx)
jmp 0x6ec5
movl $0x3, (%rbx)
jmp 0x6ec5
movl $0x3f, (%rbx)
jmp 0x6ec5
callq 0x21a0
movq (%rax), %rax
movslq %r14d, %rcx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x6eb0
leaq 0x84cb(%rip), %rax      # 0xf370
movl %r14d, (%rax)
movl $0x16, (%rbx)
jmp 0x6ec5
movl %r14d, %edi
callq 0x7023
negl %eax
jmp 0x6d79
movl $0x36, (%rbx)
movslq (%rbx), %rax
leaq 0x8231(%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