// File: /workspace/github_c_makefile_star2_O2/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, %ebp
movq %rdi, %r12
movq 0x2062b4(%rip), %rcx    # 0x20c290
leaq 0xb03f(%rdi), %r8
leaq 0xb038(%rdi), %r9
movl 0x6278(%rip), %eax      # 0xc268
subl 0xb018(%rdi), %eax
movl 0xb01c(%rdi), %r10d
cltd
idivl %r10d
decl %r10d
testl %edx, %edx
cmovnsl %edx, %r10d
subq $0x8, %rsp
leaq 0xe0ea9b(%rip), %rdi    # 0xe14ab0
leaq 0x2ecb(%rip), %rdx      # 0x8ee7
movl $0x1000, %esi           # imm = 0x1000
xorl %eax, %eax
pushq %r10
callq 0x2070
addq $0x10, %rsp
cmpl $0x1000, %eax           # imm = 0x1000
setl %cl
cmpl $-0x1, %eax
setne %al
testb %al, %cl
jne 0x6089
pushq $-0x24
popq %r14
cmpl $0x0, 0x61cd(%rip)      # 0xc218
jle 0x627d
movq 0x5f88(%rip), %rax      # 0xbfe0
movq (%rax), %rdi
movl 0x6206(%rip), %r8d      # 0xc268
leaq 0x2e8d(%rip), %rsi      # 0x8ef6
leaq 0x212e(%rip), %rdx      # 0x819e
leaq 0x2ea6(%rip), %rcx      # 0x8f1d
movl $0x5a2, %r9d            # imm = 0x5A2
xorl %eax, %eax
callq 0x2380
jmp 0x627d
movq 0xb020(%r12), %r15
leaq 0x2e98(%rip), %rax      # 0x8f30
leaq 0x393f(%rip), %rsi      # 0x99de
testb %bpl, %bpl
cmovneq %rax, %rsi
leaq 0xe0ea03(%rip), %rbx    # 0xe14ab0
movq %rbx, %rdi
callq 0x2110
testq %rax, %rax
je 0x60e7
movq %rax, %r14
testb %bpl, %bpl
je 0x613f
movslq 0xb034(%r12), %rax
imulq $0xb0, %rax, %rax
movq 0x88(%r12,%rax), %r13
testq %r13, %r13
jne 0x6149
addq %r12, %rax
addq $0x78, %rax
jmp 0x6146
callq 0x2240
movl (%rax), %edi
movl %edi, %r14d
negl %r14d
cmpl $0x0, 0x611d(%rip)      # 0xc218
jle 0x627d
movq 0x5ed8(%rip), %rax      # 0xbfe0
movq (%rax), %r15
movl 0x6157(%rip), %ebp      # 0xc268
callq 0x21f0
movq %rax, %r10
leaq 0x2e12(%rip), %rsi      # 0x8f32
leaq 0x2077(%rip), %rdx      # 0x819e
leaq 0x2def(%rip), %rcx      # 0x8f1d
movq %r15, %rdi
movl %ebp, %r8d
movl $0x5ad, %r9d            # imm = 0x5AD
jmp 0x61de
leaq 0x611a(%rip), %rax      # 0xc260
movq (%rax), %r13
cmpl $0x3, 0x60c8(%rip)      # 0xc218
jge 0x628f
pushq $0x10
popq %rsi
movq %r13, %rdi
movq %r15, %rdx
movq %r14, %rcx
testb %bpl, %bpl
je 0x616e
callq 0x2350
jmp 0x6173
callq 0x2230
movq %rax, %r12
cmpq %r15, %rax
jne 0x61ef
movq %r14, %rdi
callq 0x2310
testl %eax, %eax
je 0x627a
callq 0x2240
movl (%rax), %edi
movl %edi, %r14d
negl %r14d
cmpl $0x0, 0x6079(%rip)      # 0xc218
jle 0x627d
movq 0x5e34(%rip), %rax      # 0xbfe0
movq (%rax), %r15
movl 0x60b3(%rip), %ebp      # 0xc268
callq 0x21f0
movq %rax, %r10
leaq 0x2ddd(%rip), %rsi      # 0x8fa1
leaq 0x1fd3(%rip), %rdx      # 0x819e
leaq 0x2d4b(%rip), %rcx      # 0x8f1d
movq %r15, %rdi
movl %ebp, %r8d
movl $0x5d8, %r9d            # imm = 0x5D8
xorl %eax, %eax
pushq %r10
pushq %rbx
callq 0x2380
popq %rcx
popq %rdx
jmp 0x627d
callq 0x2240
movl (%rax), %edi
movl %edi, %r14d
negl %r14d
cmpl $0x0, 0x6015(%rip)      # 0xc218
jle 0x627d
movq 0x5dd4(%rip), %rax      # 0xbfe0
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movl 0x604e(%rip), %eax      # 0xc268
movl %eax, 0xc(%rsp)
leaq 0x2d6f(%rip), %rax      # 0x8f94
leaq 0x2d6f(%rip), %r13      # 0x8f9b
testb %bpl, %bpl
cmovneq %rax, %r13
callq 0x21f0
movq %rax, %r10
subq $0x8, %rsp
leaq 0x2d26(%rip), %rsi      # 0x8f6c
leaq 0x1f51(%rip), %rdx      # 0x819e
leaq 0x2cc9(%rip), %rcx      # 0x8f1d
movq 0x18(%rsp), %rdi
movl 0x14(%rsp), %r8d
movl $0x5cf, %r9d            # imm = 0x5CF
xorl %eax, %eax
pushq %r15
pushq %r12
pushq %r10
pushq %rbx
pushq %r13
callq 0x2380
addq $0x30, %rsp
jmp 0x627d
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5d4a(%rip), %rax      # 0xbfe0
movq (%rax), %rdi
movl 0x5fc8(%rip), %r8d      # 0xc268
movl 0xb010(%r12), %r10d
movl 0xb034(%r12), %r11d
subq $0x8, %rsp
leaq 0x2c96(%rip), %rsi      # 0x8f51
leaq 0x1eed(%rip), %rdx      # 0x81af
leaq 0x2c54(%rip), %rcx      # 0x8f1d
movl $0x5c4, %r9d            # imm = 0x5C4
xorl %eax, %eax
pushq %r11
pushq %r10
pushq %r13
callq 0x2380
addq $0x20, %rsp
jmp 0x6156