// File: /workspace/github_c_makefile_star2_O0/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
subq $0x30, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x13e7
movq 0x7c35(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x4c30(%rip), %rsi      # 0x6004
movb $0x0, %al
callq 0x10c0
movl $0x2, -0x4(%rbp)
jmp 0x1764
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x4c2c(%rip), %rsi      # 0x6022
callq 0x10b0
cmpl $0x0, %eax
jne 0x143b
callq 0x1280
cmpl $0x0, %eax
je 0x142e
movq 0x7be7(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x4c0c(%rip), %rsi      # 0x6027
movb $0x0, %al
callq 0x10c0
movl $0x1, -0x4(%rbp)
jmp 0x1764
callq 0x1770
movl %eax, -0x4(%rbp)
jmp 0x1764
callq 0x1280
cmpl $0x0, %eax
jne 0x1469
movq 0x7bac(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x4bfb(%rip), %rsi      # 0x6051
movb $0x0, %al
callq 0x10c0
movl $0x1, -0x4(%rbp)
jmp 0x1764
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x4bff(%rip), %rsi      # 0x6077
callq 0x10b0
cmpl $0x0, %eax
je 0x149b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x51a5(%rip), %rsi      # 0x6636
callq 0x10b0
cmpl $0x0, %eax
jne 0x151a
cmpl $0x3, -0x8(%rbp)
jl 0x14b3
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x12f0
cmpl $0x0, %eax
jne 0x14d7
movq 0x7b3e(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x4bb7(%rip), %rsi      # 0x607b
movb $0x0, %al
callq 0x10c0
movl $0x1, -0x4(%rbp)
jmp 0x1764
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x5150(%rip), %rsi      # 0x6636
callq 0x10b0
cmpl $0x0, %eax
jne 0x1505
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x3560
movl %eax, -0x4(%rbp)
jmp 0x1764
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x21c0
movl %eax, -0x4(%rbp)
jmp 0x1764
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x4b77(%rip), %rsi      # 0x60a0
callq 0x10b0
cmpl $0x0, %eax
jne 0x15c8
cmpl $0x4, -0x8(%rbp)
jl 0x1556
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x4b5b(%rip), %rsi      # 0x60a7
callq 0x10b0
cmpl $0x0, %eax
je 0x157a
movq 0x7a9b(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x4b43(%rip), %rsi      # 0x60aa
movb $0x0, %al
callq 0x10c0
movl $0x1, -0x4(%rbp)
jmp 0x1764
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x1070
cmpq $0x1ff, %rax            # imm = 0x1FF
jbe 0x15b3
movq 0x7a62(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x4b33(%rip), %rsi      # 0x60d3
movb $0x0, %al
callq 0x10c0
movl $0x1, -0x4(%rbp)
jmp 0x1764
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x4c40
movl %eax, -0x4(%rbp)
jmp 0x1764
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x4b19(%rip), %rsi      # 0x60f0
callq 0x10b0
cmpl $0x0, %eax
jne 0x15f0
movb $0x0, %al
callq 0x4960
movl %eax, -0x4(%rbp)
jmp 0x1764
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x4af8(%rip), %rsi      # 0x60f7
callq 0x10b0
cmpl $0x0, %eax
jne 0x1618
movb $0x0, %al
callq 0x4ad0
movl %eax, -0x4(%rbp)
jmp 0x1764
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x4bb7(%rip), %rsi      # 0x61de
callq 0x10b0
cmpl $0x0, %eax
jne 0x1640
movb $0x0, %al
callq 0x4d60
movl %eax, -0x4(%rbp)
jmp 0x1764
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x4aac(%rip), %rsi      # 0x60fb
callq 0x10b0
cmpl $0x0, %eax
jne 0x173d
movl $0x0, -0x14(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x2, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x172c
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x16e6
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x4a5e(%rip), %rsi      # 0x6104
callq 0x10b0
cmpl $0x0, %eax
jne 0x16b9
movl $0x1, -0x14(%rbp)
jmp 0x171e
movq 0x7938(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0x4a31(%rip), %rsi      # 0x6107
movb $0x0, %al
callq 0x10c0
movl $0x1, -0x4(%rbp)
jmp 0x1764
cmpq $0x0, -0x20(%rbp)
je 0x170e
movq 0x7904(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x4a25(%rip), %rsi      # 0x6123
movb $0x0, %al
callq 0x10c0
movl $0x1, -0x4(%rbp)
jmp 0x1764
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1673
movq -0x20(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x5080
movl %eax, -0x4(%rbp)
jmp 0x1764
movq 0x78b4(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x49f5(%rip), %rsi      # 0x614b
movb $0x0, %al
callq 0x10c0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)