// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movq %rsi, %r13
movq %rdi, %r15
movl $0x400, %ebx            # imm = 0x400
movl $0x400, %edi            # imm = 0x400
callq 0x3300
testq %rax, %rax
je 0x57ee
movq %rax, %r12
movq %r15, 0x8(%rsp)
movq %r14, 0x28(%rsp)
movq %r13, %rdi
callq 0x33b0
movl $0xd, %ebp
testl %eax, %eax
je 0x5663
movq %r12, 0x18(%rsp)
movl $0x400, %eax            # imm = 0x400
movq %rax, 0x10(%rsp)
jmp 0x5744
movq %r13, %r15
movl $0x400, %eax            # imm = 0x400
movq %rax, 0x10(%rsp)
movl $0x400, %r13d           # imm = 0x400
movq %r12, 0x18(%rsp)
movq %r13, %rbx
movq %r15, 0x20(%rsp)
movslq %ebp, %r14
movq %r13, %rdx
subq %r14, %rdx
movl $0x1, %esi
movq %r12, %rdi
movq %r15, %rcx
callq 0x3380
movq %rax, %r15
subq %rax, %rbx
jbe 0x56c1
movq 0x20(%rsp), %rdi
callq 0x33b0
testl %eax, %eax
jne 0x56c1
callq 0x3030
movl (%rax), %ecx
testl %ecx, %ecx
jne 0x5862
cmpq %r14, %rbx
jbe 0x56cb
addq %r15, %r12
jmp 0x572c
movq 0x10(%rsp), %r14
leaq (%r14,%r14), %r15
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x3430
testq %rax, %rax
je 0x582d
movq %rax, %r13
movl $0x10, %esi
leaq 0x30(%rsp), %rdi
leaq 0x5a0e(%rip), %rdx      # 0xb10c
movq %r15, %rcx
xorl %eax, %eax
callq 0x33e0
cmpl $0x3, %eax
jle 0x5856
movl %eax, %ebp
addq %r14, %rbx
movq %r15, %r12
subq %rbx, %r12
movq %r13, 0x18(%rsp)
addq %r13, %r12
addl $0x9, %ebp
movq %r15, 0x10(%rsp)
movq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x33b0
movq %rbx, %r13
testl %eax, %eax
je 0x5683
movslq %ebp, %rax
cmpq %rax, %rbx
jbe 0x57f8
movq 0x10(%rsp), %r14
subq %rbx, %r14
leaq 0x59ad(%rip), %rdx      # 0xb10c
leaq 0x30(%rsp), %rdi
movl $0x10, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x33e0
testl %eax, %eax
jle 0x581c
movl %eax, %ebx
movq 0x18(%rsp), %r12
leaq (%r12,%rbx), %r15
addq $0x8, %r15
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x3400
movl $0x6d6d6f63, (%r12)     # imm = 0x6D6D6F63
movl $0x2074696d, 0x3(%r12)  # imm = 0x2074696D
leaq 0x7(%r12), %rdi
leaq 0x30(%rsp), %rsi
movq %rbx, %rdx
callq 0x3150
xorl %eax, %eax
movb %al, -0x1(%r15)
leaq (%r14,%rbx), %rcx
leaq (%r14,%rbx), %rdx
addq $0x8, %rdx
movb %al, 0x8(%r12,%rcx)
movq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0x6074
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x356f
jmp 0x5826
movq 0x97d9(%rip), %rax      # 0xefd8
movq (%rax), %rdi
movq 0x8(%rsp), %rax
movq (%rax), %rdx
leaq 0x591e(%rip), %rsi      # 0xb12f
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3340
jmp 0x5826
movq 0x8(%rsp), %rdi
callq 0x3551
movl $0x1, %eax
jmp 0x57df
movq 0x97a4(%rip), %rax      # 0xefd8
movq (%rax), %rdi
movq 0x8(%rsp), %rax
movq (%rax), %rdx
shrq $0xb, %r15
leaq 0x5862(%rip), %rsi      # 0xb0ac
movq %r15, %rcx
xorl %eax, %eax
callq 0x3340
jmp 0x5826
movq 0x8(%rsp), %rdi
callq 0x3533
jmp 0x5826
movq 0x976f(%rip), %rax      # 0xefd8
movq (%rax), %r14
movq 0x8(%rsp), %rax
movq (%rax), %r15
movq 0x10(%rsp), %rbx
subq %r13, %rbx
movl %ecx, %ebp
movl %ecx, %edi
callq 0x30b0
leaq 0x583b(%rip), %rsi      # 0xb0c7
movq %r14, %rdi
movq %r15, %rdx
movq %rbx, %rcx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x3340
jmp 0x5826