// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/hfile.c
// Function: hgetdelim
ssize_t hgetdelim(char *buffer, size_t size, int delim, hFILE *fp)
{
    char *found;
    size_t n, copied = 0;
    ssize_t got;

    if (size < 1 || size > SSIZE_MAX) {
        fp->has_errno = errno = EINVAL;
        return -1;
    }
    if (writebuffer_is_nonempty(fp)) {
        fp->has_errno = errno = EBADF;
        return -1;
    }

    --size; /* to allow space for the NUL terminator */

    do {
        n = fp->end - fp->begin;
        if (n > size - copied) n = size - copied;

        /* Look in the hFILE buffer for the delimiter */
        found = memchr(fp->begin, delim, n);
        if (found != NULL) {
            n = found - fp->begin + 1;
            memcpy(buffer + copied, fp->begin, n);
            buffer[n + copied] = '\0';
            fp->begin += n;
            return n + copied;
        }

        /* No delimiter yet, copy as much as we can and refill if necessary */
        memcpy(buffer + copied, fp->begin, n);
        fp->begin += n;
        copied += n;

        if (copied == size) { /* Output buffer full */
            buffer[copied] = '\0';
            return copied;
        }

        got = refill_buffer(fp);
    } while (got > 0);

    if (got < 0) return -1; /* Error on refill. */

    buffer[copied] = '\0';  /* EOF, return anything that was copied. */
    return copied;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq $0x0, -0x40(%rbp)
cmpq $0x1, -0x18(%rbp)
jb 0x13e16
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
cmpq %rax, -0x18(%rbp)
jbe 0x13e39
callq 0x4050
movl $0x16, (%rax)
movq -0x28(%rbp), %rax
movl $0x16, 0x34(%rax)
movq $-0x1, -0x8(%rbp)
jmp 0x13fbc
movq -0x28(%rbp), %rdi
callq 0x13fd0
cmpl $0x0, %eax
je 0x13e6a
callq 0x4050
movl $0x9, (%rax)
movq -0x28(%rbp), %rax
movl $0x9, 0x34(%rax)
movq $-0x1, -0x8(%rbp)
jmp 0x13fbc
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
subq -0x40(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x13eaa
movq -0x18(%rbp), %rax
subq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x1c(%rbp), %esi
movq -0x38(%rbp), %rdx
callq 0x4530
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x13f2a
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq %rcx, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
addq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x38(%rbp), %rdx
callq 0x43b0
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
addq -0x40(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x13fbc
movq -0x10(%rbp), %rdi
addq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x38(%rbp), %rdx
callq 0x43b0
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
jne 0x13f7f
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x13fbc
movq -0x28(%rbp), %rdi
callq 0x13c70
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jg 0x13e76
cmpq $0x0, -0x48(%rbp)
jge 0x13fa8
movq $-0x1, -0x8(%rbp)
jmp 0x13fbc
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)