// File: /workspace/github_cpp_makefile_star2_O1/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 0xc85b(%rip), %r13      # 0xffd0
movq (%r13), %rdi
movq 0x120(%rcx), %rcx
leaq 0x9044(%rip), %rsi      # 0xc7cb
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3340
movq (%r13), %rdi
movq 0x128(%r12), %rcx
leaq 0x9041(%rip), %rsi      # 0xc7e5
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 0xaf20
testl %eax, %eax
jne 0x387c
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 0xb06e
leaq 0x8(%rsp), %rcx
andq $0x0, (%rcx)
pushq $0x14
popq %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x7bee
cmpl $-0x1, %eax
jne 0x389a
movq (%r13), %rcx
leaq 0x8fde(%rip), %rdi      # 0xc7ff
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
callq 0x34c0
movq (%r13), %rdi
leaq 0x8fe3(%rip), %rsi      # 0xc81a
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 0xaf20
movq (%r13), %rcx
testl %eax, %eax
jne 0x3953
leaq 0x8fbb(%rip), %rsi      # 0xc82a
leaq 0x30(%rsp), %rax
movq %rcx, %rdi
movq %rbx, %rdx
jmp 0x38c2
movq (%r13), %rcx
leaq 0x8c18(%rip), %rdi      # 0xc49f
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
callq 0x34c0
pushq $0x1
popq %rbp
jmp 0x3984
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 0x38d1
leaq 0x8f7d(%rip), %rsi      # 0xc83c
movq %rcx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x3340
jmp 0x3965
leaq (%rsp,%rcx), %r9
addq $0x30, %r9
leaq 0x8f87(%rip), %rsi      # 0xc867
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 0xaf20
movq (%r13), %rcx
testl %eax, %eax
jne 0x3953
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 0x8f4f(%rip), %rsi      # 0xc886
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 0x3968
leaq 0x8b62(%rip), %rdi      # 0xc4bc
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 0x3984
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