// File: /workspace/github_c_makefile_star2_O1/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, 0x9024(%rip)      # 0xf354
movl %eax, 0x9022(%rip)      # 0xf358
movl %eax, 0x9020(%rip)      # 0xf35c
movl %eax, 0x901e(%rip)      # 0xf360
movl %eax, 0x9008(%rip)      # 0xf350
movl $0x1, 0x9012(%rip)      # 0xf364
movq %rdi, -0x30(%rbp)
cmpl $0x2, %edi
setge %dl
jl 0x6452
movq 0x8(%rsi), %rax
cmpb $0x2d, (%rax)
jne 0x645a
movl $0x1, %eax
leaq 0x4fd8(%rip), %r9       # 0xb353
xorl %ecx, %ecx
movslq %eax, %rdx
movq (%rsi,%rdx,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x6431
movl $0x1, %edx
movzbl (%rdi,%rdx), %edi
cmpl $0x62, %edi
jg 0x63ba
cmpl $0x52, %edi
jle 0x63d9
cmpl $0x53, %edi
je 0x63fc
cmpl $0x54, %edi
jne 0x6452
movl $0x1, 0x8f9c(%rip)      # 0xf354
jmp 0x641e
cmpl $0x63, %edi
je 0x63ea
cmpl $0x76, %edi
je 0x6414
cmpl $0x6f, %edi
jne 0x6452
movslq %eax, %rdi
incl %eax
movq 0x8(%rsi,%rdi,8), %r9
jmp 0x641e
cmpl $0x4d, %edi
jne 0x644e
movl $0x1, 0x8f70(%rip)      # 0xf358
jmp 0x641e
movl $0x1, 0x8f6c(%rip)      # 0xf360
movl %ecx, 0x8f62(%rip)      # 0xf35c
jmp 0x640c
movl $0x1, 0x8f56(%rip)      # 0xf35c
movl %ecx, 0x8f54(%rip)      # 0xf360
movl %ecx, 0x8f52(%rip)      # 0xf364
jmp 0x641e
movl $0x1, 0x8f32(%rip)      # 0xf350
incq %rdx
movslq %eax, %rdi
movq (%rsi,%rdi,8), %rdi
cmpb $0x2d, (%rdi)
je 0x6392
incl %eax
cmpl -0x30(%rbp), %eax
setl %dl
jge 0x6452
movslq %eax, %rdi
movq (%rsi,%rdi,8), %r8
cmpb $0x2d, (%r8)
je 0x637d
jmp 0x6466
testl %edi, %edi
je 0x6431
movq (%rsi), %rdi
callq 0x66af
leaq 0x4ef2(%rip), %r9       # 0xb353
movl $0x1, %edi
testb %dl, %dl
je 0x6452
movq %r9, -0x38(%rbp)
leaq (%rsi,%rdi,8), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
subl %edi, %eax
movq %rax, -0x30(%rbp)
leaq -0x560(%rbp), %r15
movl $0x1, %r14d
xorl %ebx, %ebx
xorl %r12d, %r12d
movq -0x40(%rbp), %rax
movq (%rax,%rbx,8), %r13
movq %r13, %rdi
movl $0x73, %esi
callq 0x6180
movq %rax, 0x8eea(%rip)      # 0xf398
testq %rax, %rax
je 0x669a
movl $0x200, %esi            # imm = 0x200
movq %r15, %rdi
leaq 0x4e42(%rip), %rdx      # 0xb308
leaq 0x505f(%rip), %rcx      # 0xb52c
leaq 0x5070(%rip), %r8       # 0xb544
movq %r13, %r9
xorl %eax, %eax
callq 0x20a0
movq %r15, %rdi
leaq 0x52df(%rip), %rsi      # 0xb7c7
callq 0x2140
movq %rax, 0x8e8c(%rip)      # 0xf380
testq %rax, %rax
je 0x66a2
movq %r13, 0x8e8c(%rip)      # 0xf390
movq 0x8e8d(%rip), %rdi      # 0xf398
leaq 0x5056(%rip), %rsi      # 0xb568
callq 0x2150
movq %rax, 0x8e6a(%rip)      # 0xf388
testq %rax, %rax
je 0x6695
movl %r14d, 0x8e3a(%rip)     # 0xf368
movl %r14d, 0x8e37(%rip)     # 0xf36c
movl $0xa, 0x8e31(%rip)      # 0xf370
callq 0x83ed
cmpl $0x0, 0x8e05(%rip)      # 0xf350
je 0x655e
leaq 0x502f(%rip), %rdi      # 0xb583
movq %r13, %rsi
xorl %eax, %eax
callq 0x2090
leaq 0x8e3b(%rip), %rdi      # 0xf3a0
callq 0x6a78
movl $0x0, 0x8e44(%rip)      # 0xf3b8
movq %r13, %rdi
callq 0x6118
callq 0x4b46
xorl %eax, %eax
callq 0x6122
movq 0x8df9(%rip), %rdi      # 0xf388
callq 0x2070
cmpl $0x0, 0x8dbd(%rip)      # 0xf358
je 0x65d3
leaq 0x4fed(%rip), %rdi      # 0xb591
movq %r13, %rsi
xorl %eax, %eax
callq 0x2090
callq 0x874d
movq 0x8a16(%rip), %rax      # 0xefd0
movq (%rax), %rcx
movl $0x2, %esi
movl $0x1, %edx
leaq 0x3c7a(%rip), %rdi      # 0xa248
callq 0x2170
callq 0x84cf
movq 0x8db9(%rip), %r13      # 0xf398
movl 0x8d7b(%rip), %eax      # 0xf360
orl 0x8d79(%rip), %eax      # 0xf364
je 0x6619
movq %r13, %rdi
callq 0x61c3
cmpl $0x62, %r12d
je 0x66aa
movslq %r12d, %rcx
incl %r12d
movq %rax, -0x360(%rbp,%rcx,8)
movq $0x0, -0x358(%rbp,%rcx,8)
cmpl $0x0, 0x8d3c(%rip)      # 0xf35c
jne 0x662a
movq %r13, %rdi
callq 0x2050
incq %rbx
cmpl %ebx, -0x30(%rbp)
jne 0x6492
cmpl $0x0, 0x8d27(%rip)      # 0xf364
je 0x6681
leaq -0x360(%rbp), %rbx
movq -0x38(%rbp), %rdi
movq %rbx, %rsi
callq 0x6251
cmpl $0x0, 0x8d07(%rip)      # 0xf360
setne %al
movq (%rbx), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x6681
leaq -0x358(%rbp), %rbx
callq 0x2050
movq (%rbx), %rdi
addq $0x8, %rbx
testq %rdi, %rdi
jne 0x6670
xorl %eax, %eax
addq $0x538, %rsp            # imm = 0x538
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x225e
movq %r13, %rdi
callq 0x22e0
movq %r13, %rdi
callq 0x22a1
callq 0x2236