// File: /workspace/github_cpp_makefile_star2_O2/ndsol[P]git-mine/./hashapi.h
// Function: CommitReader::read_from(_IO_FILE*, CommitMessage*)
int read_from(FILE* fin, CommitMessage* out) {
    size_t max = 1024;
    char* message = reinterpret_cast<char*>(malloc(max));
    if (!message) {
      fprintf(stderr, "%s: out of memory at %zuK\n", whoami, max / 1024);
      return 1;
    }

    char extra_room_sizer[16];
    size_t remain = max;
    // EXTRA_ROOM_PAD: padding to make this a commit.
    // strlen("commit ") + strlen("\0") + '\0' at the very end
    #define EXTRA_ROOM_PAD (7+1+1)
    int extra_room = EXTRA_ROOM_PAD + 4 /*strlen(sprintf("%s", max))*/;
    char* p = message;
    while (!feof(fin)) {
      size_t r = fread(p, 1, remain - extra_room, fin);
      if (r < remain && !feof(fin) && errno) {
        // This utility must be passed on stdin the
        // contents of the commit (completely unedited), like so:
        // git cat-file commit HEAD | $whoami
        fprintf(stderr, "Usage: %s $GIT_TOPLEVEL\n"
          "Failed to read stdin after %zu bytes: %d %s\n",
          whoami, max - remain, errno, strerror(errno));
        return 1;
      }
      p += r;
      remain -= r;
      if (remain <= (size_t) extra_room) {
        remain += max;
        message = reinterpret_cast<char*>(realloc(message, max *= 2));
        if (!message) {
          fprintf(stderr, "%s: out of memory at %zuK\n", whoami,
                  max / (2*1024));
          return 1;
        }
        p = message + (max - remain);
        extra_room = snprintf(extra_room_sizer, sizeof(extra_room_sizer), "%zu",
                              max);
        if (extra_room < 4) {
          fprintf(stderr, "%s: failed to size extra_room\n", whoami);
          return 1;
        }
        extra_room += EXTRA_ROOM_PAD;
      }
    }

    // Success. Clean up message.
    if (remain <= (size_t) extra_room) {
      fprintf(stderr, "%s: BUG: remain too small (want %d)\n", whoami,
              extra_room);
      return 1;
    }
    size_t len = max - remain;
    extra_room = snprintf(extra_room_sizer, sizeof(extra_room_sizer), "%zu",
                          len);
    if (extra_room < 1) {
      fprintf(stderr, "%s: failed to get final extra_room\n", whoami);
      return 1;
    }
    // Make room at the beginning for "commit %zu\0"
    max = max - remain + extra_room + EXTRA_ROOM_PAD;
    memmove(message + extra_room + 7 + 1, message, len);
    // Write "commit %zu\0"
    strncpy(message, "commit ", 7);
    strncpy(message + 7, extra_room_sizer, extra_room);
    message[extra_room + 7] = 0;
    message[max - 1] = 0;  // Add '\0' null terminator at very end of message.

    return out->set(message, max - 1);
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %rbx
movq %rsi, %r13
movq %rdi, 0x8(%rsp)
movl $0x400, %r14d           # imm = 0x400
movl $0x400, %edi            # imm = 0x400
callq 0x3330
testq %rax, %rax
je 0x3a68
movq %rbx, 0x28(%rsp)
pushq $0xd
popq %rcx
movq %rax, 0x18(%rsp)
movq %rax, %r15
movl $0x400, %eax            # imm = 0x400
movq %rax, 0x10(%rsp)
movl %ecx, 0x24(%rsp)
movslq %ecx, %rbp
movq %r14, %rbx
movq %r13, %rdi
callq 0x3400
testl %eax, %eax
jne 0x39c8
movq %rbx, %rdx
subq %rbp, %rdx
movq %r15, %rdi
pushq $0x1
popq %rsi
movq %r13, %rcx
callq 0x33e0
movq %rax, %r12
movq %rbx, %r14
subq %rax, %r14
jbe 0x395c
movq %r13, %rdi
callq 0x3400
testl %eax, %eax
jne 0x395c
callq 0x3030
movl (%rax), %ecx
testl %ecx, %ecx
jne 0x3ad8
addq %r12, %r15
cmpq %rbp, %r14
ja 0x390f
movq 0x10(%rsp), %r15
leaq (%r15,%r15), %r12
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x3470
testq %rax, %rax
je 0x3b1a
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
pushq $0x10
popq %rsi
leaq 0x6777(%rip), %rdx      # 0xa10c
movq %r12, %rcx
xorl %eax, %eax
callq 0x3430
cmpl $0x3, %eax
jle 0x3b3f
movl %eax, %ecx
addq %r15, %r14
movq %r12, %r15
subq %r14, %r15
movq %rbx, 0x18(%rsp)
addq %rbx, %r15
addl $0x9, %ecx
movq %r12, 0x10(%rsp)
jmp 0x3908
cmpq %rbp, %rbx
jbe 0x3a8d
movq 0x10(%rsp), %r12
subq %rbx, %r12
leaq 0x672c(%rip), %rdx      # 0xa10c
leaq 0x30(%rsp), %rdi
pushq $0x10
popq %rsi
movq %r12, %rcx
xorl %eax, %eax
callq 0x3430
testl %eax, %eax
jle 0x3ab3
movl %eax, %r14d
movq 0x18(%rsp), %rbx
leaq (%rbx,%r14), %r15
addq $0x8, %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x3440
movl $0x6d6d6f63, (%rbx)     # imm = 0x6D6D6F63
movl $0x2074696d, 0x3(%rbx)  # imm = 0x2074696D
leaq 0x7(%rbx), %rdi
leaq 0x30(%rsp), %rsi
movq %r14, %rdx
callq 0x3160
xorl %eax, %eax
movb %al, -0x1(%r15)
leaq (%r12,%r14), %rcx
leaq (%r12,%r14), %rdx
addq $0x8, %rdx
movb %al, 0x8(%rbx,%rcx)
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x4432
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb569(%rip), %rax      # 0xefd8
movq (%rax), %rdi
movq 0x8(%rsp), %rax
movq (%rax), %rdx
leaq 0x662b(%rip), %rsi      # 0xa0ac
pushq $0x1
popq %rcx
xorl %eax, %eax
callq 0x33a0
jmp 0x3ad3
movq 0xb544(%rip), %rax      # 0xefd8
movq (%rax), %rdi
movq 0x8(%rsp), %rax
movq (%rax), %rdx
leaq 0x6689(%rip), %rsi      # 0xa12f
movl 0x24(%rsp), %ecx
xorl %eax, %eax
callq 0x33a0
jmp 0x3ad3
movq 0xb51e(%rip), %rax      # 0xefd8
movq (%rax), %rdi
movq 0x8(%rsp), %rax
movq (%rax), %rdx
leaq 0x6688(%rip), %rsi      # 0xa154
xorl %eax, %eax
callq 0x33a0
pushq $0x1
popq %rax
jmp 0x3a59
movq 0xb4f9(%rip), %rax      # 0xefd8
movq (%rax), %r14
movq 0x8(%rsp), %rax
movq (%rax), %r15
movq 0x10(%rsp), %r12
subq %rbx, %r12
movl %ecx, %ebx
movl %ecx, %edi
callq 0x30b0
leaq 0x65c5(%rip), %rsi      # 0xa0c7
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl %ebx, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x33a0
jmp 0x3ad3
movq 0xb4b7(%rip), %rax      # 0xefd8
movq (%rax), %rdi
movq 0x8(%rsp), %rax
movq (%rax), %rdx
shrq $0xb, %r12
leaq 0x6575(%rip), %rsi      # 0xa0ac
movq %r12, %rcx
jmp 0x3a84
movq 0xb492(%rip), %rax      # 0xefd8
movq (%rax), %rdi
movq 0x8(%rsp), %rax
movq (%rax), %rdx
leaq 0x65b8(%rip), %rsi      # 0xa110
jmp 0x3acc
nop