// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x8090, %rsp           # imm = 0x8090
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rcx
movl $0x8000, %eax           # imm = 0x8000
cmpq 0x48(%rcx), %rax
jae 0x6a33
movl $0x8000, %eax           # imm = 0x8000
movq %rax, -0x8068(%rbp)
jmp 0x6a45
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
shrq %rax
movq %rax, -0x8068(%rbp)
movq -0x8068(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
xorl %eax, %eax
cmpq $0xf, -0x40(%rbp)
movb %al, -0x8069(%rbp)
jae 0x6a7f
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x8069(%rbp)
movb -0x8069(%rbp), %al
testb $0x1, %al
jne 0x6a8b
jmp 0x6adc
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x77, %eax
jne 0x6aa9
movl $0x61, %eax
movl %eax, -0x8070(%rbp)
jmp 0x6abb
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x8070(%rbp)
movl -0x8070(%rbp), %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, -0x60(%rbp,%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x6a58
movq -0x40(%rbp), %rax
movb $0x0, -0x60(%rbp,%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
leaq 0xe387c(%rip), %rdx     # 0xea374
callq 0x8b70
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x6b0d
jmp 0x6df0
cmpl $0x0, -0x1c(%rbp)
jle 0x6b30
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq 0xe3853(%rip), %rdx     # 0xea374
callq 0x92f0
cmpl $0x0, %eax
je 0x6b30
jmp 0x6df0
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rsi
movq -0x48(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
leaq 0xe3825(%rip), %r8      # 0xea374
callq 0x9370
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jge 0x6b64
jmp 0x6df0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
leaq -0x28(%rbp), %rdi
leaq 0xe37fd(%rip), %rdx     # 0xea374
xorl %ecx, %ecx
callq 0x8c10
cmpl $0x0, %eax
je 0x6b88
jmp 0x6df0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x60(%rbp), %rsi
leaq 0xe37d9(%rip), %rdx     # 0xea374
callq 0x8b70
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x6bb0
jmp 0x6df0
cmpl $0x0, -0x1c(%rbp)
jle 0x6bd3
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq 0xe37b0(%rip), %rdx     # 0xea374
callq 0x92f0
cmpl $0x0, %eax
je 0x6bd3
jmp 0x6df0
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rsi
addq -0x48(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdx
subq -0x48(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
leaq 0xe3776(%rip), %r8      # 0xea374
callq 0x9370
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jge 0x6c13
jmp 0x6df0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
leaq -0x28(%rbp), %rdi
leaq 0xe374e(%rip), %rdx     # 0xea374
xorl %ecx, %ecx
callq 0x8c10
cmpl $0x0, %eax
je 0x6c37
jmp 0x6df0
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
leaq 0xe7933(%rip), %rsi     # 0xee581
leaq 0xe371f(%rip), %rdx     # 0xea374
callq 0x8b70
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x6c6a
jmp 0x6df0
cmpl $0x0, -0x1c(%rbp)
jle 0x6c8d
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq 0xe36f6(%rip), %rdx     # 0xea374
callq 0x92f0
cmpl $0x0, %eax
je 0x6c8d
jmp 0x6df0
jmp 0x6c8f
movq -0x28(%rbp), %rdi
leaq -0x8060(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movl $0x8000, %edx           # imm = 0x8000
leaq 0xe36c6(%rip), %r8      # 0xea374
callq 0x8d30
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jge 0x6cc3
jmp 0x6df0
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jae 0x6d74
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x8080(%rbp)
leaq -0x8060(%rbp), %rax
movq %rax, -0x8078(%rbp)
movq -0x40(%rbp), %rax
addq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jae 0x6d15
movq -0x38(%rbp), %rax
movq %rax, -0x8088(%rbp)
jmp 0x6d28
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
subq -0x40(%rbp), %rax
movq %rax, -0x8088(%rbp)
movq -0x8078(%rbp), %rsi
movq -0x8080(%rbp), %rdi
movq -0x8088(%rbp), %rdx
callq 0x41b0
cmpl $0x0, %eax
je 0x6d74
movq 0x101292(%rip), %rax    # 0x107fe0
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x40(%rbp), %r8
leaq 0xe3485(%rip), %rsi     # 0xea1e9
leaq 0xe3609(%rip), %rdx     # 0xea374
movb $0x0, %al
callq 0x46d0
jmp 0x6df0
movq -0x38(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x38(%rbp)
jg 0x6c8f
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x48(%rcx), %rax
je 0x6dc6
movq 0x101240(%rip), %rax    # 0x107fe0
movq (%rax), %rdi
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x48(%rax), %r8
leaq 0xe3459(%rip), %rsi     # 0xea20f
leaq 0xe35b7(%rip), %rdx     # 0xea374
movb $0x0, %al
callq 0x46d0
jmp 0x6df0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
leaq -0x28(%rbp), %rdi
leaq 0xe359b(%rip), %rdx     # 0xea374
xorl %ecx, %ecx
callq 0x8c10
cmpl $0x0, %eax
je 0x6de7
jmp 0x6df0
movl $0x0, -0x4(%rbp)
jmp 0x6e07
cmpq $0x0, -0x28(%rbp)
je 0x6e00
movq -0x28(%rbp), %rdi
callq 0xe0e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x8090, %rsp           # imm = 0x8090
popq %rbp
retq
nopw %cs:(%rax,%rax)