// File: /workspace/github_c_makefile_star2_O3/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
subq $0x98, %rsp
movq %rsi, %rbx
cmpl $0x1, %edi
jle 0x2acb
movl %edi, %r14d
movq 0x8(%rbx), %rdi
leaq 0x1737(%rip), %rsi      # 0x4022
callq 0x10c0
leaq 0x1dfb(%rip), %rdi      # 0x46f2
leaq -0xa8(%rbp), %rsi
testl %eax, %eax
je 0x29e3
callq 0x10e0
cmpl $-0x1, %eax
je 0x2af1
movl $0xf000, %eax           # imm = 0xF000
andl -0x90(%rbp), %eax
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x2af1
movq 0x8(%rbx), %r15
leaq 0x1742(%rip), %rsi      # 0x4077
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x2a15
cmpb $0x72, (%r15)
jne 0x295d
cmpb $0x6d, 0x1(%r15)
jne 0x295d
cmpb $0x0, 0x2(%r15)
je 0x2a15
leaq 0x173c(%rip), %rsi      # 0x40a0
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x2a5f
leaq 0x1772(%rip), %rsi      # 0x40ed
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x2ab7
leaq 0x1762(%rip), %rsi      # 0x40f4
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x2add
leaq 0x182f(%rip), %rsi      # 0x41d8
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x2afb
leaq 0x1738(%rip), %rsi      # 0x40f8
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
jne 0x2b91
cmpl $0x2, %r14d
jne 0x2b23
xorl %esi, %esi
xorl %edi, %edi
jmp 0x2b5b
callq 0x10e0
cmpl $-0x1, %eax
je 0x2a03
movl $0xf000, %eax           # imm = 0xF000
andl -0x90(%rbp), %eax
cmpl $0x4000, %eax           # imm = 0x4000
je 0x2b6d
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2bdc
cmpl $0x2, %r14d
je 0x2b0f
movq 0x10(%rbx), %rdi
callq 0x2855
testl %eax, %eax
je 0x2b0f
movq 0x8(%rbx), %rax
cmpb $0x72, (%rax)
jne 0x2a49
cmpb $0x6d, 0x1(%rax)
jne 0x2a49
cmpb $0x0, 0x2(%rax)
je 0x2b74
movq 0x10(%rbx), %rdi
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2d09
cmpl $0x4, %r14d
jb 0x2b19
movq 0x10(%rbx), %rax
cmpb $0x2d, (%rax)
jne 0x2b19
cmpb $0x6d, 0x1(%rax)
jne 0x2b19
cmpb $0x0, 0x2(%rax)
jne 0x2b19
movq 0x18(%rbx), %rbx
movq %rbx, %rdi
callq 0x1080
cmpq $0x200, %rax            # imm = 0x200
jae 0x2b8a
movq %rbx, %rdi
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x36e2
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x3475
movq %rbx, %rdi
callq 0x12ca
movl $0x2, %eax
jmp 0x2bc4
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x35a2
callq 0x126c
jmp 0x2bbf
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x37e8
callq 0x123d
jmp 0x2bbf
callq 0x120e
jmp 0x2bbf
movl %r14d, %eax
xorl %edi, %edi
movl $0x2, %ecx
xorl %esi, %esi
movq (%rbx,%rcx,8), %rdx
cmpb $0x2d, (%rdx)
jne 0x2b4b
cmpb $0x62, 0x1(%rdx)
jne 0x2ba7
movl $0x1, %esi
cmpb $0x0, 0x2(%rdx)
je 0x2b53
jmp 0x2ba7
testq %rdi, %rdi
movq %rdx, %rdi
jne 0x2bd2
incq %rcx
cmpq %rcx, %rax
jne 0x2b2f
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x3ab4
callq 0x129b
jmp 0x2bbf
movq 0x10(%rbx), %rdi
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2e98
callq 0x11df
jmp 0x2bbf
movq 0x4460(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x15a3(%rip), %rsi      # 0x4145
movq %r15, %rdx
jmp 0x2bb8
movq 0x444a(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x1549(%rip), %rsi      # 0x4101
xorl %eax, %eax
callq 0x10d0
movl $0x1, %eax
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x11b0
jmp 0x2bbf
nopl (%rax)