// File: /workspace/github_c_makefile_star2_O1/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 $0x0, 0x8(%rsp)
movq 0x18(%rdi), %rdi
cmpl $0x2, %edx
je 0x6dbe
cmpl $0x1, %r12d
jne 0x6dc5
callq 0x87d4
jmp 0x6dd1
callq 0x882f
jmp 0x6dd1
leaq 0x8d40d(%rip), %rdx     # 0x941d9
callq 0x85b7
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %r14
testq %r14, %r14
je 0x6e39
testl %r15d, %r15d
jle 0x6dfb
leaq 0x8d3ed(%rip), %rdx     # 0x941d9
movq %r14, %rdi
movl %r15d, %esi
callq 0x887e
testl %eax, %eax
jne 0x6e39
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rsi
movq 0x48(%rbx), %rdx
leaq 0x8d3cb(%rip), %r8      # 0x941d9
movq %r14, %rdi
callq 0x88a5
testq %rax, %rax
js 0x6e39
movq %rax, %r14
movq 0x18(%rbx), %rsi
leaq 0x8d3b0(%rip), %rdx     # 0x941d9
leaq 0x8(%rsp), %rdi
xorl %ecx, %ecx
callq 0x861b
testl %eax, %eax
je 0x6e61
movq 0x8(%rsp), %rdi
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x6e4d
callq 0xbc44
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 0x914d8(%rip), %rsi     # 0x98344
cmpl $0x2, %r12d
je 0x6e7f
cmpl $0x1, %r12d
jne 0x6e86
callq 0x87d4
jmp 0x6e92
callq 0x882f
jmp 0x6e92
leaq 0x8d34c(%rip), %rdx     # 0x941d9
callq 0x85b7
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %r12
testq %r12, %r12
je 0x6e39
testl %r15d, %r15d
jle 0x6ec0
leaq 0x8d32c(%rip), %rdx     # 0x941d9
movq %r12, %rdi
movl %r15d, %esi
callq 0x887e
testl %eax, %eax
jne 0x6e39
movq 0x18(%rbx), %r15
movq %r12, %rdi
callq 0xc33b
cmpl %ebp, %eax
jne 0x6f60
xorl %r15d, %r15d
leaq 0x10(%rsp), %rbp
movq 0x18(%rbx), %rcx
movl $0x8000, %edx           # imm = 0x8000
movq %r12, %rdi
movq %rbp, %rsi
leaq 0x8d2e7(%rip), %r8      # 0x941d9
callq 0x868e
testq %rax, %rax
js 0x6e39
movq %rax, %r13
movq 0x48(%rbx), %rax
movq %rax, %rdx
subq %r15, %rdx
jbe 0x6f2d
movq 0x40(%rbx), %rdi
addq %r15, %rdi
leaq (%r15,%r13), %rcx
cmpq %rax, %rcx
cmovbq %r13, %rdx
movq %rbp, %rsi
callq 0x44c0
testl %eax, %eax
jne 0x6fac
addq %r13, %r15
testq %r13, %r13
jne 0x6edc
cmpq %r14, %r15
jne 0x6f8c
movq 0x18(%rbx), %rsi
leaq 0x8d294(%rip), %rdx     # 0x941d9
leaq 0x8(%rsp), %rdi
xorl %ebx, %ebx
xorl %ecx, %ecx
callq 0x861b
testl %eax, %eax
jne 0x6e39
jmp 0x6e4d
movq 0xae079(%rip), %rcx     # 0xb4fe0
movq (%rcx), %rdi
leaq 0x8d3bf(%rip), %rsi     # 0x94330
leaq 0x8d261(%rip), %rdx     # 0x941d9
movl %eax, %ecx
movq %r15, %r8
movl %ebp, %r9d
xorl %eax, %eax
callq 0x4700
jmp 0x6e39
movq 0xae04d(%rip), %rax     # 0xb4fe0
movq (%rax), %rdi
leaq 0x8d272(%rip), %rsi     # 0x9420f
leaq 0x8d235(%rip), %rdx     # 0x941d9
movq %r15, %rcx
movq %r14, %r8
jmp 0x6fcb
movq 0xae02d(%rip), %rax     # 0xb4fe0
movq (%rax), %rdi
movq 0x18(%rbx), %rcx
leaq 0x8d228(%rip), %rsi     # 0x941e9
leaq 0x8d211(%rip), %rdx     # 0x941d9
movq %r15, %r8
xorl %eax, %eax
callq 0x4700
jmp 0x6e39