// File: /workspace/github_c_makefile_star2_O2/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 $0xe8, %rsp
movl %ecx, %r12d
movl %edx, %ebp
movq %rdi, %rbx
movq %rsp, 0x38(%rsp)
movq 0x18(%rdi), %rdi
movq 0x48(%rbx), %rax
pushq $0xa
popq %rcx
xorl %edx, %edx
divq %rcx
movq %rax, %r15
leaq 0x6d593(%rip), %rdx     # 0x744c5
callq 0x7d08
movq %rax, %r14
movq %rax, 0x10(%rsp)
pushq $-0x1
popq %rax
testq %r14, %r14
je 0x6fa9
movl %r12d, 0x8(%rsp)
movl %ebp, 0x24(%rsp)
xorl %ebp, %ebp
leaq 0x6d56c(%rip), %r13     # 0x744c5
xorl %r12d, %r12d
movq 0x18(%rbx), %rsi
cmpq $0xa, %r12
je 0x6fad
movq %r14, %rdi
movq %r13, %rdx
callq 0x83bc
movq %rax, 0x40(%rsp,%r12,8)
testq %rax, %rax
js 0x6fc4
movq %rbp, 0x90(%rsp,%r12,8)
movq 0x40(%rbx), %rsi
addq %rbp, %rsi
movq 0x18(%rbx), %rcx
movq %r14, %rdi
movq %r15, %rdx
movq %r13, %r8
callq 0x816e
incq %r12
addq %r15, %rbp
testq %rax, %rax
jns 0x6f5c
jmp 0x6fc4
movl %eax, %ebx
jmp 0x6fd6
leaq 0x6d511(%rip), %rdx     # 0x744c5
leaq 0x10(%rsp), %rdi
xorl %ecx, %ecx
callq 0x7d69
testl %eax, %eax
je 0x6fef
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x6fd3
callq 0xad16
pushq $-0x1
popq %rbx
movq 0x38(%rsp), %rsp
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rbx), %rdi
leaq 0x7129c(%rip), %rsi     # 0x78296
leaq 0x6d4c4(%rip), %rdx     # 0x744c5
callq 0x7d08
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x6fd3
movq %rax, %r14
cmpl $0x0, 0x8(%rsp)
jle 0x7031
leaq 0x6d4a4(%rip), %rdx     # 0x744c5
movq %r14, %rdi
movl 0x8(%rsp), %esi
callq 0x811d
testl %eax, %eax
jne 0x6fc4
xorl %eax, %eax
leaq 0x6d48b(%rip), %r13     # 0x744c5
cmpq 0x48(%rbx), %rax
jae 0x7149
movq %rax, 0x28(%rsp)
xorl %edx, %edx
divq %r15
movq 0x40(%rsp,%rax,8), %rax
movq %rax, 0x8(%rsp)
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0x7113
leaq 0x6d665(%rip), %rax     # 0x746d0
movq %rcx, 0x18(%rsp)
movq (%rax,%rcx,8), %r12
movq 0x18(%rbx), %rdx
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x8419
testl %eax, %eax
jne 0x6fc4
movq 0x18(%rbx), %rdx
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rcx
callq 0x8481
testq %rax, %rax
js 0x6fc4
movq 0x18(%rbx), %rax
movq %rax, 0x30(%rsp)
leaq 0x1(%r12), %rbp
decq %rbp
je 0x70cb
movq %r14, %rdi
callq 0xb2a9
testl %eax, %eax
jns 0x70b8
jmp 0x7120
addq 0x28(%rsp), %r12
pushq $0x10
popq %rbp
subq $0x1, %rbp
jb 0x7106
cmpq 0x48(%rbx), %r12
jae 0x7106
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rax
movzbl (%rax,%r12), %edx
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %r8
callq 0x8369
incq %r12
testl %eax, %eax
jns 0x70d3
jmp 0x6fc4
movq 0x18(%rsp), %rcx
incq %rcx
jmp 0x705a
movq 0x28(%rsp), %rax
addq %r15, %rax
jmp 0x703a
movq 0x93eb9(%rip), %rax     # 0x9afe0
movq (%rax), %rdi
leaq 0x6d426(%rip), %rsi     # 0x74557
leaq 0x6d38d(%rip), %rdx     # 0x744c5
movq 0x30(%rsp), %rcx
xorl %eax, %eax
callq 0x4700
jmp 0x6fc4
movq 0x18(%rbx), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x8419
testl %eax, %eax
jne 0x6fc4
movq 0x18(%rbx), %rdx
leaq 0x6d35b(%rip), %rcx     # 0x744c5
movq %r14, %rdi
xorl %esi, %esi
callq 0x8481
testq %rax, %rax
js 0x6fc4
xorl %r15d, %r15d
leaq 0x6d33e(%rip), %r12     # 0x744c5
cmpq $0x11170, %r15          # imm = 0x11170
je 0x71bd
cmpq 0x48(%rbx), %r15
jae 0x71bd
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 0x7187
jmp 0x6fc4
movl 0x24(%rsp), %esi
testl %esi, %esi
jle 0x72db
movq 0xb8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %r14, %rdi
callq 0xaf45
xorl %r15d, %r15d
leaq 0x6d2d3(%rip), %r12     # 0x744c5
cmpq $0xa, %r15
je 0x72db
movq 0x18(%rbx), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x8419
testl %eax, %eax
jne 0x6fc4
movq 0x18(%rbx), %rdx
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rcx
callq 0x8481
testq %rax, %rax
js 0x6fc4
xorl %r13d, %r13d
cmpq $0x40, %r13
je 0x7262
cmpq 0x48(%rbx), %r13
jae 0x7262
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 0x722f
jmp 0x6fc4
movq 0x18(%rbx), %rdx
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x8419
testl %eax, %eax
jne 0x6fc4
movq 0x18(%rbx), %rdx
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rcx
callq 0x8481
testq %rax, %rax
js 0x6fc4
movq 0x18(%rsp), %r13
pushq $0x40
popq %rbp
subq $0x1, %rbp
jb 0x72d3
cmpq 0x48(%rbx), %r13
jae 0x72d3
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 0x72a0
jmp 0x6fc4
incq %r15
jmp 0x71f2
movq 0x18(%rbx), %rsi
leaq 0x6d1df(%rip), %rdx     # 0x744c5
leaq 0x10(%rsp), %rdi
xorl %ebx, %ebx
xorl %ecx, %ecx
callq 0x7d69
testl %eax, %eax
jne 0x6fc4
jmp 0x6fd6