// File: /workspace/github_c_makefile_star2_O2/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, %r15
andq $0x0, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq 0x18(%rdi), %rdi
movq 0x40(%r15), %r12
leaq 0x6fdbe(%rip), %rsi     # 0x774b1
leaq 0x6cecc(%rip), %rdx     # 0x745c6
callq 0x7d08
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x776f
movq %rax, %r14
testl %ebp, %ebp
jle 0x7725
leaq 0x6ceaf(%rip), %rdx     # 0x745c6
movq %r14, %rdi
movl %ebp, %esi
callq 0x811d
testl %eax, %eax
jne 0x7760
movq 0x18(%r15), %rcx
movq 0x40(%r15), %rsi
movq 0x48(%r15), %rdx
leaq 0x6ce8e(%rip), %r8      # 0x745c6
movq %r14, %rdi
callq 0x816e
testq %rax, %rax
js 0x7760
movq 0x18(%r15), %rsi
leaq 0x6ce76(%rip), %rdx     # 0x745c6
leaq 0x8(%rsp), %rdi
xorl %ecx, %ecx
callq 0x7d69
testl %eax, %eax
je 0x779b
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x776f
callq 0xad16
pushq $-0x1
popq %rbx
movq 0x30(%rsp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
andq $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 0x18(%r15), %rdi
leaq 0x70af0(%rip), %rsi     # 0x78296
leaq 0x6ce19(%rip), %rdx     # 0x745c6
callq 0x7d08
movq %rax, 0x8(%rsp)
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x776f
testl %ebp, %ebp
jle 0x77dc
leaq 0x6cdfa(%rip), %rdx     # 0x745c6
movq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x811d
testl %eax, %eax
jne 0x7760
xorl %eax, %eax
pushq $0xa
popq %rbx
movq 0x48(%r15), %r13
subq %rax, %r13
jbe 0x7853
movq %r12, %rbp
movq %rax, 0x18(%rsp)
leaq (%r12,%rax), %r14
movq %r14, %rdi
movl %ebx, %esi
callq 0x4180
movq %rax, %r12
subq %r14, %r12
testq %rax, %rax
cmoveq %r13, %r12
movq 0x10(%rsp), %rdi
movl %ebx, %esi
leaq 0x20(%rsp), %rdx
callq 0xb32b
testl %eax, %eax
js 0x7879
movq 0x20(%rsp), %r10
movq 0x30(%rsp), %r13
cmpq %r12, %r10
jne 0x78aa
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x44c0
testl %eax, %eax
jne 0x78a7
movq 0x18(%rsp), %rax
addq %r12, %rax
incq %rax
movq %rbp, %r12
jmp 0x77e1
movq 0x18(%r15), %rsi
leaq 0x6cd68(%rip), %rdx     # 0x745c6
leaq 0x8(%rsp), %rdi
xorl %ebx, %ebx
xorl %ecx, %ecx
callq 0x7d69
testl %eax, %eax
jne 0x7760
jmp 0x7772
movq 0x93760(%rip), %rcx     # 0x9afe0
movq (%rcx), %r14
leaq 0x6cd7a(%rip), %rcx     # 0x74604
leaq 0x6cd6d(%rip), %r12     # 0x745fe
movq 0x18(%r15), %rbx
cmpl $-0x1, %eax
cmoveq %rcx, %r12
jne 0x78e4
leaq 0x6cd6a(%rip), %r9      # 0x7460f
jmp 0x78f3
movq %r12, %r10
movq 0x9372f(%rip), %rax     # 0x9afe0
movq (%rax), %rdi
movq 0x18(%r15), %rcx
movq 0x18(%rsp), %r9
addq 0x40(%r15), %r9
leaq 0x6cd4b(%rip), %rsi     # 0x74613
leaq 0x6ccf7(%rip), %rdx     # 0x745c6
movl %r12d, %r8d
xorl %eax, %eax
pushq %r13
pushq %r10
callq 0x4700
popq %rcx
popq %rdx
jmp 0x7760
callq 0x4050
movl (%rax), %edi
callq 0x4140
movq %rax, %r9
leaq 0x6ccde(%rip), %rsi     # 0x745d8
leaq 0x6ccc5(%rip), %rdx     # 0x745c6
movq %r14, %rdi
movq %r12, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x4700
jmp 0x7760