// File: ndsol[P]git-mine/hashapi.cpp
// Function: printGitCommit(unsigned long, Sha1Hash&, Blake2Hash&, CommitMessage&)
int printGitCommit(size_t thId, Sha1Hash& sha, Blake2Hash& b2h,
                   CommitMessage& noodle) {
  fprintf(stderr, "Th%zu author time = %lld\n", thId, noodle.atime());
  fprintf(stderr, "Th%zu committer   = %lld\n", thId, noodle.ctime());
  char buf[1024];
  if (sha.dump(buf, sizeof(buf))) {
    fprintf(stderr, "sha.dump failed\n");
    return 1;
  }
  std::string wantOutput = buf;
  size_t matchlen = 0;
  int match = b2h.instr(sha.result, sizeof(sha.result), &matchlen);
  if (match == -1) {
    fprintf(stderr, "unable to match sha1-b2h:\n");
    fprintf(stderr, "Th%zu sha1: %s\n", thId, buf);
    if (b2h.dump(buf, sizeof(buf))) {
      fprintf(stderr, "b2h.dump failed\n");
      return 1;
    }
    fprintf(stderr, "Th%zu blake2: %s\n", thId, buf);
    return 1;
  }
  match *= 2;
  matchlen *= 2;
  if (matchlen > wantOutput.size()) {
    fprintf(stderr, "b2h.instr: matchlen=%zu must not be > %zu\n",
            matchlen, wantOutput.size());
    return 1;
  }
  fprintf(stderr, "Th%zu sha1: \e[1;31m%.*s\e[0m%s\n", thId, (int)matchlen,
          buf, &buf[matchlen]);

  if (b2h.dump(buf, sizeof(buf))) {
    fprintf(stderr, "b2h.dump failed\n");
    return 1;
  }
  fprintf(stderr, "Th%zu blake2: %.*s\e[1;31m%.*s\e[0m%s\n", thId, match,
          buf, (int)matchlen, &buf[match], &buf[match + matchlen]);
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x500, %rsp            # imm = 0x500
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq 0xd116(%rip), %rax      # 0x1ffd8
movq (%rax), %rax
movq %rax, -0x498(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x490(%rbp)
movq -0x28(%rbp), %rdi
callq 0x8520
movq -0x498(%rbp), %rdi
movq -0x490(%rbp), %rdx
movq %rax, %rcx
leaq 0x5953(%rip), %rsi      # 0x1884b
movb $0x0, %al
callq 0x44c0
movq 0xd0d2(%rip), %rax      # 0x1ffd8
movq (%rax), %rax
movq %rax, -0x488(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x480(%rbp)
movq -0x28(%rbp), %rdi
callq 0x8540
movq -0x488(%rbp), %rdi
movq -0x480(%rbp), %rdx
movq %rax, %rcx
leaq 0x5929(%rip), %rsi      # 0x18865
movb $0x0, %al
callq 0x44c0
movq -0x18(%rbp), %rdi
leaq -0x430(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x51f0
cmpl $0x0, %eax
je 0x12f81
movq 0xd074(%rip), %rax      # 0x1ffd8
movq (%rax), %rdi
leaq 0x54f7(%rip), %rsi      # 0x18465
movb $0x0, %al
callq 0x44c0
movl $0x1, -0x4(%rbp)
jmp 0x132e1
leaq -0x451(%rbp), %rdi
movq %rdi, -0x4a0(%rbp)
callq 0x4610
movq -0x4a0(%rbp), %rdx
leaq -0x450(%rbp), %rdi
leaq -0x430(%rbp), %rsi
callq 0x15200
jmp 0x12fb0
leaq -0x451(%rbp), %rdi
callq 0x4350
movq $0x0, -0x470(%rbp)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x14, %edx
leaq -0x470(%rbp), %rcx
callq 0xab20
movl %eax, -0x4a4(%rbp)
jmp 0x12fe8
movl -0x4a4(%rbp), %eax
movl %eax, -0x474(%rbp)
cmpl $-0x1, -0x474(%rbp)
jne 0x13129
movq 0xcfd0(%rip), %rax      # 0x1ffd8
movq %rax, -0x4c0(%rbp)
movq (%rax), %rdi
leaq 0x5866(%rip), %rsi      # 0x1887f
xorl %eax, %eax
movb %al, -0x4b1(%rbp)
callq 0x44c0
movq -0x4c0(%rbp), %rcx
movb -0x4b1(%rbp), %al
movq (%rcx), %rdi
movq -0x10(%rbp), %rdx
leaq 0x5859(%rip), %rsi      # 0x1889a
leaq -0x430(%rbp), %rcx
movq %rcx, -0x4b0(%rbp)
callq 0x44c0
movq -0x4b0(%rbp), %rsi
movq -0x20(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0xc5d0
movl %eax, -0x4a8(%rbp)
jmp 0x13071
movl -0x4a8(%rbp), %eax
cmpl $0x0, %eax
je 0x130f0
movq 0xcf55(%rip), %rax      # 0x1ffd8
movq (%rax), %rdi
leaq 0x53f5(%rip), %rsi      # 0x18482
movb $0x0, %al
callq 0x44c0
movl $0x1, -0x4(%rbp)
movl $0x1, -0x478(%rbp)
jmp 0x132d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x460(%rbp)
movl %eax, -0x464(%rbp)
leaq -0x451(%rbp), %rdi
callq 0x4350
jmp 0x132ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x460(%rbp)
movl %eax, -0x464(%rbp)
leaq -0x450(%rbp), %rdi
callq 0x4200
jmp 0x132ed
movq 0xcee1(%rip), %rax      # 0x1ffd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq -0x430(%rbp), %rcx
leaq 0x579e(%rip), %rsi      # 0x188aa
movb $0x0, %al
callq 0x44c0
movl $0x1, -0x4(%rbp)
movl $0x1, -0x478(%rbp)
jmp 0x132d5
movl -0x474(%rbp), %eax
shll %eax
movl %eax, -0x474(%rbp)
movq -0x470(%rbp), %rax
shlq %rax
movq %rax, -0x470(%rbp)
movq -0x470(%rbp), %rax
movq %rax, -0x4c8(%rbp)
leaq -0x450(%rbp), %rdi
callq 0x4230
movq %rax, %rcx
movq -0x4c8(%rbp), %rax
cmpq %rcx, %rax
jbe 0x131d1
movq 0xce60(%rip), %rax      # 0x1ffd8
movq (%rax), %rax
movq %rax, -0x4d8(%rbp)
movq -0x470(%rbp), %rax
movq %rax, -0x4d0(%rbp)
leaq -0x450(%rbp), %rdi
callq 0x4230
movq -0x4d8(%rbp), %rdi
movq -0x4d0(%rbp), %rdx
movq %rax, %rcx
leaq 0x5708(%rip), %rsi      # 0x188bc
movb $0x0, %al
callq 0x44c0
movl $0x1, -0x4(%rbp)
movl $0x1, -0x478(%rbp)
jmp 0x132d5
movq 0xce00(%rip), %rax      # 0x1ffd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
movq -0x470(%rbp), %rax
movl %eax, %ecx
leaq -0x430(%rbp,%rax), %r9
leaq 0x56f0(%rip), %rsi      # 0x188e7
xorl %eax, %eax
leaq -0x430(%rbp), %r8
movq %r8, -0x4e8(%rbp)
callq 0x44c0
movq -0x4e8(%rbp), %rsi
movq -0x20(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0xc5d0
movl %eax, -0x4dc(%rbp)
jmp 0x13229
movl -0x4dc(%rbp), %eax
cmpl $0x0, %eax
je 0x1325f
movq 0xcd9d(%rip), %rax      # 0x1ffd8
movq (%rax), %rdi
leaq 0x523d(%rip), %rsi      # 0x18482
movb $0x0, %al
callq 0x44c0
movl $0x1, -0x4(%rbp)
movl $0x1, -0x478(%rbp)
jmp 0x132d5
movq 0xcd72(%rip), %rax      # 0x1ffd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
movl -0x474(%rbp), %ecx
leaq -0x430(%rbp), %r8
movq -0x470(%rbp), %rax
movl %eax, %r9d
movslq -0x474(%rbp), %rax
leaq -0x430(%rbp), %r10
addq %rax, %r10
movslq -0x474(%rbp), %rsi
addq -0x470(%rbp), %rsi
leaq -0x430(%rbp), %rax
addq %rsi, %rax
leaq 0x5652(%rip), %rsi      # 0x18906
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x44c0
movl $0x0, -0x4(%rbp)
movl $0x1, -0x478(%rbp)
leaq -0x450(%rbp), %rdi
callq 0x4200
movl -0x4(%rbp), %eax
addq $0x500, %rsp            # imm = 0x500
popq %rbp
retq
movq -0x460(%rbp), %rdi
callq 0x4600
nopl (%rax)