// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x8070, %rsp           # imm = 0x8070
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x48(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x8054(%rbp)
subl $0x1, %eax
je 0x66ba
jmp 0x66ad
movl -0x8054(%rbp), %eax
subl $0x2, %eax
je 0x66d8
jmp 0x66f6
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
leaq 0xe3b0c(%rip), %rdx     # 0xea1d9
callq 0x9080
movq %rax, -0x30(%rbp)
jmp 0x6712
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
leaq 0xe3aee(%rip), %rdx     # 0xea1d9
callq 0x91c0
movq %rax, -0x30(%rbp)
jmp 0x6712
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
leaq 0xe3ad0(%rip), %rdx     # 0xea1d9
callq 0x8b70
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x671e
jmp 0x69ca
cmpl $0x0, -0x20(%rbp)
jle 0x6741
movq -0x30(%rbp), %rdi
movl -0x20(%rbp), %esi
leaq 0xe3aa7(%rip), %rdx     # 0xea1d9
callq 0x92f0
cmpl $0x0, %eax
je 0x6741
jmp 0x69ca
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
leaq 0xe3a75(%rip), %r8      # 0xea1d9
callq 0x9370
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jge 0x6779
jmp 0x69ca
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
leaq -0x30(%rbp), %rdi
leaq 0xe3a4d(%rip), %rdx     # 0xea1d9
xorl %ecx, %ecx
callq 0x8c10
cmpl $0x0, %eax
je 0x679d
jmp 0x69ca
movl -0x1c(%rbp), %eax
movl %eax, -0x8058(%rbp)
subl $0x1, %eax
je 0x67ba
jmp 0x67ad
movl -0x8058(%rbp), %eax
subl $0x2, %eax
je 0x67db
jmp 0x67fc
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
leaq 0xe7db8(%rip), %rsi     # 0xee581
leaq 0xe3a09(%rip), %rdx     # 0xea1d9
callq 0x9080
movq %rax, -0x30(%rbp)
jmp 0x681b
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
leaq 0xe7d97(%rip), %rsi     # 0xee581
leaq 0xe39e8(%rip), %rdx     # 0xea1d9
callq 0x91c0
movq %rax, -0x30(%rbp)
jmp 0x681b
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
leaq 0xe7d76(%rip), %rsi     # 0xee581
leaq 0xe39c7(%rip), %rdx     # 0xea1d9
callq 0x8b70
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x6827
jmp 0x69ca
cmpl $0x0, -0x20(%rbp)
jle 0x684a
movq -0x30(%rbp), %rdi
movl -0x20(%rbp), %esi
leaq 0xe399e(%rip), %rdx     # 0xea1d9
callq 0x92f0
cmpl $0x0, %eax
je 0x684a
jmp 0x69ca
movq -0x30(%rbp), %rdi
movl -0x24(%rbp), %esi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0xe3979(%rip), %rcx     # 0xea1d9
callq 0x9430
cmpl $0x0, %eax
je 0x686f
jmp 0x69ca
jmp 0x6871
movq -0x30(%rbp), %rdi
leaq -0x8050(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movl $0x8000, %edx           # imm = 0x8000
leaq 0xe3949(%rip), %r8      # 0xea1d9
callq 0x8d30
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jge 0x68a5
jmp 0x69ca
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jae 0x6956
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x8068(%rbp)
leaq -0x8050(%rbp), %rax
movq %rax, -0x8060(%rbp)
movq -0x48(%rbp), %rax
addq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jae 0x68f7
movq -0x40(%rbp), %rax
movq %rax, -0x8070(%rbp)
jmp 0x690a
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
subq -0x48(%rbp), %rax
movq %rax, -0x8070(%rbp)
movq -0x8060(%rbp), %rsi
movq -0x8068(%rbp), %rdi
movq -0x8070(%rbp), %rdx
callq 0x41b0
cmpl $0x0, %eax
je 0x6956
movq 0x1016b0(%rip), %rax    # 0x107fe0
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x48(%rbp), %r8
leaq 0xe38a3(%rip), %rsi     # 0xea1e9
leaq 0xe388c(%rip), %rdx     # 0xea1d9
movb $0x0, %al
callq 0x46d0
jmp 0x69ca
movq -0x40(%rbp), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x40(%rbp)
jg 0x6871
movq -0x48(%rbp), %rax
cmpq -0x38(%rbp), %rax
je 0x69a0
movq 0x101662(%rip), %rax    # 0x107fe0
movq (%rax), %rdi
movq -0x48(%rbp), %rcx
movq -0x38(%rbp), %r8
leaq 0xe387f(%rip), %rsi     # 0xea20f
leaq 0xe3842(%rip), %rdx     # 0xea1d9
movb $0x0, %al
callq 0x46d0
jmp 0x69ca
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
leaq -0x30(%rbp), %rdi
leaq 0xe3826(%rip), %rdx     # 0xea1d9
xorl %ecx, %ecx
callq 0x8c10
cmpl $0x0, %eax
je 0x69c1
jmp 0x69ca
movl $0x0, -0x4(%rbp)
jmp 0x69e1
cmpq $0x0, -0x30(%rbp)
je 0x69da
movq -0x30(%rbp), %rdi
callq 0xe0e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x8070, %rsp           # imm = 0x8070
popq %rbp
retq
nopl (%rax)