// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/test/test_bgzf.c
// Function: test_embed_eof
static int test_embed_eof(Files *f, const char *mode, int nthreads) {
    BGZF* bgz = NULL;
    ssize_t bg_put, bg_got;
    size_t pos = 0, half = BUFSZ < f->ltext ? BUFSZ : f->ltext / 2;
    char append_mode[16];
    unsigned char bg_buf[BUFSZ];

    for (pos = 0; pos < sizeof(append_mode) - 1 && mode[pos] != 0; pos++) {
        append_mode[pos] = mode[pos] == 'w' ? 'a' : mode[pos];
    }
    append_mode[pos] ='\0';

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

    if (nthreads > 0 && try_bgzf_mt(bgz, nthreads, __func__) != 0) goto fail;

    bg_put = try_bgzf_write(bgz, f->text, half, f->tmp_bgzf, __func__);
    if (bg_put < 0) goto fail;

    if (try_bgzf_close(&bgz, f->tmp_bgzf, __func__, 0) != 0) goto fail;


    // Write second half.  Append mode, so an EOF block should be in the
    // middle.
    bgz = try_bgzf_open(f->tmp_bgzf, append_mode, __func__);
    if (!bgz) goto fail;

    if (nthreads > 0 && try_bgzf_mt(bgz, nthreads, __func__) != 0) goto fail;

    bg_put = try_bgzf_write(bgz, f->text + half, f->ltext - half, f->tmp_bgzf,
                            __func__);
    if (bg_put < 0) goto fail;

    if (try_bgzf_close(&bgz, f->tmp_bgzf, __func__, 0) != 0) goto fail;

    // Try reading
    pos = 0;
    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;

    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 != f->ltext) {
        fprintf(stderr, "%s : bgzf_read got %zd bytes; expected %zd\n",
                __func__, pos, f->ltext);
        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 $0x8028, %rsp           # imm = 0x8028
movl %esi, %ebp
movq %rdi, %rbx
movq 0x48(%rdi), %rax
movq %rax, %rcx
shrq %rcx
cmpq $0x8001, %rax           # imm = 0x8001
movl $0x8000, %r14d          # imm = 0x8000
cmovbq %rcx, %r14
xorl %eax, %eax
leaq 0x8d3dc(%rip), %rcx     # 0x94511
movzbl (%rax,%rcx), %edx
movb $0x61, %sil
cmpl $0x77, %edx
je 0x7147
testl %edx, %edx
je 0x715a
movl %edx, %esi
movb %sil, 0x10(%rsp,%rax)
incq %rax
cmpq $0xf, %rax
jne 0x7135
movl $0xf, %eax
movb $0x0, 0x10(%rsp,%rax)
movq 0x18(%rbx), %rdi
leaq 0x8d3a7(%rip), %rsi     # 0x94511
leaq 0x8a21f(%rip), %rdx     # 0x91390
callq 0x865e
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x71e5
movq %rax, %r15
testl %ebp, %ebp
jle 0x719c
leaq 0x8a202(%rip), %rdx     # 0x91390
movq %r15, %rdi
movl %ebp, %esi
callq 0x8915
testl %eax, %eax
jne 0x71d6
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rsi
leaq 0x8a1e5(%rip), %r8      # 0x91390
movq %r15, %rdi
movq %r14, %rdx
callq 0x893c
testq %rax, %rax
js 0x71d6
movq 0x18(%rbx), %rsi
leaq 0x8a1ca(%rip), %rdx     # 0x91390
leaq 0x8(%rsp), %rdi
xorl %ecx, %ecx
callq 0x86bf
testl %eax, %eax
je 0x71fe
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x71e5
callq 0xbb59
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x8028, %rsp           # imm = 0x8028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rbx), %rdi
leaq 0x8a187(%rip), %rdx     # 0x91390
leaq 0x10(%rsp), %rsi
callq 0x865e
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x71e5
movq %rax, %r15
testl %ebp, %ebp
jle 0x7239
leaq 0x8a165(%rip), %rdx     # 0x91390
movq %r15, %rdi
movl %ebp, %esi
callq 0x8915
testl %eax, %eax
jne 0x71d6
movq 0x40(%rbx), %rsi
addq %r14, %rsi
movq 0x18(%rbx), %rcx
movq 0x48(%rbx), %rdx
subq %r14, %rdx
leaq 0x8a13e(%rip), %r8      # 0x91390
movq %r15, %rdi
callq 0x893c
testq %rax, %rax
js 0x71d6
movq 0x18(%rbx), %rsi
leaq 0x8a122(%rip), %rdx     # 0x91390
leaq 0x8(%rsp), %rdi
xorl %ecx, %ecx
callq 0x86bf
testl %eax, %eax
jne 0x71d6
movq 0x18(%rbx), %rdi
leaq 0x8e05e(%rip), %rsi     # 0x952eb
leaq 0x8a0fc(%rip), %rdx     # 0x91390
callq 0x865e
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x71e5
movq %rax, %r14
testl %ebp, %ebp
jle 0x72c7
leaq 0x8a0db(%rip), %rdx     # 0x91390
movq %r14, %rdi
movl %ebp, %esi
callq 0x8915
testl %eax, %eax
jne 0x71d6
xorl %r15d, %r15d
movq 0x18(%rbx), %rcx
movl $0x8000, %edx           # imm = 0x8000
movq %r14, %rdi
leaq 0x20(%rsp), %rsi
leaq 0x8a0ae(%rip), %r8      # 0x91390
callq 0x8732
testq %rax, %rax
js 0x71d6
movq %rax, %r13
movq 0x48(%rbx), %rbp
movq %rbp, %rdx
subq %r15, %rdx
jbe 0x7321
movq 0x40(%rbx), %rdi
addq %r15, %rdi
leaq (%r15,%r13), %r12
cmpq %rbp, %r12
cmovbq %r13, %rdx
leaq 0x20(%rsp), %rsi
callq 0x44c0
testl %eax, %eax
je 0x7327
jmp 0x737a
addq %r13, %r15
movq %r15, %r12
movq %r12, %r15
testq %r13, %r13
jne 0x72ca
cmpq %rbp, %r12
jne 0x735a
movq 0x18(%rbx), %rsi
leaq 0x8a051(%rip), %rdx     # 0x91390
leaq 0x8(%rsp), %rdi
xorl %ebx, %ebx
xorl %ecx, %ecx
callq 0x86bf
testl %eax, %eax
jne 0x71d6
jmp 0x71ea
movq 0xabc7f(%rip), %rax     # 0xb2fe0
movq (%rax), %rdi
leaq 0x89ec0(%rip), %rsi     # 0x9122b
leaq 0x8a01e(%rip), %rdx     # 0x91390
movq %r12, %rcx
movq %rbp, %r8
jmp 0x7399
movq 0xabc5f(%rip), %rax     # 0xb2fe0
movq (%rax), %rdi
movq 0x18(%rbx), %rcx
leaq 0x89e76(%rip), %rsi     # 0x91205
leaq 0x89ffa(%rip), %rdx     # 0x91390
movq %r15, %r8
xorl %eax, %eax
callq 0x4700
jmp 0x71d6