// File: /workspace/github_c_makefile_star2_O2/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 0x70beb(%rip), %rcx     # 0x774b1
cmpq $0xf, %rax
je 0x68e8
movzbl (%rax,%rcx), %edx
movb $0x61, %sil
cmpl $0x77, %edx
je 0x68de
testl %edx, %edx
je 0x68e8
movl %edx, %esi
movb %sil, 0x10(%rsp,%rax)
incq %rax
jmp 0x68c6
movb $0x0, 0x10(%rsp,%rax)
movq 0x18(%rbx), %rdi
leaq 0x70bb9(%rip), %rsi     # 0x774b1
leaq 0x6da75(%rip), %rdx     # 0x74374
callq 0x7d08
movq %rax, (%rsp)
pushq $-0x1
popq %r12
testq %rax, %rax
je 0x6973
movq %rax, %r15
testl %ebp, %ebp
jle 0x692d
leaq 0x6da55(%rip), %rdx     # 0x74374
movq %r15, %rdi
movl %ebp, %esi
callq 0x811d
testl %eax, %eax
jne 0x6965
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rsi
leaq 0x6da38(%rip), %r8      # 0x74374
movq %r15, %rdi
movq %r14, %rdx
callq 0x816e
testq %rax, %rax
js 0x6965
movq 0x18(%rbx), %rsi
leaq 0x6da1d(%rip), %rdx     # 0x74374
movq %rsp, %rdi
xorl %ecx, %ecx
callq 0x7d69
testl %eax, %eax
je 0x698a
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x6973
callq 0xad16
movl %r12d, %ebx
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 0x6d9df(%rip), %rdx     # 0x74374
leaq 0x10(%rsp), %rsi
callq 0x7d08
movq %rax, (%rsp)
testq %rax, %rax
je 0x6973
movq %rax, %r15
testl %ebp, %ebp
jle 0x69c4
leaq 0x6d9be(%rip), %rdx     # 0x74374
movq %r15, %rdi
movl %ebp, %esi
callq 0x811d
testl %eax, %eax
jne 0x6965
movq 0x40(%rbx), %rsi
addq %r14, %rsi
movq 0x18(%rbx), %rcx
movq 0x48(%rbx), %rdx
subq %r14, %rdx
leaq 0x6d997(%rip), %r8      # 0x74374
movq %r15, %rdi
callq 0x816e
testq %rax, %rax
js 0x6965
movq 0x18(%rbx), %rsi
leaq 0x6d97b(%rip), %rdx     # 0x74374
movq %rsp, %rdi
xorl %ecx, %ecx
callq 0x7d69
testl %eax, %eax
jne 0x6965
movq 0x18(%rbx), %rdi
leaq 0x71880(%rip), %rsi     # 0x78296
leaq 0x6d957(%rip), %rdx     # 0x74374
callq 0x7d08
movq %rax, (%rsp)
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x6973
testl %ebp, %ebp
jle 0x6a53
leaq 0x6d935(%rip), %rdx     # 0x74374
movq 0x8(%rsp), %rdi
movl %ebp, %esi
callq 0x811d
testl %eax, %eax
jne 0x6965
xorl %r15d, %r15d
movq 0x18(%rbx), %rcx
movl $0x8000, %edx           # imm = 0x8000
movq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x6d904(%rip), %r8      # 0x74374
callq 0x7e14
testq %rax, %rax
js 0x6965
movq %rax, %r13
movq 0x48(%rbx), %rbp
movq %rbp, %rdx
subq %r15, %rdx
jbe 0x6aaf
movq 0x40(%rbx), %rdi
addq %r15, %rdi
leaq (%r15,%r13), %r14
cmpq %rbp, %r14
cmovbq %r13, %rdx
leaq 0x20(%rsp), %rsi
callq 0x44c0
testl %eax, %eax
je 0x6ab5
jmp 0x6b06
addq %r13, %r15
movq %r15, %r14
movq %r14, %r15
testq %r13, %r13
jne 0x6a56
cmpq %rbp, %r14
jne 0x6ae6
movq 0x18(%rbx), %rsi
leaq 0x6d8a7(%rip), %rdx     # 0x74374
movq %rsp, %rdi
xorl %ebx, %ebx
xorl %ecx, %ecx
callq 0x7d69
testl %eax, %eax
jne 0x6965
jmp 0x6976
movq 0x944f3(%rip), %rax     # 0x9afe0
movq (%rax), %rdi
leaq 0x6d718(%rip), %rsi     # 0x7420f
leaq 0x6d876(%rip), %rdx     # 0x74374
movq %r14, %rcx
movq %rbp, %r8
jmp 0x6b25
movq 0x944d3(%rip), %rax     # 0x9afe0
movq (%rax), %rdi
movq 0x18(%rbx), %rcx
leaq 0x6d6ce(%rip), %rsi     # 0x741e9
leaq 0x6d852(%rip), %rdx     # 0x74374
movq %r15, %r8
xorl %eax, %eax
callq 0x4700
jmp 0x6965