// File: /workspace/github_c_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %rbx
cmpl $0x1, %edi
jle 0x2b72
movl %edi, %r14d
movq 0x8(%rbx), %rdi
leaq 0x1703(%rip), %rsi      # 0x4022
callq 0x10c0
leaq 0x1dcd(%rip), %rdi      # 0x46f8
leaq -0xd0(%rbp), %rsi
testl %eax, %eax
je 0x2a91
callq 0x10e0
cmpl $-0x1, %eax
je 0x2ba6
movl $0xf000, %eax           # imm = 0xF000
andl -0xb8(%rbp), %eax
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x2ba6
movq 0x8(%rbx), %r15
leaq 0x170e(%rip), %rsi      # 0x4077
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x2ac7
leaq 0x1cb1(%rip), %rsi      # 0x4631
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x2ac7
leaq 0x1709(%rip), %rsi      # 0x40a0
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x2b1f
leaq 0x1742(%rip), %rsi      # 0x40f0
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x2b84
leaq 0x1732(%rip), %rsi      # 0x40f7
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x2bb0
leaq 0x1802(%rip), %rsi      # 0x41de
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x2bcf
leaq 0x1708(%rip), %rsi      # 0x40fb
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
jne 0x2c17
cmpl $0x2, %r14d
setne -0x29(%rbp)
je 0x2be7
movl %r14d, %ecx
movl $0x2, %r12d
subq %rcx, %r12
xorl %edi, %edi
movl $0x3, %r15d
xorl %esi, %esi
movq -0x8(%rbx,%r15,8), %r13
cmpb $0x2d, (%r13)
jne 0x2a69
movq %rbx, %r14
movq %rcx, %rbx
movq %rsi, -0x40(%rbp)
movq %rdi, -0x38(%rbp)
movq %r13, %rdi
leaq 0x16b9(%rip), %rsi      # 0x4104
callq 0x10c0
testl %eax, %eax
jne 0x2c61
movl $0x1, %esi
movq -0x38(%rbp), %rdi
movq %rbx, %rcx
movq %r14, %rbx
jmp 0x2a75
testq %rdi, %rdi
jne 0x2c49
movq %r13, %rdi
cmpq %rcx, %r15
setb -0x29(%rbp)
leaq (%r12,%r15), %rax
incq %rax
incq %r15
cmpq $0x3, %rax
jne 0x2a27
jmp 0x2beb
callq 0x10e0
cmpl $-0x1, %eax
je 0x2ab1
movl $0xf000, %eax           # imm = 0xF000
andl -0xb8(%rbp), %eax
cmpl $0x4000, %eax           # imm = 0x4000
je 0x2bc8
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c90
cmpl $0x2, %r14d
je 0x2b9c
movq 0x10(%rbx), %rdi
callq 0x2885
testl %eax, %eax
je 0x2b9c
movq 0x8(%rbx), %rdi
leaq 0x1b44(%rip), %rsi      # 0x4631
callq 0x10c0
movq 0x10(%rbx), %rdi
addq $0xa8, %rsp
testl %eax, %eax
je 0x2b10
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2dbd
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2f4c
cmpl $0x4, %r14d
jl 0x2c09
movq 0x10(%rbx), %rdi
leaq 0x1573(%rip), %rsi      # 0x40a7
callq 0x10c0
testl %eax, %eax
jne 0x2c09
movq 0x18(%rbx), %rbx
movq %rbx, %rdi
callq 0x1080
cmpq $0x200, %rax            # imm = 0x200
jae 0x2c10
movq %rbx, %rdi
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x373c
movq %rbx, %rdi
callq 0x12ca
movl $0x2, %eax
jmp 0x2c37
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x34cf
callq 0x123d
jmp 0x2c32
callq 0x126c
jmp 0x2c32
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x35fc
callq 0x129b
jmp 0x2c32
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3842
xorl %esi, %esi
xorl %edi, %edi
xorl %eax, %eax
testb $0x1, -0x29(%rbp)
jne 0x2c37
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3b0e
callq 0x120e
jmp 0x2c32
callq 0x11df
jmp 0x2c32
movq 0x43da(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x1523(%rip), %rsi      # 0x414b
movq %r15, %rdx
xorl %eax, %eax
callq 0x10d0
movl $0x1, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %rbx
movq %rsi, %r14
callq 0x11b0
movq %r14, %rsi
movq %rbx, %rdi
movl $0x1, %eax
jmp 0x2bed
movq 0x4390(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x1495(%rip), %rsi      # 0x4107
movq %r13, %rdx
xorl %eax, %eax
callq 0x10d0
movl $0x1, %eax
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
jmp 0x2bed
nop