// File: /workspace/github_cpp_makefile_star2_O3/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 0xb8a0(%rip), %r13      # 0xefd8
movq (%r13), %rdi
movq 0x120(%rcx), %rcx
leaq 0x8081(%rip), %rsi      # 0xb7cb
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3340
movq (%r13), %rdi
movq 0x128(%r12), %rcx
leaq 0x807e(%rip), %rsi      # 0xb7e5
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3340
leaq 0x30(%rsp), %rdi
pushq $0x14
popq %rcx
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdx
callq 0x9bb4
testl %eax, %eax
jne 0x383f
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x30(%rsp), %r12
movq %r12, %rdi
callq 0x3100
leaq (%rsp,%rax), %rdx
addq $0x30, %rdx
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x9cd0
leaq 0x8(%rsp), %rcx
andq $0x0, (%rcx)
pushq $0x14
popq %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x7a16
cmpl $-0x1, %eax
jne 0x385d
movq (%r13), %rcx
leaq 0x801b(%rip), %rdi      # 0xb7ff
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
callq 0x34c0
movq (%r13), %rdi
leaq 0x8020(%rip), %rsi      # 0xb81a
leaq 0x30(%rsp), %r15
movq %rbx, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x3340
pushq $0x40
popq %rcx
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdi
movq %r14, %rdx
callq 0x9bb4
movq (%r13), %rcx
testl %eax, %eax
jne 0x3916
leaq 0x7ff8(%rip), %rsi      # 0xb82a
leaq 0x30(%rsp), %rax
movq %rcx, %rdi
movq %rbx, %rdx
jmp 0x3885
movq (%r13), %rcx
leaq 0x7c55(%rip), %rdi      # 0xb49f
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
callq 0x34c0
pushq $0x1
popq %rbp
jmp 0x3947
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 0x3894
leaq 0x7fba(%rip), %rsi      # 0xb83c
movq %rcx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x3340
jmp 0x3928
leaq (%rsp,%rcx), %r9
addq $0x30, %r9
leaq 0x7fc4(%rip), %rsi      # 0xb867
xorl %ebp, %ebp
leaq 0x30(%rsp), %r12
movq %rbx, %rdx
movq %r12, %r8
xorl %eax, %eax
callq 0x3340
pushq $0x40
popq %rcx
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdi
movq %r14, %rdx
callq 0x9bb4
movq (%r13), %rcx
testl %eax, %eax
jne 0x3916
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 0x7f8c(%rip), %rsi      # 0xb886
leaq 0x30(%rsp), %r8
movq %rcx, %rdi
movq %rbx, %rdx
movl %eax, %ecx
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x3340
popq %rcx
popq %rdx
jmp 0x392b
leaq 0x7b9f(%rip), %rdi      # 0xb4bc
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
callq 0x34c0
pushq $0x1
popq %rbp
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x3947
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3240
movl %ebp, %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq