// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/test/test_bgzf.c
// Function: test_write_read
static int test_write_read(Files *f, const char *mode, Open_method method,
                           int nthreads, int expected_compression) {
    BGZF* bgz = NULL;
    ssize_t bg_put, bg_got;
    size_t pos = 0;
    unsigned char bg_buf[BUFSZ];

    switch (method) {
    case USE_BGZF_DOPEN:
        bgz = try_bgzf_dopen(f->tmp_bgzf, mode, __func__);
        break;
    case USE_BGZF_HOPEN:
        bgz = try_bgzf_hopen(f->tmp_bgzf, mode, __func__);
        break;
    default:
        bgz = try_bgzf_open(f->tmp_bgzf, mode, __func__);
        break;
    }
    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;

    switch (method) {
    case USE_BGZF_DOPEN:
        bgz = try_bgzf_dopen(f->tmp_bgzf, "r", __func__);
        break;
    case USE_BGZF_HOPEN:
        bgz = try_bgzf_hopen(f->tmp_bgzf, "r", __func__);
        break;
    default:
        bgz = try_bgzf_open(f->tmp_bgzf, "r", __func__);
        break;
    }
    if (!bgz) goto fail;

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

    if (try_bgzf_compression(bgz, expected_compression,
                             f->tmp_bgzf, __func__) != 0) {
        goto fail;
    }

    do {
        bg_got = try_bgzf_read(bgz, bg_buf, BUFSZ, f->tmp_bgzf, __func__);
        if (bg_got < 0) goto fail;

        if (pos < f->ltext &&
            memcmp(f->text + pos, bg_buf,
                   pos + bg_got < f->ltext ? bg_got : f->ltext - pos) != 0) {
            fprintf(stderr, "%s : Got wrong data from %s, pos %zu\n",
                    __func__, f->tmp_bgzf, pos);
            goto fail;
        }
        pos += bg_got;
    } while (bg_got > 0);

    if (pos != bg_put) {
        fprintf(stderr, "%s : bgzf_read got %zd bytes; expected %zd\n",
                __func__, pos, bg_put);
        goto fail;
    }

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

    return 0;

 fail:
    if (bgz) bgzf_close(bgz);
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x8018, %rsp           # imm = 0x8018
movl %r8d, %ebp
movl %ecx, %r15d
movl %edx, %r12d
movq %rdi, %rbx
movq 0x18(%rdi), %rdi
cmpl $0x2, %edx
je 0x6676
cmpl $0x1, %r12d
jne 0x667d
callq 0x7f8f
jmp 0x6689
callq 0x805c
jmp 0x6689
leaq 0x6db55(%rip), %rdx     # 0x741d9
callq 0x7d08
movq %rax, %r14
movq %rax, (%rsp)
testq %rax, %rax
je 0x66ee
testl %r15d, %r15d
jle 0x66b0
leaq 0x6db38(%rip), %rdx     # 0x741d9
movq %r14, %rdi
movl %r15d, %esi
callq 0x811d
testl %eax, %eax
jne 0x66ee
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rsi
movq 0x48(%rbx), %rdx
leaq 0x6db16(%rip), %r8      # 0x741d9
movq %r14, %rdi
callq 0x816e
movq %rax, 0x8(%rsp)
testq %rax, %rax
js 0x66ee
movq 0x18(%rbx), %rsi
leaq 0x6daf9(%rip), %rdx     # 0x741d9
movq %rsp, %rdi
xorl %ecx, %ecx
callq 0x7d69
testl %eax, %eax
je 0x6713
movq (%rsp), %rdi
pushq $-0x1
popq %rbx
testq %rdi, %rdi
je 0x66ff
callq 0xad16
movl %ebx, %eax
addq $0x8018, %rsp           # imm = 0x8018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rbx), %rdi
leaq 0x71b78(%rip), %rsi     # 0x78296
cmpl $0x2, %r12d
je 0x6731
cmpl $0x1, %r12d
jne 0x6738
callq 0x7f8f
jmp 0x6744
callq 0x805c
jmp 0x6744
leaq 0x6da9a(%rip), %rdx     # 0x741d9
callq 0x7d08
movq %rax, %r12
movq %rax, (%rsp)
testq %rax, %rax
je 0x66ee
testl %r15d, %r15d
jle 0x676b
leaq 0x6da7d(%rip), %rdx     # 0x741d9
movq %r12, %rdi
movl %r15d, %esi
callq 0x811d
testl %eax, %eax
jne 0x66ee
movq 0x18(%rbx), %r14
movq %r12, %rdi
callq 0xb298
cmpl %ebp, %eax
jne 0x6819
xorl %r15d, %r15d
leaq 0x10(%rsp), %rbp
movq 0x18(%rbx), %rcx
movl $0x8000, %edx           # imm = 0x8000
movq %r12, %rdi
movq %rbp, %rsi
leaq 0x6da3c(%rip), %r8      # 0x741d9
callq 0x7e14
testq %rax, %rax
js 0x66ee
movq %rax, %r14
movq 0x48(%rbx), %rax
movq %rax, %rdx
subq %r15, %rdx
jbe 0x67dd
movq 0x40(%rbx), %rdi
addq %r15, %rdi
leaq (%r14,%r15), %r13
cmpq %rax, %r13
cmovbq %r14, %rdx
movq %rbp, %rsi
callq 0x44c0
testl %eax, %eax
je 0x67e3
jmp 0x6862
addq %r14, %r15
movq %r15, %r13
movq %r13, %r15
testq %r14, %r14
jne 0x6787
movq 0x8(%rsp), %r8
cmpq %r8, %r13
jne 0x6845
movq 0x18(%rbx), %rsi
leaq 0x6d9d9(%rip), %rdx     # 0x741d9
movq %rsp, %rdi
xorl %ebx, %ebx
xorl %ecx, %ecx
callq 0x7d69
testl %eax, %eax
jne 0x66ee
jmp 0x66ff
movq 0x947c0(%rip), %rcx     # 0x9afe0
movq (%rcx), %rdi
leaq 0x6db06(%rip), %rsi     # 0x74330
leaq 0x6d9a8(%rip), %rdx     # 0x741d9
movl %eax, %ecx
movq %r14, %r8
movl %ebp, %r9d
xorl %eax, %eax
callq 0x4700
jmp 0x66ee
movq 0x94794(%rip), %rax     # 0x9afe0
movq (%rax), %rdi
leaq 0x6d9b9(%rip), %rsi     # 0x7420f
leaq 0x6d97c(%rip), %rdx     # 0x741d9
movq %r13, %rcx
jmp 0x6881
movq 0x94777(%rip), %rax     # 0x9afe0
movq (%rax), %rdi
movq 0x18(%rbx), %rcx
leaq 0x6d972(%rip), %rsi     # 0x741e9
leaq 0x6d95b(%rip), %rdx     # 0x741d9
movq %r15, %r8
xorl %eax, %eax
callq 0x4700
jmp 0x66ee