// File: /workspace/github_c_makefile_star2_O3/00pauln00[P]yapio/yapio.c
// Function: yapio_md_buffer_io
static int
yapio_md_buffer_io(const yapio_test_group_t *ytg, const bool dump)
{
    int rc = snprintf(yapioRestartFileName, PATH_MAX, "%s/.%s%s.%d.md",
                      yapioTestRootDir, ytg->ytg_prefix, ytg->ytg_suffix,
                      yapio_relative_rank_get(ytg, 0));
    if (rc >= PATH_MAX || rc == -1)
    {
        log_msg(YAPIO_LL_ERROR, "Md filename is too long");
        return -ENAMETOOLONG;
    }

    const size_t nblks_per_rank = ytg->ytg_num_blks_per_rank;

    FILE *file = fopen(yapioRestartFileName, dump ? "w" : "r");
    if (!file)
    {
        int rc = -errno;
        log_msg(YAPIO_LL_ERROR, "fopen(`%s'): %s", yapioRestartFileName,
                strerror(errno));
        return rc;
    }

    yapio_blk_md_t *md_array;
    if (dump)
    {
        /* use metadata from last iteration */
        int test_ctx_idf = ytg->ytg_last_writer_ctx;
        const yapio_test_ctx_t *ytc = &ytg->ytg_contexts[test_ctx_idf];

        md_array = yapio_test_ctx_to_md_array(ytc, YAPIO_TEST_CTX_MDH_OUT,
                                              NULL);
        if (!md_array)
            md_array = yapio_test_ctx_to_md_array(ytc, YAPIO_TEST_CTX_MDH_IN,
                                                  NULL);
    }
    else
    {
        md_array = yapioSourceBlkMd;
    }

    log_msg(YAPIO_LL_DEBUG, "%p %d lc=%d", md_array, ytg->ytg_num_contexts,
            ytg->ytg_last_writer_ctx);

    size_t io_rc = dump ?
        fwrite(md_array, sizeof(yapio_blk_md_t), nblks_per_rank, file) :
        fread(md_array, sizeof(yapio_blk_md_t), nblks_per_rank, file);

    if (io_rc != nblks_per_rank)
    {
        int rc = -errno;
        log_msg(YAPIO_LL_ERROR, "%s(`%s'): %s (%zu / %zu)",
                dump ? "fwrite" : "fread", yapioRestartFileName,
                strerror(errno), io_rc, nblks_per_rank);

        return rc;
    }

    if (fclose(file))
    {
        int rc = -errno;
        log_msg(YAPIO_LL_ERROR, "fclose(`%s'): %s", yapioRestartFileName,
                strerror(errno));
        return rc;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %ebx
movq %rdi, %r12
movq 0x205695(%rip), %rcx    # 0x20c290
leaq 0xb03f(%rdi), %r8
leaq 0xb038(%rdi), %r9
movl 0xb01c(%rdi), %r10d
movl 0x5652(%rip), %eax      # 0xc268
subl 0xb018(%rdi), %eax
cltd
idivl %r10d
decl %r10d
testl %edx, %edx
cmovnsl %edx, %r10d
subq $0x8, %rsp
leaq 0xe0de7c(%rip), %rdi    # 0xe14ab0
leaq 0x22e8(%rip), %rdx      # 0x8f23
movl $0x1000, %esi           # imm = 0x1000
xorl %eax, %eax
pushq %r10
callq 0x2080
addq $0x10, %rsp
cmpl $0x1000, %eax           # imm = 0x1000
setl %cl
cmpl $-0x1, %eax
setne %al
testb %al, %cl
jne 0x6c7b
movl $0xffffffdc, %ebp       # imm = 0xFFFFFFDC
cmpl $0x0, 0x55b5(%rip)      # 0xc220
jle 0x6df3
callq 0x27aa
jmp 0x6df3
movq 0xb020(%r12), %r14
leaq 0x22e2(%rip), %rax      # 0x8f6c
leaq 0x2d89(%rip), %rsi      # 0x9a1a
testb %bl, %bl
cmovneq %rax, %rsi
leaq 0xe0de12(%rip), %r15    # 0xe14ab0
movq %r15, %rdi
callq 0x2120
testq %rax, %rax
je 0x6cd7
movq %rax, %r13
testb %bl, %bl
je 0x6cf9
movslq 0xb034(%r12), %rax
imulq $0xb0, %rax, %rax
movq 0x88(%r12,%rax), %rbp
testq %rbp, %rbp
jne 0x6d03
addq %r12, %rax
addq $0x78, %rax
jmp 0x6d00
callq 0x2250
movl (%rax), %edi
movl %edi, %ebp
negl %ebp
cmpl $0x0, 0x5537(%rip)      # 0xc220
jle 0x6df3
callq 0x2755
jmp 0x6df3
leaq 0x5560(%rip), %rax      # 0xc260
movq (%rax), %rbp
cmpl $0x3, 0x5516(%rip)      # 0xc220
jge 0x6e04
movl $0x10, %esi
movq %rbp, %rdi
movq %r14, %rdx
movq %r13, %rcx
testb %bl, %bl
je 0x6d29
callq 0x2360
jmp 0x6d2e
callq 0x2240
movq %rax, %r12
cmpq %r14, %rax
jne 0x6d68
movq %r13, %rdi
callq 0x2320
testl %eax, %eax
je 0x6df1
callq 0x2250
movl (%rax), %edi
movl %edi, %ebp
negl %ebp
cmpl $0x0, 0x54c8(%rip)      # 0xc220
jle 0x6df3
callq 0x2700
jmp 0x6df3
callq 0x2250
movl (%rax), %edi
movl %edi, %ebp
negl %ebp
cmpl $0x0, 0x54a6(%rip)      # 0xc220
jle 0x6df3
movq 0x525d(%rip), %rax      # 0xbfe0
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movl 0x54d7(%rip), %eax      # 0xc268
movl %eax, 0xc(%rsp)
leaq 0x2234(%rip), %rax      # 0x8fd0
leaq 0x2234(%rip), %r13      # 0x8fd7
testb %bl, %bl
cmovneq %rax, %r13
callq 0x2200
movq %rax, %r10
subq $0x8, %rsp
leaq 0x21ec(%rip), %rsi      # 0x8fa8
leaq 0x1417(%rip), %rdx      # 0x81da
leaq 0x218f(%rip), %rcx      # 0x8f59
movq 0x18(%rsp), %rdi
movl 0x14(%rsp), %r8d
movl $0x5cf, %r9d            # imm = 0x5CF
xorl %eax, %eax
pushq %r14
pushq %r12
pushq %r10
pushq %r15
pushq %r13
callq 0x2390
addq $0x30, %rsp
jmp 0x6df3
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
movq %rbp, %rsi
callq 0x26aa
jmp 0x6d10