// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/test/test_bgzf.c
// Function: test_bgzf_getline
static int test_bgzf_getline(Files *f, const char *mode, int nthreads) {
    BGZF* bgz = NULL;
    ssize_t bg_put;
    size_t pos;
    kstring_t str = { 0, 0, NULL };
    const char *text = (const char *) f->text;

    bgz = try_bgzf_open(f->tmp_bgzf, mode, __func__);
    if (!bgz) goto fail;

    if (nthreads > 0 && try_bgzf_mt(bgz, nthreads, __func__) != 0) goto fail;

    bg_put = try_bgzf_write(bgz, f->text, f->ltext, f->tmp_bgzf, __func__);
    if (bg_put < 0) goto fail;

    if (try_bgzf_close(&bgz, f->tmp_bgzf, __func__, 0) != 0) goto fail;

    bgz = try_bgzf_open(f->tmp_bgzf, "r", __func__);
    if (!bgz) goto fail;

    if (nthreads > 0 && try_bgzf_mt(bgz, nthreads, __func__) != 0) goto fail;

    for (pos = 0; pos < f->ltext; ) {
        const char *end = strchr(text + pos, '\n');
        size_t l = end ? end - (text + pos) : f->ltext - pos;
        int res;

        if ((res = bgzf_getline(bgz, '\n', &str)) < 0) {
            fprintf(stderr, "%s : %s from bgzf_getline on %s : %s\n",
                    __func__, res < -1 ? "Error" : "Unexpected EOF",
                    f->tmp_bgzf, res < -1 ? strerror(errno) : "EOF");
            goto fail;
        }

        if (str.l != l || memcmp(text + pos, str.s, l) != 0) {
            fprintf(stderr,
                    "%s : Unexpected data from bgzf_getline on %s\n"
                    "Expected : %.*s\n"
                    "Got      : %.*s\n",
                    __func__, f->tmp_bgzf, (int) l, (char *) f->text + pos,
                    (int) str.l, str.s);
            goto fail;
        }

        pos += l + 1;
    }

    if (try_bgzf_close(&bgz, f->tmp_bgzf, __func__, 0) != 0) goto fail;
    free(ks_release(&str));
    return 0;

 fail:
    if (bgz) bgzf_close(bgz);
    free(ks_release(&str));
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %ebp
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x18(%rdi), %rdi
movq 0x40(%rbx), %r15
leaq 0x8c44f(%rip), %rsi     # 0x94511
leaq 0x89519(%rip), %rdx     # 0x915e2
callq 0x865e
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x8141
movq %rax, %r14
testl %ebp, %ebp
jle 0x80f4
leaq 0x894fc(%rip), %rdx     # 0x915e2
movq %r14, %rdi
movl %ebp, %esi
callq 0x8915
testl %eax, %eax
jne 0x8132
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rsi
movq 0x48(%rbx), %rdx
leaq 0x894db(%rip), %r8      # 0x915e2
movq %r14, %rdi
callq 0x893c
testq %rax, %rax
js 0x8132
leaq 0x18(%rbx), %r14
movq (%r14), %rsi
leaq 0x894c0(%rip), %rdx     # 0x915e2
leaq 0x8(%rsp), %rdi
xorl %ecx, %ecx
callq 0x86bf
testl %eax, %eax
je 0x8172
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x8141
callq 0xbb59
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x30(%rsp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
callq 0x45b0
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rdi
leaq 0x8d16f(%rip), %rsi     # 0x952eb
leaq 0x8945f(%rip), %rdx     # 0x915e2
callq 0x865e
movq %rax, 0x8(%rsp)
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x8141
testl %ebp, %ebp
jle 0x81b2
leaq 0x89440(%rip), %rdx     # 0x915e2
movq 0x18(%rsp), %rdi
movl %ebp, %esi
callq 0x8915
testl %eax, %eax
jne 0x8132
movq %r14, 0x10(%rsp)
movq 0x48(%rbx), %r12
testq %r12, %r12
je 0x822c
xorl %r13d, %r13d
leaq (%r15,%r13), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x4180
movq %rax, %rcx
subq %r14, %rcx
subq %r13, %r12
testq %rax, %rax
cmovneq %rcx, %r12
movq 0x18(%rsp), %rdi
movl $0xa, %esi
leaq 0x20(%rsp), %rdx
callq 0xc2fc
testl %eax, %eax
js 0x8256
movq 0x20(%rsp), %r10
movq 0x30(%rsp), %rbp
cmpq %r12, %r10
jne 0x826a
movq %r14, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x44c0
testl %eax, %eax
jne 0x8267
addq %r12, %r13
incq %r13
movq 0x48(%rbx), %r12
cmpq %r12, %r13
jb 0x81c3
movq 0x10(%rsp), %rax
movq (%rax), %rsi
leaq 0x893a7(%rip), %rdx     # 0x915e2
leaq 0x8(%rsp), %rdi
xorl %ebx, %ebx
xorl %ecx, %ecx
callq 0x86bf
testl %eax, %eax
jne 0x8132
jmp 0x8146
movl %eax, %edi
movq 0x10(%rsp), %rsi
callq 0x4afe
jmp 0x8132
movq %r12, %r10
movq 0xaad6f(%rip), %rax     # 0xb2fe0
movq (%rax), %rdi
movq 0x18(%rbx), %rcx
addq 0x40(%rbx), %r13
leaq 0x893ac(%rip), %rsi     # 0x9162f
leaq 0x89358(%rip), %rdx     # 0x915e2
movl %r12d, %r8d
movq %r13, %r9
xorl %eax, %eax
pushq %rbp
pushq %r10
callq 0x4700
addq $0x10, %rsp
jmp 0x8132