// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
movl $0x400, %r13d           # imm = 0x400
movl $0x400, %edi            # imm = 0x400
callq 0x3300
testq %rax, %rax
je 0x5984
movq %rbx, 0x38(%rsp)
movl $0xd, %ebx
movq %rax, 0x10(%rsp)
movq %rax, %r12
movl $0x400, %eax            # imm = 0x400
movq %rax, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movq %r14, %rdi
callq 0x33b0
movl %ebx, %ebp
movslq %ebx, %rbx
testl %eax, %eax
jne 0x58ee
movq %r13, %rdx
subq %rbx, %rdx
movl $0x1, %esi
movq %r12, %rdi
movq %r14, %rcx
callq 0x3380
movq %rax, %r15
movq %r13, %r14
subq %rax, %r14
jbe 0x57d4
movq 0x20(%rsp), %rdi
callq 0x33b0
testl %eax, %eax
jne 0x57d4
callq 0x3030
movl (%rax), %ecx
testl %ecx, %ecx
jne 0x5898
addq %r15, %r12
movb $0x1, %r15b
cmpq %rbx, %r14
jbe 0x57e6
movq %r14, %r13
movl %ebp, %ebx
jmp 0x583e
movq 0x18(%rsp), %rbx
addq %rbx, %r14
addq %rbx, %rbx
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x3430
testq %rax, %rax
movq %rbx, 0x18(%rsp)
je 0x5851
movq %rbx, %r12
subq %r14, %r12
movq %rax, 0x10(%rsp)
addq %rax, %r12
movl $0x10, %esi
leaq 0x40(%rsp), %rdi
leaq 0x68e5(%rip), %rdx      # 0xc10c
movq %rbx, %rcx
xorl %eax, %eax
callq 0x33e0
movl %eax, %ebx
cmpl $0x3, %eax
jle 0x5889
addl $0x9, %ebx
movq %r14, %r13
testb %r15b, %r15b
movq 0x20(%rsp), %r14
jne 0x5781
jmp 0x59be
movq 0xa778(%rip), %rax      # 0xffd0
movq (%rax), %rdi
movq 0x8(%rsp), %rax
movq (%rax), %rdx
shrq $0xb, %rbx
movq $0x0, 0x10(%rsp)
leaq 0x6835(%rip), %rsi      # 0xc0ac
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3340
xorl %r15d, %r15d
jmp 0x57df
movq 0x8(%rsp), %rdi
callq 0x3577
xorl %r15d, %r15d
jmp 0x583b
movq 0xa731(%rip), %rax      # 0xffd0
movq (%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x18(%rsp), %r14
subq %r13, %r14
movl %ecx, %ebx
movl %ecx, %edi
callq 0x30b0
xorl %r15d, %r15d
movq 0x28(%rsp), %rdi
leaq 0x67f3(%rip), %rsi      # 0xc0c7
movq 0x30(%rsp), %rdx
movq %r14, %rcx
movl %ebx, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x3340
jmp 0x57e2
cmpq %rbx, %r13
jbe 0x5990
movq 0x18(%rsp), %r14
subq %r13, %r14
leaq 0x6806(%rip), %rdx      # 0xc10c
leaq 0x40(%rsp), %rdi
movl $0x10, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x33e0
testl %eax, %eax
jle 0x59b4
movl %eax, %r15d
movq 0x10(%rsp), %rbx
leaq (%rbx,%r15), %r12
addq $0x8, %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3400
movl $0x6d6d6f63, (%rbx)     # imm = 0x6D6D6F63
movl $0x2074696d, 0x3(%rbx)  # imm = 0x2074696D
leaq 0x7(%rbx), %rdi
leaq 0x40(%rsp), %rsi
movq %r15, %rdx
callq 0x3150
xorl %eax, %eax
movb %al, -0x1(%r12)
leaq (%r14,%r15), %rcx
leaq (%r14,%r15), %rdx
addq $0x8, %rdx
movb %al, 0x8(%rbx,%rcx)
movq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x61e0
jmp 0x59c3
movq 0x8(%rsp), %rdi
callq 0x3595
jmp 0x59be
movq 0xa639(%rip), %rax      # 0xffd0
movq (%rax), %rdi
movq 0x8(%rsp), %rax
movq (%rax), %rdx
leaq 0x6786(%rip), %rsi      # 0xc12f
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3340
jmp 0x59be
movq 0x8(%rsp), %rdi
callq 0x3559
movl $0x1, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq