// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq 0x7373(%rip), %r13      # 0xefd8
movq (%r13), %rdi
movq 0x120(%rcx), %rcx
leaq 0x2b24(%rip), %rsi      # 0xa79b
movq %rbx, %rdx
xorl %eax, %eax
callq 0x33a0
movq (%r13), %rdi
movq 0x128(%r12), %rcx
leaq 0x2b21(%rip), %rsi      # 0xa7b5
movq %rbx, %rdx
xorl %eax, %eax
callq 0x33a0
leaq 0x30(%rsp), %rsi
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
callq 0x3c08
testl %eax, %eax
jne 0x7d53
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x8(%rsp), %r12
movq %r12, %rdx
callq 0x91f4
andq $0x0, (%r12)
pushq $0x14
popq %rdx
leaq 0x8(%rsp), %rcx
movq %r14, %rdi
movq %r15, %rsi
callq 0x5954
cmpl $-0x1, %eax
jne 0x7d71
movq (%r13), %rcx
leaq 0x2ad4(%rip), %rdi      # 0xa7cf
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
callq 0x3510
movq (%r13), %rdi
leaq 0x2ad9(%rip), %rsi      # 0xa7ea
leaq 0x30(%rsp), %r15
movq %rbx, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x33a0
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
movq %r15, %rsi
callq 0x5da8
movq (%r13), %rcx
testl %eax, %eax
jne 0x7e27
leaq 0x2ab4(%rip), %rsi      # 0xa7fa
leaq 0x30(%rsp), %rax
movq %rcx, %rdi
movq %rbx, %rdx
jmp 0x7d99
movq (%r13), %rcx
leaq 0x2717(%rip), %rdi      # 0xa475
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
callq 0x3510
pushq $0x1
popq %rbp
jmp 0x7e46
movl %eax, %r15d
movq 0x8(%rsp), %rcx
addq %rcx, %rcx
movq %rcx, 0x8(%rsp)
movq 0x18(%rsp), %rax
movq (%r13), %rdi
cmpq %rax, %rcx
jbe 0x7da8
leaq 0x2a76(%rip), %rsi      # 0xa80c
movq %rcx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x33a0
jmp 0x7e39
leaq (%rsp,%rcx), %r9
addq $0x30, %r9
leaq 0x2a80(%rip), %rsi      # 0xa837
xorl %ebp, %ebp
leaq 0x30(%rsp), %r12
movq %rbx, %rdx
movq %r12, %r8
xorl %eax, %eax
callq 0x33a0
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
movq %r12, %rsi
callq 0x5da8
movq (%r13), %rcx
testl %eax, %eax
jne 0x7e27
addl %r15d, %r15d
movq 0x8(%rsp), %r9
movslq %r15d, %rax
leaq (%rsp,%rax), %r10
addq $0x30, %r10
movq %r9, %rdx
addq %rax, %rdx
leaq (%rsp,%rdx), %r11
addq $0x30, %r11
leaq 0x2a4b(%rip), %rsi      # 0xa856
leaq 0x30(%rsp), %r8
movq %rcx, %rdi
movq %rbx, %rdx
movl %eax, %ecx
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x33a0
popq %rcx
popq %rdx
jmp 0x7e3c
leaq 0x2664(%rip), %rdi      # 0xa492
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
callq 0x3510
pushq $0x1
popq %rbp
leaq 0x10(%rsp), %rdi
callq 0x3110
movl %ebp, %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq