// File: /workspace/github_c_makefile_star2_O3/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
xorl %eax, %eax
movl %eax, 0x8f5c(%rip)      # 0xf354
movl %eax, 0x8f5a(%rip)      # 0xf358
movl %eax, 0x8f58(%rip)      # 0xf35c
movl %eax, 0x8f56(%rip)      # 0xf360
movl %eax, 0x8f40(%rip)      # 0xf350
movl $0x1, 0x8f4a(%rip)      # 0xf364
cmpl $0x2, %edi
jl 0x6508
movl %edi, %r12d
leaq 0x4f26(%rip), %r14      # 0xb353
movl $0x1, %eax
movl $0x1, %ecx
movslq %ecx, %rdx
movq (%rsi,%rdx,8), %r8
cmpb $0x2d, (%r8)
jne 0x6510
movl $0x1, %edx
movzbl (%r8,%rdx), %r8d
cmpl $0x62, %r8d
jg 0x647a
cmpl $0x52, %r8d
jle 0x6498
cmpl $0x53, %r8d
je 0x64be
cmpl $0x54, %r8d
jne 0x6508
movl $0x1, 0x8edc(%rip)      # 0xf354
jmp 0x64e2
cmpl $0x63, %r8d
je 0x64aa
cmpl $0x76, %r8d
je 0x64d8
cmpl $0x6f, %r8d
jne 0x6508
movslq %ecx, %r8
incl %ecx
movq 0x8(%rsi,%r8,8), %r14
jmp 0x64e2
cmpl $0x4d, %r8d
jne 0x6503
movl $0x1, 0x8eb0(%rip)      # 0xf358
jmp 0x64e2
movl $0x1, 0x8eac(%rip)      # 0xf360
xorl %eax, %eax
movl %eax, 0x8ea0(%rip)      # 0xf35c
jmp 0x64d0
movl $0x1, 0x8e94(%rip)      # 0xf35c
xorl %eax, %eax
movl %eax, 0x8e90(%rip)      # 0xf360
movl %eax, 0x8e8e(%rip)      # 0xf364
jmp 0x64e2
movl $0x1, 0x8e6e(%rip)      # 0xf350
incq %rdx
movslq %ecx, %r8
movq (%rsi,%r8,8), %r8
cmpb $0x2d, (%r8)
je 0x644d
incl %ecx
cmpl %r12d, %ecx
jl 0x6437
jmp 0x6508
testl %r8d, %r8d
je 0x64f6
movq (%rsi), %rdi
callq 0x6756
subl %ecx, %r12d
jle 0x66e3
leaq (%rsi,%rdx,8), %rax
movq %rax, -0x38(%rbp)
xorl %r15d, %r15d
movl $0x0, -0x2c(%rbp)
movq -0x38(%rbp), %rax
movq (%rax,%r15,8), %r13
movq %r13, %rdi
movl $0x73, %esi
callq 0x6248
movq %rax, 0x8e51(%rip)      # 0xf398
testq %rax, %rax
je 0x673c
movl $0x200, %esi            # imm = 0x200
leaq -0x560(%rbp), %rbx
movq %rbx, %rdi
leaq 0x4da2(%rip), %rdx      # 0xb308
leaq 0x4fbf(%rip), %rcx      # 0xb52c
leaq 0x4fd0(%rip), %r8       # 0xb544
movq %r13, %r9
xorl %eax, %eax
callq 0x20a0
movq %rbx, %rdi
leaq 0x523f(%rip), %rsi      # 0xb7c7
callq 0x2140
movq %rax, 0x8dec(%rip)      # 0xf380
testq %rax, %rax
je 0x6744
movq %r13, 0x8dec(%rip)      # 0xf390
movq 0x8ded(%rip), %rdi      # 0xf398
leaq 0x4fb6(%rip), %rsi      # 0xb568
callq 0x2150
movq %rax, 0x8dca(%rip)      # 0xf388
testq %rax, %rax
je 0x674c
movl $0x1, %eax
movl %eax, 0x8d96(%rip)      # 0xf368
movl %eax, 0x8d94(%rip)      # 0xf36c
movl $0xa, 0x8d8e(%rip)      # 0xf370
callq 0x8459
cmpl $0x0, 0x8d62(%rip)      # 0xf350
je 0x6601
leaq 0x4f8c(%rip), %rdi      # 0xb583
movq %r13, %rsi
xorl %eax, %eax
callq 0x2090
leaq 0x8d98(%rip), %rdi      # 0xf3a0
callq 0x6b20
movl $0x0, 0x8da1(%rip)      # 0xf3b8
movq %r13, %rdi
callq 0x61dd
callq 0x4abb
xorl %eax, %eax
callq 0x61e7
movq 0x8d56(%rip), %rdi      # 0xf388
callq 0x2070
cmpl $0x0, 0x8d1a(%rip)      # 0xf358
je 0x6676
leaq 0x4f4a(%rip), %rdi      # 0xb591
movq %r13, %rsi
xorl %eax, %eax
callq 0x2090
callq 0x87c4
movq 0x8973(%rip), %rax      # 0xefd0
movq (%rax), %rcx
movl $0x2, %esi
movl $0x1, %edx
leaq 0x3bd7(%rip), %rdi      # 0xa248
callq 0x2170
callq 0x853b
movq 0x8d16(%rip), %r13      # 0xf398
movl 0x8cd8(%rip), %eax      # 0xf360
orl 0x8cd6(%rip), %eax      # 0xf364
je 0x66c0
movq %r13, %rdi
callq 0x628b
movl -0x2c(%rbp), %edx
cmpl $0x62, %edx
je 0x6751
movslq %edx, %rcx
incl %edx
movl %edx, -0x2c(%rbp)
movq %rax, -0x360(%rbp,%rcx,8)
movq $0x0, -0x358(%rbp,%rcx,8)
cmpl $0x0, 0x8c95(%rip)      # 0xf35c
jne 0x66d1
movq %r13, %rdi
callq 0x2050
incq %r15
cmpl %r15d, %r12d
jne 0x652b
movl 0x8c81(%rip), %eax      # 0xf364
testl %eax, %eax
je 0x6728
leaq -0x360(%rbp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6319
cmpl $0x0, 0x8c60(%rip)      # 0xf360
setne %al
movq (%rbx), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x6728
leaq -0x358(%rbp), %rbx
callq 0x2050
movq (%rbx), %rdi
addq $0x8, %rbx
testq %rdi, %rdi
jne 0x6717
xorl %eax, %eax
addq $0x538, %rsp            # imm = 0x538
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x2307
movq %r13, %rdi
callq 0x22c8
callq 0x2285
callq 0x225d