// File: /workspace/github_c_makefile_star2_O1/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
xorl %eax, %eax
movq %rax, (%rsp)
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq 0x18(%rdi), %rdi
movq 0x40(%rbx), %r12
leaq 0x8f563(%rip), %rsi     # 0x97561
leaq 0x8c5c1(%rip), %rdx     # 0x945c6
callq 0x85b7
movq %rax, (%rsp)
testq %rax, %rax
je 0x8070
movq %rax, %r14
testl %ebp, %ebp
jle 0x802f
leaq 0x8c5a5(%rip), %rdx     # 0x945c6
movq %r14, %rdi
movl %ebp, %esi
callq 0x887e
testl %eax, %eax
jne 0x8070
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rsi
movq 0x48(%rbx), %rdx
leaq 0x8c584(%rip), %r8      # 0x945c6
movq %r14, %rdi
callq 0x88a5
testq %rax, %rax
js 0x8070
leaq 0x18(%rbx), %rax
movq %rax, 0x8(%rsp)
movq (%rax), %rsi
leaq 0x8c564(%rip), %rdx     # 0x945c6
movq %rsp, %rdi
xorl %ecx, %ecx
callq 0x861b
testl %eax, %eax
je 0x80af
movq (%rsp), %rdi
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x8083
callq 0xbc44
movq 0x20(%rsp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
callq 0x45b0
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x90286(%rip), %rsi     # 0x98344
leaq 0x8c501(%rip), %rdx     # 0x945c6
callq 0x85b7
movq %rax, (%rsp)
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x8070
testl %ebp, %ebp
jle 0x80f7
leaq 0x8c4e3(%rip), %rdx     # 0x945c6
movq 0x30(%rsp), %rdi
movl %ebp, %esi
callq 0x887e
testl %eax, %eax
jne 0x8070
xorl %r14d, %r14d
movq 0x48(%rbx), %r15
subq %r14, %r15
jbe 0x81b9
leaq (%r12,%r14), %rbp
movq %rbp, %rdi
movl $0xa, %esi
callq 0x4180
movq %rax, %r13
subq %rbp, %r13
testq %rax, %rax
cmoveq %r15, %r13
movq 0x30(%rsp), %rdi
movl $0xa, %esi
leaq 0x10(%rsp), %rdx
callq 0xc3cd
testl %eax, %eax
js 0x81a9
movq 0x10(%rsp), %r15
cmpq %r13, %r15
jne 0x816e
movq 0x20(%rsp), %rsi
movq %rbp, %rdi
movq %r13, %rdx
callq 0x44c0
testl %eax, %eax
jne 0x816e
addq %r13, %r14
incq %r14
movb $0x1, %bpl
testb %bpl, %bpl
jne 0x80fa
jmp 0x8070
movq 0xace6b(%rip), %rax     # 0xb4fe0
movq (%rax), %rdi
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %r9
addq %r14, %r9
xorl %ebp, %ebp
leaq 0x8c487(%rip), %rsi     # 0x94613
leaq 0x8c433(%rip), %rdx     # 0x945c6
movl %r13d, %r8d
xorl %eax, %eax
pushq 0x20(%rsp)
pushq %r15
callq 0x4700
addq $0x10, %rsp
jmp 0x8164
movl %eax, %edi
movq 0x8(%rsp), %rsi
callq 0x4a82
xorl %ebp, %ebp
jmp 0x8164
movq 0x8(%rsp), %rax
movq (%rax), %rsi
leaq 0x8c3fe(%rip), %rdx     # 0x945c6
movq %rsp, %rdi
xorl %ebx, %ebx
xorl %ecx, %ecx
callq 0x861b
testl %eax, %eax
jne 0x8070
jmp 0x8083