// File: /workspace/github_c_makefile_star2_O3/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 0x6ee3
cmpl $0x1, %r12d
jne 0x6eea
callq 0x886b
jmp 0x6ef6
callq 0x88c6
jmp 0x6ef6
leaq 0x8a304(%rip), %rdx     # 0x911f5
callq 0x865e
movq %rax, %r14
movq %rax, (%rsp)
testq %rax, %rax
je 0x6f5b
testl %r15d, %r15d
jle 0x6f1d
leaq 0x8a2e7(%rip), %rdx     # 0x911f5
movq %r14, %rdi
movl %r15d, %esi
callq 0x8915
testl %eax, %eax
jne 0x6f5b
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rsi
movq 0x48(%rbx), %rdx
leaq 0x8a2c5(%rip), %r8      # 0x911f5
movq %r14, %rdi
callq 0x893c
movq %rax, 0x8(%rsp)
testq %rax, %rax
js 0x6f5b
movq 0x18(%rbx), %rsi
leaq 0x8a2a8(%rip), %rdx     # 0x911f5
movq %rsp, %rdi
xorl %ecx, %ecx
callq 0x86bf
testl %eax, %eax
je 0x6f82
movq (%rsp), %rdi
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x6f6e
callq 0xbb59
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 0x8e35e(%rip), %rsi     # 0x952eb
cmpl $0x2, %r12d
je 0x6fa0
cmpl $0x1, %r12d
jne 0x6fa7
callq 0x886b
jmp 0x6fb3
callq 0x88c6
jmp 0x6fb3
leaq 0x8a247(%rip), %rdx     # 0x911f5
callq 0x865e
movq %rax, %r12
movq %rax, (%rsp)
testq %rax, %rax
je 0x6f5b
testl %r15d, %r15d
jle 0x6fda
leaq 0x8a22a(%rip), %rdx     # 0x911f5
movq %r12, %rdi
movl %r15d, %esi
callq 0x8915
testl %eax, %eax
jne 0x6f5b
movq 0x18(%rbx), %r14
movq %r12, %rdi
callq 0xc264
cmpl %ebp, %eax
jne 0x7088
xorl %r15d, %r15d
leaq 0x10(%rsp), %rbp
movq 0x18(%rbx), %rcx
movl $0x8000, %edx           # imm = 0x8000
movq %r12, %rdi
movq %rbp, %rsi
leaq 0x8a1e9(%rip), %r8      # 0x911f5
callq 0x8732
testq %rax, %rax
js 0x6f5b
movq %rax, %r14
movq 0x48(%rbx), %rax
movq %rax, %rdx
subq %r15, %rdx
jbe 0x704c
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 0x7052
jmp 0x70d1
addq %r14, %r15
movq %r15, %r13
movq %r13, %r15
testq %r14, %r14
jne 0x6ff6
movq 0x8(%rsp), %r8
cmpq %r8, %r13
jne 0x70b4
movq 0x18(%rbx), %rsi
leaq 0x8a186(%rip), %rdx     # 0x911f5
movq %rsp, %rdi
xorl %ebx, %ebx
xorl %ecx, %ecx
callq 0x86bf
testl %eax, %eax
jne 0x6f5b
jmp 0x6f6e
movq 0xabf51(%rip), %rcx     # 0xb2fe0
movq (%rcx), %rdi
leaq 0x8a2b3(%rip), %rsi     # 0x9134c
leaq 0x8a155(%rip), %rdx     # 0x911f5
movl %eax, %ecx
movq %r14, %r8
movl %ebp, %r9d
xorl %eax, %eax
callq 0x4700
jmp 0x6f5b
movq 0xabf25(%rip), %rax     # 0xb2fe0
movq (%rax), %rdi
leaq 0x8a166(%rip), %rsi     # 0x9122b
leaq 0x8a129(%rip), %rdx     # 0x911f5
movq %r13, %rcx
jmp 0x70f0
movq 0xabf08(%rip), %rax     # 0xb2fe0
movq (%rax), %rdi
movq 0x18(%rbx), %rcx
leaq 0x8a11f(%rip), %rsi     # 0x91205
leaq 0x8a108(%rip), %rdx     # 0x911f5
movq %r15, %r8
xorl %eax, %eax
callq 0x4700
jmp 0x6f5b