// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/test/test_bgzf.c
// Function: test_tell_seek_getc
static int test_tell_seek_getc(Files *f, const char *mode,
                               int cache_size, int nthreads) {

    BGZF* bgz = NULL;
    ssize_t bg_put;
    size_t num_points = 10;
    size_t i, j, k, iskip = f->ltext / num_points;
    size_t offsets[3] = { 0, 100, 50 };
    size_t points[num_points];
    int64_t point_vos[num_points];

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

    for (i = 0; i < num_points; i++) {
        point_vos[i] = try_bgzf_tell(bgz, f->tmp_bgzf, __func__);
        if (point_vos[i] < 0) goto fail;
        points[i] = i * iskip;
        bg_put = try_bgzf_write(bgz, f->text + i * iskip, iskip, f->tmp_bgzf, __func__);
        if (bg_put < 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;

    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_seek(bgz, point_vos[i/iskip], SEEK_SET, f->tmp_bgzf, __func__) != 0) {
                goto fail;
            }
            if (try_bgzf_tell_expect(bgz, point_vos[i/iskip], f->tmp_bgzf, __func__) < 0) {
                goto fail;
            }

            if (try_skip(bgz, o, 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_seek(bgz, 0, SEEK_SET, f->tmp_bgzf, __func__) != 0) {
        goto fail;
    }
    if (try_bgzf_tell_expect(bgz, 0, 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 = points[num_points / 2];
        int64_t mid_vo = point_vos[num_points / 2];
        bgzf_set_cache_size(bgz, cache_size);

        for (i = 0; i < 10; i++) {
            if (try_bgzf_seek(bgz, 0, SEEK_SET, f->tmp_bgzf, __func__) != 0) {
                goto fail;
            }
            if (try_bgzf_tell_expect(bgz, 0, 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_seek(bgz, mid_vo, SEEK_SET,
                               f->tmp_bgzf, __func__) != 0) {
                goto fail;
            }
            if (try_bgzf_tell_expect(bgz, mid_vo, 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 $0xd8, %rsp
movl %ecx, (%rsp)
movl %edx, 0x8(%rsp)
movq %rdi, %rbx
movq $0x0, 0x10(%rsp)
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
mulq 0x48(%rdi)
movq %rdx, %r15
movq %rsp, 0x28(%rsp)
movq 0x18(%rdi), %rdi
leaq 0x8ccae(%rip), %rdx     # 0x944c5
callq 0x85b7
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x789f
movq %rax, %r14
shrq $0x3, %r15
xorl %ebp, %ebp
leaq 0x8cc8f(%rip), %r13     # 0x944c5
xorl %r12d, %r12d
movq 0x18(%rbx), %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0x8a49
movq %rax, 0x30(%rsp,%r12,8)
testq %rax, %rax
js 0x789f
movq %rbp, 0x80(%rsp,%r12,8)
movq 0x40(%rbx), %rsi
addq %rbp, %rsi
movq 0x18(%rbx), %rcx
movq %r14, %rdi
movq %r15, %rdx
movq %r13, %r8
callq 0x88a5
testq %rax, %rax
js 0x789f
incq %r12
addq %r15, %rbp
cmpq $0xa, %r12
jne 0x7839
movq 0x18(%rbx), %rsi
leaq 0x8cc36(%rip), %rdx     # 0x944c5
leaq 0x10(%rsp), %rdi
xorl %ecx, %ecx
callq 0x861b
testl %eax, %eax
je 0x78cc
movq 0x10(%rsp), %rdi
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x78b3
callq 0xbc44
movq 0x28(%rsp), %rsp
movl %ebx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rbx), %rdi
leaq 0x90a6d(%rip), %rsi     # 0x98344
leaq 0x8cbe7(%rip), %rdx     # 0x944c5
callq 0x85b7
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x789f
movq %rax, %r14
cmpl $0x0, (%rsp)
jle 0x790c
leaq 0x8cbc8(%rip), %rdx     # 0x944c5
movq %r14, %rdi
movl (%rsp), %esi
callq 0x887e
testl %eax, %eax
jne 0x789f
cmpq $0x0, 0x48(%rbx)
je 0x79f6
xorl %eax, %eax
movq %rax, 0x18(%rsp)
xorl %edx, %edx
divq %r15
movq 0x30(%rsp,%rax,8), %rsi
xorl %r13d, %r13d
movq %rsi, (%rsp)
leaq 0x8cd9a(%rip), %rax     # 0x946d0
movq (%rax,%r13,8), %r12
movq 0x18(%rbx), %rdx
movq %r14, %rdi
callq 0x8a70
testl %eax, %eax
jne 0x789f
movq 0x18(%rbx), %rdx
movq %r14, %rdi
movq (%rsp), %rsi
leaq 0x8cb65(%rip), %rcx     # 0x944c5
callq 0x8aa1
testq %rax, %rax
js 0x789f
testq %r13, %r13
je 0x7994
movq 0x18(%rbx), %rax
movq %rax, 0x20(%rsp)
movq %r12, %rbp
movq %r14, %rdi
callq 0xc34c
testl %eax, %eax
js 0x7b94
decq %rbp
jne 0x797f
addq 0x18(%rsp), %r12
movl $0x10, %ebp
cmpq 0x48(%rbx), %r12
jae 0x79d3
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rax
movzbl (%rax,%r12), %edx
movq %r14, %rdi
movq %r12, %rsi
leaq 0x8cb07(%rip), %r8      # 0x944c5
callq 0x89f6
testl %eax, %eax
js 0x789f
incq %r12
decq %rbp
jne 0x799e
incq %r13
cmpq $0x3, %r13
movq (%rsp), %rsi
jne 0x792f
movq 0x18(%rsp), %rax
addq %r15, %rax
cmpq 0x48(%rbx), %rax
jb 0x7919
movq 0x18(%rbx), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x8a70
testl %eax, %eax
jne 0x789f
movq 0x18(%rbx), %rdx
leaq 0x8caae(%rip), %rcx     # 0x944c5
movq %r14, %rdi
xorl %esi, %esi
callq 0x8aa1
testq %rax, %rax
js 0x789f
xorl %r15d, %r15d
leaq 0x8ca91(%rip), %r12     # 0x944c5
cmpq 0x48(%rbx), %r15
jae 0x7a69
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rax
movzbl (%rax,%r15), %edx
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %r8
callq 0x89f6
testl %eax, %eax
js 0x789f
incq %r15
cmpq $0x11170, %r15          # imm = 0x11170
jne 0x7a34
cmpl $0x0, 0x8(%rsp)
jle 0x7bc8
movq 0xa8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x58(%rsp), %rax
movq %rax, (%rsp)
movq %r14, %rdi
movl 0x8(%rsp), %esi
callq 0xbf22
movq $0x0, 0x8(%rsp)
leaq 0x8ca1f(%rip), %r12     # 0x944c5
xorl %r15d, %r15d
movq 0x18(%rbx), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x8a70
testl %eax, %eax
jne 0x7bbd
movq 0x18(%rbx), %rdx
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rcx
callq 0x8aa1
testq %rax, %rax
js 0x7bbd
xorl %r13d, %r13d
cmpq 0x48(%rbx), %r13
jae 0x7b0e
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rax
movzbl (%rax,%r13), %edx
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %r8
callq 0x89f6
testl %eax, %eax
js 0x7bbd
incq %r13
cmpq $0x40, %r13
jne 0x7adc
movq 0x18(%rbx), %rdx
movq %r14, %rdi
movq (%rsp), %rsi
callq 0x8a70
testl %eax, %eax
jne 0x7bbd
movq 0x18(%rbx), %rdx
movq %r14, %rdi
movq (%rsp), %rsi
movq %r12, %rcx
callq 0x8aa1
testq %rax, %rax
js 0x7bbd
movl $0x40, %ebp
movq 0x18(%rsp), %r13
cmpq 0x48(%rbx), %r13
jae 0x7b75
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rax
movzbl (%rax,%r13), %edx
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %r8
callq 0x89f6
testl %eax, %eax
js 0x7bbd
incq %r13
decq %rbp
jne 0x7b48
cmpq $0x9, %r15
leaq 0x1(%r15), %rax
setae %cl
movq %rcx, 0x8(%rsp)
movq %rax, %r15
cmpq $0xa, %rax
jne 0x7aa9
jmp 0x7bc8
movq 0xad445(%rip), %rax     # 0xb4fe0
movq (%rax), %rdi
leaq 0x8c9b2(%rip), %rsi     # 0x94557
leaq 0x8c919(%rip), %rdx     # 0x944c5
movq 0x20(%rsp), %rcx
xorl %eax, %eax
callq 0x4700
jmp 0x789f
testb $0x1, 0x8(%rsp)
je 0x789f
movq 0x18(%rbx), %rsi
leaq 0x8c8f2(%rip), %rdx     # 0x944c5
leaq 0x10(%rsp), %rdi
xorl %ebx, %ebx
xorl %ecx, %ecx
callq 0x861b
testl %eax, %eax
jne 0x789f
jmp 0x78b3