// File: ndsol[P]git-mine/git-mine.cpp
// Function: main
int main(int argc, char ** argv) {
  if (argc != 3 && argc != 1) {
    // This utility must be called from a post-commit hook
    // with $GIT_TOPLEVEL as the only argument.
    fprintf(stderr, "Usage: %s [ atime_hint ctime_hint ]\n",
            argv[0]);
    return 1;
  }
  long long atime_hint = 0;
  long long ctime_hint = 0;
  if (argc == 3) {
    int n;
    if (sscanf(argv[1], "%lld%n", &atime_hint, &n) != 1 ||
        (int)strlen(argv[1]) != n) {
      fprintf(stderr, "Invalid atime_hint: \"%s\"\n", argv[2]);
      return 1;
    }
    if (sscanf(argv[2], "%lld%n", &ctime_hint, &n) != 1 ||
        (int)strlen(argv[2]) != n) {
      fprintf(stderr, "Invalid ctime_hint: \"%s\"\n", argv[2]);
      return 1;
    }
  }

  MineBoss boss;
  boss.atime_hint = atime_hint;
  boss.ctime_hint = ctime_hint;
  {
    FILE* f = stdin;
    CommitReader reader(argv[0]);
    if (reader.read_from(f, &boss.orig)) {
      return 1;
    }
    Sha1Hash sha;
    Blake2Hash b2h;
    if (boss.orig.hash(sha, b2h)) {
      return 1;
    }
    char shabuf[1024];
    if (sha.dump(shabuf, sizeof(shabuf))) {
      return 1;
    }
    fprintf(stderr, "Signing commit: %s\n", shabuf);
  }

  boss.start();
  for (size_t i = 90;;) {
    if (boss.printProgressAt1Hz()) break;
    i--;
    i++;
    if (!i) {
      fprintf(stderr, "\ntimed out\n");
      break;
    }
  }
  if (boss.getSearchDone()) {
    boss.commitMatch();
  }
  boss.stop();
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x7f0, %rsp            # imm = 0x7F0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
je 0x4810
cmpl $0x1, -0x8(%rbp)
je 0x4810
movq 0x1b7ec(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x1381f(%rip), %rsi     # 0x1801c
movb $0x0, %al
callq 0x44c0
movl $0x1, -0x4(%rbp)
jmp 0x4b3a
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
cmpl $0x3, -0x8(%rbp)
jne 0x48ee
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x13808(%rip), %rsi     # 0x18041
leaq -0x18(%rbp), %rdx
leaq -0x24(%rbp), %rcx
movb $0x0, %al
callq 0x42f0
cmpl $0x1, %eax
jne 0x485f
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x4140
cmpl -0x24(%rbp), %eax
je 0x488b
movq 0x1b772(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x137d0(%rip), %rsi     # 0x18048
movb $0x0, %al
callq 0x44c0
movl $0x1, -0x4(%rbp)
jmp 0x4b3a
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x137a7(%rip), %rsi     # 0x18041
leaq -0x20(%rbp), %rdx
leaq -0x24(%rbp), %rcx
movb $0x0, %al
callq 0x42f0
cmpl $0x1, %eax
jne 0x48c0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x4140
cmpl -0x24(%rbp), %eax
je 0x48ec
movq 0x1b711(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x13789(%rip), %rsi     # 0x18062
movb $0x0, %al
callq 0x44c0
movl $0x1, -0x4(%rbp)
jmp 0x4b3a
jmp 0x48ee
leaq -0x1f0(%rbp), %rdi
callq 0x4bf0
movq -0x18(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq 0x1b6b1(%rip), %rax     # 0x1ffc8
movq (%rax), %rax
movq %rax, -0x1f8(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq -0x200(%rbp), %rdi
callq 0x4c90
jmp 0x4936
movq -0x1f8(%rbp), %rsi
leaq -0x200(%rbp), %rdi
leaq -0x1f0(%rbp), %rdx
callq 0x4cb0
movl %eax, -0x7dc(%rbp)
jmp 0x4958
movl -0x7dc(%rbp), %eax
cmpl $0x0, %eax
je 0x499c
movl $0x1, -0x4(%rbp)
movl $0x1, -0x210(%rbp)
jmp 0x4b2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x208(%rbp)
movl %eax, -0x20c(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x5d60
jmp 0x4b46
leaq -0x288(%rbp), %rdi
callq 0x5040
jmp 0x49aa
leaq -0x3c8(%rbp), %rdi
callq 0x5060
jmp 0x49b8
leaq -0x1f0(%rbp), %rdi
leaq -0x288(%rbp), %rsi
leaq -0x3c8(%rbp), %rdx
callq 0x5080
movl %eax, -0x7e0(%rbp)
jmp 0x49da
movl -0x7e0(%rbp), %eax
cmpl $0x0, %eax
je 0x49fb
movl $0x1, -0x4(%rbp)
movl $0x1, -0x210(%rbp)
jmp 0x4b2e
leaq -0x288(%rbp), %rdi
leaq -0x7d0(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x51f0
movl %eax, -0x7e4(%rbp)
jmp 0x4a1b
movl -0x7e4(%rbp), %eax
cmpl $0x0, %eax
je 0x4a3c
movl $0x1, -0x4(%rbp)
movl $0x1, -0x210(%rbp)
jmp 0x4b2e
movq 0x1b595(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0x1362f(%rip), %rsi     # 0x1807c
xorl %eax, %eax
leaq -0x7d0(%rbp), %rdx
callq 0x44c0
leaq -0x1f0(%rbp), %rdi
callq 0x5220
jmp 0x4a69
movq $0x5a, -0x7d8(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x5740
movl %eax, -0x7e8(%rbp)
jmp 0x4a88
movl -0x7e8(%rbp), %eax
cmpl $0x0, %eax
je 0x4a95
jmp 0x4adf
movq -0x7d8(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x7d8(%rbp)
movq -0x7d8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x7d8(%rbp)
cmpq $0x0, -0x7d8(%rbp)
jne 0x4add
movq 0x1b50e(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0x135bc(%rip), %rsi     # 0x18090
movb $0x0, %al
callq 0x44c0
jmp 0x4adf
jmp 0x4a74
leaq -0x1f0(%rbp), %rdi
callq 0x5b70
movb %al, -0x7e9(%rbp)
jmp 0x4af3
movb -0x7e9(%rbp), %al
testb $0x1, %al
jne 0x4aff
jmp 0x4b0f
leaq -0x1f0(%rbp), %rdi
callq 0x5bc0
jmp 0x4b0d
jmp 0x4b0f
leaq -0x1f0(%rbp), %rdi
callq 0x5c90
jmp 0x4b1d
movl $0x0, -0x4(%rbp)
movl $0x1, -0x210(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x5d60
movl -0x4(%rbp), %eax
addq $0x7f0, %rsp            # imm = 0x7F0
popq %rbp
retq
movq -0x208(%rbp), %rdi
callq 0x4600
nopw %cs:(%rax,%rax)