// File: /workspace/github_c_makefile_star2_O2/ejunjsh[P]mycc/main.c
// Function: main
int main(int argc, char **argv) {
  char *outfilename = AOUT;
  char *asmfile, *objfile;
  char *objlist[MAXOBJ];
  int i, j, objcnt = 0;

  // 初始化变量
  O_dumpAST = 0;
  O_dumpsym = 0;
  O_keepasm = 0;
  O_assemble = 0;
  O_verbose = 0;
  O_dolink = 1;

  // 扫描命令行参数
  for (i = 1; i < argc; i++) {
    // 不是'-'开头,停止扫描
    if (*argv[i] != '-')
      break;

    // 根据不同的参数设置不同的变量
    for (j = 1; (*argv[i] == '-') && argv[i][j]; j++) {
      switch (argv[i][j]) {
      case 'o':
        outfilename = argv[++i];	// 直接获取下一个参数
        break;
      case 'T':
        O_dumpAST = 1;
        break;
      case 'M':
        O_dumpsym = 1;
        break;
      case 'c':
        O_assemble = 1;
        O_keepasm = 0;
        O_dolink = 0;
        break;
      case 'S':
        O_keepasm = 1;
        O_assemble = 0;
        O_dolink = 0;
        break;
      case 'v':
        O_verbose = 1;
        break;
      default:
        usage(argv[0]);
      }
    }
  }

  // 保证至少由一个输入文件参数
  if (i >= argc)
    usage(argv[0]);

  // 循环处理每个输入文件
  while (i < argc) {
    asmfile = do_compile(argv[i]);	// 编译源文件

    if (O_dolink || O_assemble) {
      objfile = do_assemble(asmfile);	// 汇编成目标文件
      if (objcnt == (MAXOBJ - 2)) {
        fprintf(stderr, "Too many object files for the compiler to handle\n");
        exit(1);
      }
      objlist[objcnt++] = objfile;	//  把目标文件名加入到目标文件列表
      objlist[objcnt] = NULL;	
    }

    if (!O_keepasm)		// 如果不需要汇编后的文件,删之
      unlink(asmfile);		
    i++;
  }

  // 链接所有目标文件
  if (O_dolink) {
    do_link(outfilename, objlist);

    // 如果不需要目标文件,删之
    if (!O_assemble) {
      for (i = 0; objlist[i] != NULL; i++)
        unlink(objlist[i]);
    }
  }

  return (0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x538, %rsp            # imm = 0x538
andl $0x0, 0x83ae(%rip)      # 0xe354
andl $0x0, 0x83ab(%rip)      # 0xe358
andl $0x0, 0x83a8(%rip)      # 0xe35c
movq %rsi, %rbx
andl $0x0, 0x83a2(%rip)      # 0xe360
andl $0x0, 0x838b(%rip)      # 0xe350
movl $0x1, 0x8395(%rip)      # 0xe364
pushq $0x1
popq %rax
leaq 0x437a(%rip), %r9       # 0xa353
pushq $0x1
popq %rcx
cmpl %edi, %eax
jge 0x62a2
movslq %eax, %r13
movq (%rbx,%r13,8), %rdx
cmpb $0x2d, (%rdx)
jne 0x60a6
movb $0x2d, %r8b
movq %rcx, %rsi
cmpb $0x2d, %r8b
jne 0x609f
movzbl (%rdx,%rsi), %r8d
cmpl $0x4d, %r8d
je 0x6066
cmpl $0x53, %r8d
je 0x604c
cmpl $0x54, %r8d
je 0x6081
cmpl $0x63, %r8d
je 0x6039
cmpl $0x6f, %r8d
je 0x6072
cmpl $0x76, %r8d
jne 0x6096
movl $0x1, 0x8319(%rip)      # 0xe350
jmp 0x608b
andl $0x0, 0x831c(%rip)      # 0xe35c
movl $0x1, 0x8316(%rip)      # 0xe360
jmp 0x605d
andl $0x0, 0x830d(%rip)      # 0xe360
movl $0x1, 0x82ff(%rip)      # 0xe35c
andl $0x0, 0x8300(%rip)      # 0xe364
jmp 0x608b
movl $0x1, 0x82e8(%rip)      # 0xe358
jmp 0x608b
movslq %eax, %rdx
incl %eax
movq 0x8(%rbx,%rdx,8), %rdx
movq %rdx, %r9
jmp 0x608b
movl $0x1, 0x82c9(%rip)      # 0xe354
incq %rsi
movb (%rdx), %r8b
jmp 0x5ffa
testl %r8d, %r8d
jne 0x62a2
incl %eax
jmp 0x5fdc
movq %r9, -0x30(%rbp)
movslq %edi, %rax
movq %rax, -0x38(%rbp)
xorl %r14d, %r14d
cmpq -0x38(%rbp), %r13
jge 0x6256
movq (%rbx,%r13,8), %r15
movq %r15, %rdi
pushq $0x73
popq %rsi
callq 0x5dc0
movq %rax, 0x82c4(%rip)      # 0xe398
testq %rax, %rax
je 0x62d6
movl $0x200, %esi            # imm = 0x200
leaq -0x560(%rbp), %r12
movq %r12, %rdi
leaq 0x4215(%rip), %rdx      # 0xa308
leaq 0x4432(%rip), %rcx      # 0xa52c
leaq 0x4443(%rip), %r8       # 0xa544
movq %r15, %r9
xorl %eax, %eax
callq 0x20a0
movq %r12, %rdi
leaq 0x46b2(%rip), %rsi      # 0xa7c7
callq 0x2150
movq %rax, 0x825f(%rip)      # 0xe380
testq %rax, %rax
je 0x62f3
movq %r15, 0x825f(%rip)      # 0xe390
movq 0x8260(%rip), %rdi      # 0xe398
leaq 0x4429(%rip), %rsi      # 0xa568
callq 0x2160
movq %rax, 0x823d(%rip)      # 0xe388
testq %rax, %rax
je 0x62aa
pushq $0x1
popq %rax
movl %eax, 0x820b(%rip)      # 0xe368
movl %eax, 0x8209(%rip)      # 0xe36c
movl $0xa, 0x8203(%rip)      # 0xe370
callq 0x7d37
cmpl $0x0, 0x81d7(%rip)      # 0xe350
je 0x618c
leaq 0x4401(%rip), %rdi      # 0xa583
movq %r15, %rsi
xorl %eax, %eax
callq 0x2090
leaq 0x820d(%rip), %rdi      # 0xe3a0
callq 0x66f4
andl $0x0, 0x8219(%rip)      # 0xe3b8
movq %r15, %rdi
callq 0x5d55
callq 0x483f
xorl %eax, %eax
callq 0x5d5f
movq 0x81ce(%rip), %rdi      # 0xe388
callq 0x2070
cmpl $0x0, 0x8192(%rip)      # 0xe358
je 0x61fa
leaq 0x43c2(%rip), %rdi      # 0xa591
movq %r15, %rsi
xorl %eax, %eax
callq 0x2090
callq 0x80a3
movq 0x7deb(%rip), %rax      # 0xdfd0
movq (%rax), %rcx
leaq 0x3059(%rip), %rdi      # 0x9248
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x2180
callq 0x7e2a
movq 0x8192(%rip), %r15      # 0xe398
movl 0x8154(%rip), %eax      # 0xe360
orl 0x8152(%rip), %eax      # 0xe364
je 0x623d
movq %r15, %rdi
callq 0x5e01
cmpl $0x62, %r14d
je 0x6328
movslq %r14d, %rcx
incl %r14d
movq %rax, -0x360(%rbp,%rcx,8)
andq $0x0, -0x358(%rbp,%rcx,8)
cmpl $0x0, 0x8118(%rip)      # 0xe35c
jne 0x624e
movq %r15, %rdi
callq 0x2050
incq %r13
jmp 0x60b4
cmpl $0x0, 0x8107(%rip)      # 0xe364
je 0x628e
leaq -0x360(%rbp), %rbx
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
callq 0x5eb3
cmpl $0x0, 0x80e7(%rip)      # 0xe360
jne 0x628e
jmp 0x6286
callq 0x2050
addq $0x8, %rbx
movq (%rbx), %rdi
testq %rdi, %rdi
jne 0x627d
xorl %eax, %eax
addq $0x538, %rsp            # imm = 0x538
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rdi
callq 0x6346
movq 0x7d3f(%rip), %rax      # 0xdff0
movq (%rax), %rbx
movq 0x80dd(%rip), %r14      # 0xe398
callq 0x2040
movl (%rax), %edi
callq 0x21a0
leaq 0x429c(%rip), %rsi      # 0xa56a
movq %rbx, %rdi
movq %r14, %rdx
jmp 0x6316
movq 0x7d13(%rip), %rax      # 0xdff0
movq (%rax), %rdi
leaq 0x4219(%rip), %rsi      # 0xa500
movq %r15, %rdx
xorl %eax, %eax
callq 0x2100
jmp 0x6320
movq 0x7cf6(%rip), %rax      # 0xdff0
movq (%rax), %rbx
callq 0x2040
movl (%rax), %edi
callq 0x21a0
leaq 0x4241(%rip), %rsi      # 0xa551
movq %rbx, %rdi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2100
pushq $0x1
popq %rdi
callq 0x2170
movq 0x7cc1(%rip), %rax      # 0xdff0
movq (%rax), %rcx
leaq 0x4020(%rip), %rdi      # 0xa359
pushq $0x31
popq %rsi
pushq $0x1
popq %rdx
callq 0x2180
jmp 0x6320