// File: /workspace/github_c_makefile_star2_O0/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
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
leaq 0xa075(%rip), %rax      # 0x12548
cmpl $0x0, (%rax)
je 0x8524
leaq 0xa069(%rip), %rax      # 0x12548
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
leaq 0xa05a(%rip), %rax      # 0x12548
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
leaq 0xa047(%rip), %rax      # 0x12548
movl 0x10(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
leaq 0xa036(%rip), %rax      # 0x12548
movl $0x0, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x89f6
callq 0x8a00
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
incl %eax
movl %eax, %ecx
movq %rcx, -0x20(%rbp)
subl $0x7f, %eax
ja 0x892a
movq -0x20(%rbp), %rax
leaq 0x5265(%rip), %rcx      # 0xd7b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x89f6
callq 0x8a80
movl %eax, -0x14(%rbp)
cmpl $0x2b, %eax
jne 0x8583
movq -0x10(%rbp), %rax
movl $0x1a, (%rax)
jmp 0x85a9
cmpl $0x3d, -0x14(%rbp)
jne 0x8595
movq -0x10(%rbp), %rax
movl $0x2, (%rax)
jmp 0x85a7
movl -0x14(%rbp), %edi
callq 0x8c40
movq -0x10(%rbp), %rax
movl $0x15, (%rax)
jmp 0x85a9
jmp 0x89d5
callq 0x8a80
movl %eax, -0x14(%rbp)
cmpl $0x2d, %eax
jne 0x85c7
movq -0x10(%rbp), %rax
movl $0x1b, (%rax)
jmp 0x863c
cmpl $0x3e, -0x14(%rbp)
jne 0x85d9
movq -0x10(%rbp), %rax
movl $0x3f, (%rax)
jmp 0x863a
cmpl $0x3d, -0x14(%rbp)
jne 0x85eb
movq -0x10(%rbp), %rax
movl $0x3, (%rax)
jmp 0x8638
callq 0x2170
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x8624
movl -0x14(%rbp), %edi
callq 0x8c60
xorl %ecx, %ecx
subl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movl $0x33, (%rax)
jmp 0x8636
movl -0x14(%rbp), %edi
callq 0x8c40
movq -0x10(%rbp), %rax
movl $0x16, (%rax)
jmp 0x8638
jmp 0x863a
jmp 0x863c
jmp 0x89d5
callq 0x8a80
movl %eax, -0x14(%rbp)
cmpl $0x3d, %eax
jne 0x865a
movq -0x10(%rbp), %rax
movl $0x4, (%rax)
jmp 0x866c
movl -0x14(%rbp), %edi
callq 0x8c40
movq -0x10(%rbp), %rax
movl $0x17, (%rax)
jmp 0x89d5
callq 0x8a80
movl %eax, -0x14(%rbp)
cmpl $0x3d, %eax
jne 0x868a
movq -0x10(%rbp), %rax
movl $0x5, (%rax)
jmp 0x869c
movl -0x14(%rbp), %edi
callq 0x8c40
movq -0x10(%rbp), %rax
movl $0x18, (%rax)
jmp 0x89d5
callq 0x8a80
movl %eax, -0x14(%rbp)
cmpl $0x3d, %eax
jne 0x86ba
movq -0x10(%rbp), %rax
movl $0x6, (%rax)
jmp 0x86cc
movl -0x14(%rbp), %edi
callq 0x8c40
movq -0x10(%rbp), %rax
movl $0x19, (%rax)
jmp 0x89d5
movq -0x10(%rbp), %rax
movl $0x35, (%rax)
jmp 0x89d5
movq -0x10(%rbp), %rax
movl $0x37, (%rax)
jmp 0x89d5
movq -0x10(%rbp), %rax
movl $0x38, (%rax)
jmp 0x89d5
movq -0x10(%rbp), %rax
movl $0x39, (%rax)
jmp 0x89d5
movq -0x10(%rbp), %rax
movl $0x3a, (%rax)
jmp 0x89d5
movq -0x10(%rbp), %rax
movl $0x3b, (%rax)
jmp 0x89d5
movq -0x10(%rbp), %rax
movl $0x3c, (%rax)
jmp 0x89d5
movq -0x10(%rbp), %rax
movl $0x1c, (%rax)
jmp 0x89d5
movq -0x10(%rbp), %rax
movl $0xb, (%rax)
jmp 0x89d5
movq -0x10(%rbp), %rax
movl $0x3d, (%rax)
jmp 0x89d5
movq -0x10(%rbp), %rax
movl $0x3e, (%rax)
jmp 0x89d5
movq -0x10(%rbp), %rax
movl $0x40, (%rax)
jmp 0x89d5
movq -0x10(%rbp), %rax
movl $0x7, (%rax)
jmp 0x89d5
callq 0x8a80
movl %eax, -0x14(%rbp)
cmpl $0x3d, %eax
jne 0x87ad
movq -0x10(%rbp), %rax
movl $0xd, (%rax)
jmp 0x87bf
movl -0x14(%rbp), %edi
callq 0x8c40
movq -0x10(%rbp), %rax
movl $0x1, (%rax)
jmp 0x89d5
callq 0x8a80
movl %eax, -0x14(%rbp)
cmpl $0x3d, %eax
jne 0x87dd
movq -0x10(%rbp), %rax
movl $0xe, (%rax)
jmp 0x87ef
movl -0x14(%rbp), %edi
callq 0x8c40
movq -0x10(%rbp), %rax
movl $0x1d, (%rax)
jmp 0x89d5
callq 0x8a80
movl %eax, -0x14(%rbp)
cmpl $0x3d, %eax
jne 0x880d
movq -0x10(%rbp), %rax
movl $0x11, (%rax)
jmp 0x8833
cmpl $0x3c, -0x14(%rbp)
jne 0x881f
movq -0x10(%rbp), %rax
movl $0x13, (%rax)
jmp 0x8831
movl -0x14(%rbp), %edi
callq 0x8c40
movq -0x10(%rbp), %rax
movl $0xf, (%rax)
jmp 0x8833
jmp 0x89d5
callq 0x8a80
movl %eax, -0x14(%rbp)
cmpl $0x3d, %eax
jne 0x8851
movq -0x10(%rbp), %rax
movl $0x12, (%rax)
jmp 0x8877
cmpl $0x3e, -0x14(%rbp)
jne 0x8863
movq -0x10(%rbp), %rax
movl $0x14, (%rax)
jmp 0x8875
movl -0x14(%rbp), %edi
callq 0x8c40
movq -0x10(%rbp), %rax
movl $0x10, (%rax)
jmp 0x8877
jmp 0x89d5
callq 0x8a80
movl %eax, -0x14(%rbp)
cmpl $0x26, %eax
jne 0x8895
movq -0x10(%rbp), %rax
movl $0x9, (%rax)
jmp 0x88a7
movl -0x14(%rbp), %edi
callq 0x8c40
movq -0x10(%rbp), %rax
movl $0xc, (%rax)
jmp 0x89d5
callq 0x8a80
movl %eax, -0x14(%rbp)
cmpl $0x7c, %eax
jne 0x88c5
movq -0x10(%rbp), %rax
movl $0x8, (%rax)
jmp 0x88d7
movl -0x14(%rbp), %edi
callq 0x8c40
movq -0x10(%rbp), %rax
movl $0xa, (%rax)
jmp 0x89d5
callq 0x8d10
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movl $0x33, (%rax)
callq 0x8a80
cmpl $0x27, %eax
je 0x890a
leaq 0x52ec(%rip), %rdi      # 0xdbf1
callq 0x8110
jmp 0x89d5
leaq 0x9c4a(%rip), %rdi      # 0x12560
callq 0x8e80
movq -0x10(%rbp), %rax
movl $0x34, (%rax)
jmp 0x89d5
callq 0x2170
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x8961
movl -0x14(%rbp), %edi
callq 0x8c60
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movl $0x33, (%rax)
jmp 0x89d5
callq 0x2170
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0x8985
movl $0x5f, %eax
cmpl -0x14(%rbp), %eax
jne 0x89c4
movl -0x14(%rbp), %edi
leaq 0x9bd1(%rip), %rsi      # 0x12560
movl $0x200, %edx            # imm = 0x200
callq 0x8f00
leaq 0x9bc0(%rip), %rdi      # 0x12560
callq 0x8fe0
movl %eax, -0x18(%rbp)
cmpl $0x0, %eax
je 0x89b8
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
jmp 0x89d5
movq -0x10(%rbp), %rax
movl $0x36, (%rax)
jmp 0x89d5
jmp 0x89c6
movl -0x14(%rbp), %esi
leaq 0x5246(%rip), %rdi      # 0xdc16
callq 0x81f0
movq -0x10(%rbp), %rax
movslq (%rax), %rcx
leaq 0x98ad(%rip), %rax      # 0x12290
movq (%rax,%rcx,8), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nop