// File: /workspace/github_c_makefile_star2_O1/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 $0x0, 0x8(%rsp)
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 0x90548(%rip), %rcx     # 0x97561
movzbl (%rax,%rcx), %edx
movb $0x61, %sil
cmpl $0x77, %edx
je 0x702b
testl %edx, %edx
je 0x703e
movl %edx, %esi
movb %sil, 0x10(%rsp,%rax)
incq %rax
cmpq $0xf, %rax
jne 0x7019
movl $0xf, %eax
movb $0x0, 0x10(%rsp,%rax)
movq 0x18(%rbx), %rdi
leaq 0x90513(%rip), %rsi     # 0x97561
leaq 0x8d31f(%rip), %rdx     # 0x94374
callq 0x85b7
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x70ba
movq %rax, %r15
testl %ebp, %ebp
jle 0x7080
leaq 0x8d302(%rip), %rdx     # 0x94374
movq %r15, %rdi
movl %ebp, %esi
callq 0x887e
testl %eax, %eax
jne 0x70ba
movq 0x18(%rbx), %rcx
movq 0x40(%rbx), %rsi
leaq 0x8d2e5(%rip), %r8      # 0x94374
movq %r15, %rdi
movq %r14, %rdx
callq 0x88a5
testq %rax, %rax
js 0x70ba
movq 0x18(%rbx), %rsi
leaq 0x8d2ca(%rip), %rdx     # 0x94374
leaq 0x8(%rsp), %rdi
xorl %ecx, %ecx
callq 0x861b
testl %eax, %eax
je 0x70e2
movq 0x8(%rsp), %rdi
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x70ce
callq 0xbc44
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 0x8d287(%rip), %rdx     # 0x94374
leaq 0x10(%rsp), %rsi
callq 0x85b7
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x70ba
movq %rax, %r15
testl %ebp, %ebp
jle 0x711d
leaq 0x8d265(%rip), %rdx     # 0x94374
movq %r15, %rdi
movl %ebp, %esi
callq 0x887e
testl %eax, %eax
jne 0x70ba
movq 0x40(%rbx), %rsi
addq %r14, %rsi
movq 0x18(%rbx), %rcx
movq 0x48(%rbx), %rdx
subq %r14, %rdx
leaq 0x8d23e(%rip), %r8      # 0x94374
movq %r15, %rdi
callq 0x88a5
testq %rax, %rax
js 0x70ba
movq 0x18(%rbx), %rsi
leaq 0x8d222(%rip), %rdx     # 0x94374
leaq 0x8(%rsp), %rdi
xorl %ecx, %ecx
callq 0x861b
testl %eax, %eax
jne 0x70ba
movq 0x18(%rbx), %rdi
leaq 0x911d3(%rip), %rsi     # 0x98344
leaq 0x8d1fc(%rip), %rdx     # 0x94374
callq 0x85b7
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x70ba
movq %rax, %r15
testl %ebp, %ebp
jle 0x71ab
leaq 0x8d1db(%rip), %rdx     # 0x94374
movq %r15, %rdi
movl %ebp, %esi
callq 0x887e
testl %eax, %eax
jne 0x70ba
xorl %r14d, %r14d
leaq 0x20(%rsp), %r13
movq 0x18(%rbx), %rcx
movl $0x8000, %edx           # imm = 0x8000
movq %r15, %rdi
movq %r13, %rsi
leaq 0x8d1ab(%rip), %r8      # 0x94374
callq 0x868e
testq %rax, %rax
js 0x70ba
movq %rax, %r12
movq 0x48(%rbx), %rbp
movq %rbp, %rdx
subq %r14, %rdx
jbe 0x7204
movq 0x40(%rbx), %rdi
addq %r14, %rdi
leaq (%r12,%r14), %rax
cmpq %rbp, %rax
cmovbq %r12, %rdx
movq %r13, %rsi
callq 0x44c0
testl %eax, %eax
jne 0x7257
addq %r12, %r14
testq %r12, %r12
jne 0x71b3
cmpq %rbp, %r14
jne 0x7237
movq 0x18(%rbx), %rsi
leaq 0x8d158(%rip), %rdx     # 0x94374
leaq 0x8(%rsp), %rdi
xorl %ebx, %ebx
xorl %ecx, %ecx
callq 0x861b
testl %eax, %eax
jne 0x70ba
jmp 0x70ce
movq 0xadda2(%rip), %rax     # 0xb4fe0
movq (%rax), %rdi
leaq 0x8cfc7(%rip), %rsi     # 0x9420f
leaq 0x8d125(%rip), %rdx     # 0x94374
movq %r14, %rcx
movq %rbp, %r8
jmp 0x7276
movq 0xadd82(%rip), %rax     # 0xb4fe0
movq (%rax), %rdi
movq 0x18(%rbx), %rcx
leaq 0x8cf7d(%rip), %rsi     # 0x941e9
leaq 0x8d101(%rip), %rdx     # 0x94374
movq %r14, %r8
xorl %eax, %eax
callq 0x4700
jmp 0x70ba