// File: /workspace/github_c_makefile_star2_O0/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
subq $0x370, %rsp            # imm = 0x370
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x5bd3(%rip), %rax      # 0xd4f3
movq %rax, -0x18(%rbp)
movl $0x0, -0x35c(%rbp)
movl $0x0, 0xabac(%rip)      # 0x124e4
movl $0x0, 0xaba6(%rip)      # 0x124e8
movl $0x0, 0xaba0(%rip)      # 0x124ec
movl $0x0, 0xab9a(%rip)      # 0x124f0
movl $0x0, 0xab80(%rip)      # 0x124e0
movl $0x1, 0xab8a(%rip)      # 0x124f4
movl $0x1, -0x354(%rbp)
movl -0x354(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x7aff
movq -0x10(%rbp), %rax
movslq -0x354(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x799f
jmp 0x7aff
movl $0x1, -0x358(%rbp)
movq -0x10(%rbp), %rax
movslq -0x354(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x2d, %ecx
movb %al, -0x35d(%rbp)
jne 0x79ee
movq -0x10(%rbp), %rax
movslq -0x354(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x358(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x35d(%rbp)
movb -0x35d(%rbp), %al
testb $0x1, %al
jne 0x79fd
jmp 0x7ae9
movq -0x10(%rbp), %rax
movslq -0x354(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x358(%rbp), %rcx
movsbl (%rax,%rcx), %eax
addl $-0x4d, %eax
movl %eax, %ecx
movq %rcx, -0x368(%rbp)
subl $0x29, %eax
ja 0x7ac7
movq -0x368(%rbp), %rax
leaq 0x599a(%rip), %rcx      # 0xd3d4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movl -0x354(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x354(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
jmp 0x7ad3
movl $0x1, 0xaa77(%rip)      # 0x124e4
jmp 0x7ad3
movl $0x1, 0xaa6f(%rip)      # 0x124e8
jmp 0x7ad3
movl $0x1, 0xaa6b(%rip)      # 0x124f0
movl $0x0, 0xaa5d(%rip)      # 0x124ec
movl $0x0, 0xaa5b(%rip)      # 0x124f4
jmp 0x7ad3
movl $0x1, 0xaa47(%rip)      # 0x124ec
movl $0x0, 0xaa41(%rip)      # 0x124f0
movl $0x0, 0xaa3b(%rip)      # 0x124f4
jmp 0x7ad3
movl $0x1, 0xaa1b(%rip)      # 0x124e0
jmp 0x7ad3
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7c60
jmp 0x7ad5
movl -0x358(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x358(%rbp)
jmp 0x79a9
jmp 0x7aeb
movl -0x354(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x354(%rbp)
jmp 0x7974
movl -0x354(%rbp), %eax
cmpl -0x8(%rbp), %eax
jl 0x7b16
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7c60
jmp 0x7b18
movl -0x354(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x7be1
movq -0x10(%rbp), %rax
movslq -0x354(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x7d30
movq %rax, -0x20(%rbp)
cmpl $0x0, 0xa9ae(%rip)      # 0x124f4
jne 0x7b51
cmpl $0x0, 0xa9a1(%rip)      # 0x124f0
je 0x7bbb
movq -0x20(%rbp), %rdi
callq 0x76d0
movq %rax, -0x28(%rbp)
cmpl $0x62, -0x35c(%rbp)
jne 0x7b89
movq 0xa48a(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x5981(%rip), %rsi      # 0xd4f9
movb $0x0, %al
callq 0x20e0
movl $0x1, %edi
callq 0x2140
movq -0x28(%rbp), %rcx
movl -0x35c(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x35c(%rbp)
cltq
movq %rcx, -0x350(%rbp,%rax,8)
movslq -0x35c(%rbp), %rax
movq $0x0, -0x350(%rbp,%rax,8)
cmpl $0x0, 0xa92a(%rip)      # 0x124ec
jne 0x7bcd
movq -0x20(%rbp), %rdi
callq 0x2040
movl -0x354(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x354(%rbp)
jmp 0x7b18
cmpl $0x0, 0xa90c(%rip)      # 0x124f4
je 0x7c48
movq -0x18(%rbp), %rdi
leaq -0x350(%rbp), %rsi
callq 0x77c0
cmpl $0x0, 0xa8ef(%rip)      # 0x124f0
jne 0x7c46
movl $0x0, -0x354(%rbp)
movslq -0x354(%rbp), %rax
cmpq $0x0, -0x350(%rbp,%rax,8)
je 0x7c44
movslq -0x354(%rbp), %rax
movq -0x350(%rbp,%rax,8), %rdi
callq 0x2040
movl -0x354(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x354(%rbp)
jmp 0x7c0d
jmp 0x7c46
jmp 0x7c48
xorl %eax, %eax
addq $0x370, %rsp            # imm = 0x370
popq %rbp
retq
nopw %cs:(%rax,%rax)