// File: /workspace/github_c_makefile_star2_O3/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, %r12d
movl %edx, %ebp
movq %rdi, %rbx
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
mulq 0x48(%rdi)
movq %rdx, %r15
movq %rsp, 0x28(%rsp)
movq 0x18(%rdi), %rdi
leaq 0x89bfb(%rip), %rdx     # 0x914e1
callq 0x865e
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x7989
movq %rax, %r14
movl %r12d, (%rsp)
movl %ebp, 0x1c(%rsp)
shrq $0x3, %r15
xorl %ebp, %ebp
leaq 0x89bd0(%rip), %r13     # 0x914e1
xorl %r12d, %r12d
movq 0x18(%rbx), %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0x8ae5
movq %rax, 0x30(%rsp,%r12,8)
testq %rax, %rax
js 0x797a
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 0x893c
testq %rax, %rax
js 0x797a
incq %r12
addq %r15, %rbp
cmpq $0xa, %r12
jne 0x7914
movq 0x18(%rbx), %rsi
leaq 0x89b77(%rip), %rdx     # 0x914e1
leaq 0x10(%rsp), %rdi
xorl %ecx, %ecx
callq 0x86bf
testl %eax, %eax
je 0x79a7
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x7989
callq 0xbb59
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
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 0x8d939(%rip), %rsi     # 0x952eb
leaq 0x89b28(%rip), %rdx     # 0x914e1
callq 0x865e
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x7989
movq %rax, %r14
cmpl $0x0, (%rsp)
jle 0x79e7
leaq 0x89b09(%rip), %rdx     # 0x914e1
movq %r14, %rdi
movl (%rsp), %esi
callq 0x8915
testl %eax, %eax
jne 0x797a
cmpq $0x0, 0x48(%rbx)
je 0x7ad1
xorl %eax, %eax
movq %rax, 0x8(%rsp)
xorl %edx, %edx
divq %r15
movq 0x30(%rsp,%rax,8), %rsi
xorl %r13d, %r13d
movq %rsi, (%rsp)
leaq 0x89cdf(%rip), %rax     # 0x916f0
movq (%rax,%r13,8), %r12
movq 0x18(%rbx), %rdx
movq %r14, %rdi
callq 0x8b0c
testl %eax, %eax
jne 0x797a
movq 0x18(%rbx), %rdx
movq %r14, %rdi
movq (%rsp), %rsi
leaq 0x89aa6(%rip), %rcx     # 0x914e1
callq 0x8b3d
testq %rax, %rax
js 0x797a
testq %r13, %r13
je 0x7a6f
movq 0x18(%rbx), %rax
movq %rax, 0x20(%rsp)
movq %r12, %rbp
movq %r14, %rdi
callq 0xc275
testl %eax, %eax
js 0x7c7f
decq %rbp
jne 0x7a5a
addq 0x8(%rsp), %r12
movl $0x10, %ebp
cmpq 0x48(%rbx), %r12
jae 0x7aae
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rax
movzbl (%rax,%r12), %edx
movq %r14, %rdi
movq %r12, %rsi
leaq 0x89a48(%rip), %r8      # 0x914e1
callq 0x8a90
testl %eax, %eax
js 0x797a
incq %r12
decq %rbp
jne 0x7a79
incq %r13
cmpq $0x3, %r13
movq (%rsp), %rsi
jne 0x7a0a
movq 0x8(%rsp), %rax
addq %r15, %rax
cmpq 0x48(%rbx), %rax
jb 0x79f4
movq 0x18(%rbx), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x8b0c
testl %eax, %eax
jne 0x797a
movq 0x18(%rbx), %rdx
leaq 0x899ef(%rip), %rcx     # 0x914e1
movq %r14, %rdi
xorl %esi, %esi
callq 0x8b3d
testq %rax, %rax
js 0x797a
xorl %r15d, %r15d
leaq 0x899d2(%rip), %r12     # 0x914e1
cmpq 0x48(%rbx), %r15
jae 0x7b44
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rax
movzbl (%rax,%r15), %edx
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %r8
callq 0x8a90
testl %eax, %eax
js 0x797a
incq %r15
cmpq $0x11170, %r15          # imm = 0x11170
jne 0x7b0f
movl 0x1c(%rsp), %esi
testl %esi, %esi
jle 0x7c59
movq 0xa8(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x58(%rsp), %rax
movq %rax, (%rsp)
movq %r14, %rdi
callq 0xbe30
xorl %r15d, %r15d
leaq 0x89969(%rip), %r12     # 0x914e1
movq 0x18(%rbx), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x8b0c
testl %eax, %eax
jne 0x797a
movq 0x18(%rbx), %rdx
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rcx
callq 0x8b3d
testq %rax, %rax
js 0x797a
xorl %r13d, %r13d
cmpq 0x48(%rbx), %r13
jae 0x7bdd
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rax
movzbl (%rax,%r13), %edx
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %r8
callq 0x8a90
testl %eax, %eax
js 0x797a
incq %r13
cmpq $0x40, %r13
jne 0x7bab
movq 0x18(%rbx), %rdx
movq %r14, %rdi
movq (%rsp), %rsi
callq 0x8b0c
testl %eax, %eax
jne 0x797a
movq 0x18(%rbx), %rdx
movq %r14, %rdi
movq (%rsp), %rsi
movq %r12, %rcx
callq 0x8b3d
testq %rax, %rax
js 0x797a
movl $0x40, %ebp
movq 0x8(%rsp), %r13
cmpq 0x48(%rbx), %r13
jae 0x7c4c
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rax
movzbl (%rax,%r13), %edx
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %r8
callq 0x8a90
testl %eax, %eax
js 0x797a
incq %r13
decq %rbp
jne 0x7c1b
incq %r15
cmpq $0xa, %r15
jne 0x7b78
movq 0x18(%rbx), %rsi
leaq 0x8987d(%rip), %rdx     # 0x914e1
leaq 0x10(%rsp), %rdi
xorl %ebx, %ebx
xorl %ecx, %ecx
callq 0x86bf
testl %eax, %eax
jne 0x797a
jmp 0x798e
movq 0xab35a(%rip), %rax     # 0xb2fe0
movq (%rax), %rdi
leaq 0x898e3(%rip), %rsi     # 0x91573
leaq 0x8984a(%rip), %rdx     # 0x914e1
movq 0x20(%rsp), %rcx
xorl %eax, %eax
callq 0x4700
jmp 0x797a