// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/test/test_bgzf.c
// Function: test_index_useek_getc
static int test_index_useek_getc(Files *f, const char *mode,
                                 int cache_size, int nthreads) {
    BGZF* bgz = NULL;
    ssize_t bg_put;
    size_t i, j, k, iskip = f->ltext / 10;
    int is_uncompressed = strchr(mode, 'u') != NULL;
    size_t offsets[3] = { 0, 100, 50 };

    bgz = try_bgzf_open(f->tmp_bgzf, mode, __func__);
    if (!bgz) goto fail;

    if (try_bgzf_index_build_init(bgz, f->tmp_bgzf, __func__) != 0) 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 (!is_uncompressed) {
        if (try_bgzf_index_dump(bgz, f->tmp_idx, NULL, __func__) != 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;

    if (!is_uncompressed) {
        if (try_bgzf_index_load(bgz, f->tmp_bgzf, idx_suffix, __func__) != 0) {
            goto fail;
        }
    }

    for (i = 0; i < f->ltext; i += iskip) {
        for (k = 0; k < sizeof(offsets) / sizeof(offsets[0]); k++) {
            size_t o = offsets[k];
            if (try_bgzf_useek(bgz, i + o, SEEK_SET, f->tmp_bgzf, __func__) != 0) {
                goto fail;
            }

            for (j = 0; j < 16 && i + o + j < f->ltext; j++) {
                if (try_bgzf_getc(bgz, i + o + j, f->text[i + o + j],
                                  f->tmp_bgzf, __func__) < 0) goto fail;
            }
        }
    }

    if (try_bgzf_useek(bgz, 0, SEEK_SET, f->tmp_bgzf, __func__) != 0) {
        goto fail;
    }
    for (j = 0; j < 70000 && j < f->ltext; j++) { // Should force a block load
        if (try_bgzf_getc(bgz, j, f->text[j],
                          f->tmp_bgzf, __func__) < 0) goto fail;
    }

    if (cache_size > 0) {
        size_t mid = f->ltext / 2;
        bgzf_set_cache_size(bgz, cache_size);

        for (i = 0; i < 10; i++) {
            if (try_bgzf_useek(bgz, 0, SEEK_SET, f->tmp_bgzf, __func__) != 0) {
                goto fail;
            }
            for (j = 0; j < 64 && j < f->ltext; j++) {
                if (try_bgzf_getc(bgz, j, f->text[j],
                                  f->tmp_bgzf, __func__) < 0) goto fail;
            }

            if (try_bgzf_useek(bgz, mid, SEEK_SET,
                               f->tmp_bgzf, __func__) != 0) {
                goto fail;
            }
            for (j = 0; j < 64 && j + mid < f->ltext; j++) {
                if (try_bgzf_getc(bgz, j + mid, f->text[j + mid],
                                  f->tmp_bgzf, __func__) < 0) 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 $0x28, %rsp
movl %ecx, %r12d
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x48(%rdi), %rax
pushq $0xa
popq %rcx
xorl %edx, %edx
divq %rcx
movq %rax, %r15
pushq $0x75
popq %rsi
movq %r14, %rdi
callq 0x4180
movq %rax, %r13
movq 0x18(%rbx), %rdi
leaq 0x6d897(%rip), %rdx     # 0x74409
movq %r14, %rsi
callq 0x7d08
movq %rax, %r14
movq %rax, 0x10(%rsp)
pushq $-0x1
popq %rax
testq %r14, %r14
je 0x6cf8
movl %ebp, 0x1c(%rsp)
movq 0x18(%rbx), %rbp
movq %r14, %rdi
callq 0xb4fb
testl %eax, %eax
jne 0x6d1a
testl %r12d, %r12d
jle 0x6bc5
leaq 0x6d857(%rip), %rdx     # 0x74409
movq %r14, %rdi
movl %r12d, %esi
callq 0x811d
testl %eax, %eax
jne 0x6d4e
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rsi
movq 0x48(%rbx), %rdx
leaq 0x6d831(%rip), %r8      # 0x74409
movq %r14, %rdi
callq 0x816e
testq %rax, %rax
js 0x6d4e
testq %r13, %r13
je 0x6cfc
movq 0x18(%rbx), %rsi
leaq 0x6d80c(%rip), %rdx     # 0x74409
leaq 0x10(%rsp), %rdi
xorl %ecx, %ecx
callq 0x7d69
testl %eax, %eax
jne 0x6d4e
movq 0x18(%rbx), %rdi
leaq 0x7167a(%rip), %rsi     # 0x78296
leaq 0x6d7e6(%rip), %rdx     # 0x74409
callq 0x7d08
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x6d5d
movq %rax, %r14
testl %r12d, %r12d
jle 0x6c58
leaq 0x6d7c4(%rip), %rdx     # 0x74409
movq %r14, %rdi
movl %r12d, %esi
callq 0x811d
testl %eax, %eax
jne 0x6d4e
testq %r13, %r13
je 0x6d71
xorl %eax, %eax
leaq 0x6d79f(%rip), %r12     # 0x74409
cmpq 0x48(%rbx), %rax
jae 0x6d94
xorl %edx, %edx
movq %rax, 0x20(%rsp)
cmpq $0x3, %rdx
je 0x6cf0
leaq 0x6da48(%rip), %rcx     # 0x746d0
movq %rdx, 0x8(%rsp)
movq (%rcx,%rdx,8), %r13
addq %rax, %r13
movq 0x18(%rbx), %rdx
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rcx
callq 0x82fc
testl %eax, %eax
jne 0x6d4e
pushq $0x10
popq %rbp
subq $0x1, %rbp
jb 0x6ce1
cmpq 0x48(%rbx), %r13
jae 0x6ce1
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rax
movzbl (%rax,%r13), %edx
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %r8
callq 0x8369
incq %r13
testl %eax, %eax
jns 0x6cb1
jmp 0x6d4e
movq 0x8(%rsp), %rdx
incq %rdx
movq 0x20(%rsp), %rax
jmp 0x6c7b
addq %r15, %rax
jmp 0x6c6a
movl %eax, %ebx
jmp 0x6d60
movq 0x20(%rbx), %rsi
leaq 0x6d702(%rip), %rcx     # 0x74409
movq %r14, %rdi
xorl %edx, %edx
callq 0x828d
testl %eax, %eax
jne 0x6d4e
jmp 0x6bf2
movq 0x942bf(%rip), %rax     # 0x9afe0
movq (%rax), %rbx
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0x6d6e8(%rip), %rsi     # 0x7441f
leaq 0x6d6cb(%rip), %rdx     # 0x74409
movq %rbx, %rdi
movq %rbp, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x4700
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x6d5d
callq 0xad16
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rbx), %rsi
movq 0x9477c(%rip), %rdx     # 0x9b4f8
leaq 0x6d686(%rip), %rcx     # 0x74409
movq %r14, %rdi
callq 0x821e
testl %eax, %eax
jne 0x6d4e
jmp 0x6c61
movq 0x18(%rbx), %rdx
leaq 0x6d66a(%rip), %rcx     # 0x74409
movq %r14, %rdi
xorl %esi, %esi
callq 0x82fc
testl %eax, %eax
jne 0x6d4e
xorl %r15d, %r15d
leaq 0x6d652(%rip), %r12     # 0x74409
cmpq $0x11170, %r15          # imm = 0x11170
je 0x6ded
cmpq 0x48(%rbx), %r15
jae 0x6ded
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rax
movzbl (%rax,%r15), %edx
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %r8
callq 0x8369
incq %r15
testl %eax, %eax
jns 0x6db7
jmp 0x6d4e
movl 0x1c(%rsp), %esi
testl %esi, %esi
jle 0x6ed4
movq 0x48(%rbx), %rax
shrq %rax
movq %rax, 0x8(%rsp)
movq %r14, %rdi
callq 0xaf45
xorl %eax, %eax
leaq 0x6d5f3(%rip), %r12     # 0x74409
cmpq $0xa, %rax
je 0x6ed4
movq %rax, %r15
movq 0x18(%rbx), %rdx
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rcx
callq 0x82fc
testl %eax, %eax
jne 0x6d4e
xorl %r13d, %r13d
cmpq $0x40, %r13
je 0x6e72
cmpq 0x48(%rbx), %r13
jae 0x6e72
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rax
movzbl (%rax,%r13), %edx
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %r8
callq 0x8369
incq %r13
testl %eax, %eax
jns 0x6e3f
jmp 0x6d4e
movq 0x18(%rbx), %rdx
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rcx
callq 0x82fc
testl %eax, %eax
jne 0x6d4e
movq 0x8(%rsp), %r13
pushq $0x40
popq %rbp
subq $0x1, %rbp
jb 0x6ec9
cmpq 0x48(%rbx), %r13
jae 0x6ec9
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rax
movzbl (%rax,%r13), %edx
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %r8
callq 0x8369
incq %r13
testl %eax, %eax
jns 0x6e96
jmp 0x6d4e
movq %r15, %rax
incq %rax
jmp 0x6e16
movq 0x18(%rbx), %rsi
leaq 0x6d52a(%rip), %rdx     # 0x74409
leaq 0x10(%rsp), %rdi
xorl %ebx, %ebx
xorl %ecx, %ecx
callq 0x7d69
testl %eax, %eax
jne 0x6d4e
jmp 0x6d60