// File: /workspace/github_c_makefile_star2_O2/MicBrain[P]Git-Sample/main.c
// Function: main
int main(int argc, char **argv) {
    if (argc < 2) {
        fprintf(stderr, "Usage: %s <command> [<args>]\n", argv[0]);
        return 2;
    }

    if (strcmp(argv[1], "init") == 0) {

      if (check_initialized()) {
        fprintf(stderr, "ERROR: Repository is already initialized\n");
        return 1;
      }

      return beargit_init();

    } else {

        if (!check_initialized()) {
            fprintf(stderr, "ERROR: Repository is not initialized\n");
            return 1;
        }

        if (strcmp(argv[1], "add") == 0 || strcmp(argv[1], "rm") == 0) {

          if (argc < 3 || !check_filename(argv[2])) {
            fprintf(stderr, "ERROR: No or invalid filename given\n");
            return 1;
          }

          if (strcmp(argv[1], "rm") == 0) {
            return beargit_rm(argv[2]);
          } else {
            return beargit_add(argv[2]);
          }

        } else if (strcmp(argv[1], "commit") == 0) {

          if (argc < 4 || strcmp(argv[2], "-m") != 0) {
            fprintf(stderr, "ERROR: Need a commit message (-m <msg>)\n");
            return 1;
          }

          if (strlen(argv[3]) > MSG_SIZE-1) {
            fprintf(stderr, "ERROR: Message is too long!\n");
            return 1;
          }

          return beargit_commit(argv[3]);

        } else if (strcmp(argv[1], "status") == 0) {
            return beargit_status();
        } else if (strcmp(argv[1], "log") == 0) {
            return beargit_log();
        } else if (strcmp(argv[1], "branch") == 0) {
            return beargit_branch();
        } else if (strcmp(argv[1], "checkout") == 0) {
            int branch_new = 0;
            char* arg = NULL;

            for (int i = 2; i < argc; i++) {
              if (argv[i][0] == '-') {
                if (strcmp(argv[i], "-b") == 0) {
                  branch_new = 1;
                  continue;
                } else {
                  fprintf(stderr, "ERROR: Invalid argument: %s", argv[i]);
                  return 1;
                }
              }

              if (arg) {
                  fprintf(stderr, "ERROR: Too many arguments for checkout!");
                  return 1;
              }

              arg = argv[i];
            }

            return beargit_checkout(arg, branch_new);
        } else {
            fprintf(stderr, "ERROR: Unknown command \"%s\"\n", argv[1]);
            return 1;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
cmpl $0x1, %edi
jle 0x1546
movl %edi, %r14d
movq 0x8(%rbx), %rdi
leaq 0x2cad(%rip), %rsi      # 0x4022
callq 0x10c0
movl %eax, %r15d
callq 0x129c
testl %r15d, %r15d
je 0x1482
testl %eax, %eax
je 0x1588
movq 0x8(%rbx), %r15
leaq 0x2cd9(%rip), %rsi      # 0x4077
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x1499
cmpb $0x72, (%r15)
jne 0x13c6
cmpb $0x6d, 0x1(%r15)
jne 0x13c6
cmpb $0x0, 0x2(%r15)
je 0x1499
leaq 0x2cd3(%rip), %rsi      # 0x40a0
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x14e0
leaq 0x2d09(%rip), %rsi      # 0x40ed
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x1535
leaq 0x2cf9(%rip), %rsi      # 0x40f4
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x1568
leaq 0x2dc6(%rip), %rsi      # 0x41d8
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x159d
leaq 0x2ccf(%rip), %rsi      # 0x40f8
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
jne 0x162a
movl %r14d, %eax
xorl %esi, %esi
pushq $0x2
popq %rcx
pushq $0x1
popq %r8
xorl %edi, %edi
cmpq %rax, %rcx
jae 0x1579
movq (%rbx,%rcx,8), %rdx
cmpb $0x2d, (%rdx)
jne 0x1471
cmpb $0x62, 0x1(%rdx)
jne 0x1640
cmpb $0x0, 0x2(%rdx)
movl %r8d, %esi
je 0x147d
jmp 0x1640
testq %rdi, %rdi
movq %rdx, %rdi
jne 0x165a
incq %rcx
jmp 0x1447
testl %eax, %eax
jne 0x15d8
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1670
cmpl $0x2, %r14d
je 0x15ae
movq 0x10(%rbx), %rdi
callq 0x12e5
testl %eax, %eax
je 0x15ae
movq 0x8(%rbx), %rax
cmpb $0x72, (%rax)
jne 0x14cd
cmpb $0x6d, 0x1(%rax)
jne 0x14cd
cmpb $0x0, 0x2(%rax)
je 0x15ed
movq 0x10(%rbx), %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1bc9
cmpl $0x4, %r14d
jb 0x15c3
movq 0x10(%rbx), %rax
cmpb $0x2d, (%rax)
jne 0x15c3
cmpb $0x6d, 0x1(%rax)
jne 0x15c3
cmpb $0x0, 0x2(%rax)
jne 0x15c3
movq 0x18(%rbx), %rbx
movq %rbx, %rdi
callq 0x1080
cmpq $0x200, %rax            # imm = 0x200
jae 0x1600
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x3101
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2ea2
movq 0x5aab(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0x2aaa(%rip), %rsi      # 0x4004
xorl %eax, %eax
callq 0x10d0
pushq $0x2
jmp 0x161e
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2fb6
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x3489
movq 0x5a69(%rip), %rax      # 0x6ff8
movq (%rax), %rcx
leaq 0x2ab8(%rip), %rdi      # 0x4051
pushq $0x25
jmp 0x1613
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x3203
movq 0x5a43(%rip), %rax      # 0x6ff8
movq (%rax), %rcx
leaq 0x2abc(%rip), %rdi      # 0x407b
pushq $0x24
jmp 0x1613
movq 0x5a2e(%rip), %rax      # 0x6ff8
movq (%rax), %rcx
leaq 0x2ad3(%rip), %rdi      # 0x40a7
pushq $0x28
jmp 0x1613
movq 0x5a19(%rip), %rax      # 0x6ff8
movq (%rax), %rcx
leaq 0x2a3e(%rip), %rdi      # 0x4027
pushq $0x29
jmp 0x1613
movq 0x10(%rbx), %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2373
movq 0x59f1(%rip), %rax      # 0x6ff8
movq (%rax), %rcx
leaq 0x2abf(%rip), %rdi      # 0x40d0
pushq $0x1c
popq %rsi
pushq $0x1
popq %rdx
callq 0x1190
pushq $0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x59c7(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2b0a(%rip), %rsi      # 0x4145
movq %r15, %rdx
jmp 0x1651
movq 0x59b1(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2ab0(%rip), %rsi      # 0x4101
xorl %eax, %eax
callq 0x10d0
jmp 0x161c
movq 0x5997(%rip), %rax      # 0x6ff8
movq (%rax), %rcx
leaq 0x2ab2(%rip), %rdi      # 0x411d
pushq $0x27
jmp 0x1613
nop