// File: /workspace/github_c_makefile_star2_O1/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 0x206532(%rip), %rcx    # 0x20d290
leaq 0xb03f(%rdi), %r8
leaq 0xb038(%rdi), %r9
movl 0x64f6(%rip), %eax      # 0xd268
subl 0xb018(%rdi), %eax
movl 0xb01c(%rdi), %r10d
cltd
idivl %r10d
decl %r10d
testl %edx, %edx
cmovnsl %edx, %r10d
subq $0x8, %rsp
leaq 0xe0ed19(%rip), %rdi    # 0xe15ab0
leaq 0x2195(%rip), %rdx      # 0x8f33
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 0x6dde
movl $0xffffffdc, %ebp       # imm = 0xFFFFFFDC
cmpl $0x0, 0x6452(%rip)      # 0xd220
jle 0x6f56
callq 0x27fd
jmp 0x6f56
movq 0xb020(%r12), %r14
leaq 0x218f(%rip), %rax      # 0x8f7c
leaq 0x2c36(%rip), %rsi      # 0x9a2a
testb %bl, %bl
cmovneq %rax, %rsi
leaq 0xe0ecaf(%rip), %r15    # 0xe15ab0
movq %r15, %rdi
callq 0x2120
testq %rax, %rax
je 0x6e3a
movq %rax, %r13
testb %bl, %bl
je 0x6e5c
movslq 0xb034(%r12), %rax
imulq $0xb0, %rax, %rax
movq 0x88(%r12,%rax), %rbp
testq %rbp, %rbp
jne 0x6e66
addq %r12, %rax
addq $0x78, %rax
jmp 0x6e63
callq 0x2250
movl (%rax), %edi
movl %edi, %ebp
negl %ebp
cmpl $0x0, 0x63d4(%rip)      # 0xd220
jle 0x6f56
callq 0x27a8
jmp 0x6f56
leaq 0x63fd(%rip), %rax      # 0xd260
movq (%rax), %rbp
cmpl $0x3, 0x63b3(%rip)      # 0xd220
jge 0x6f67
movl $0x10, %esi
movq %rbp, %rdi
movq %r14, %rdx
movq %r13, %rcx
testb %bl, %bl
je 0x6e8c
callq 0x2360
jmp 0x6e91
callq 0x2240
movq %rax, %r12
cmpq %r14, %rax
jne 0x6ecb
movq %r13, %rdi
callq 0x2320
testl %eax, %eax
je 0x6f54
callq 0x2250
movl (%rax), %edi
movl %edi, %ebp
negl %ebp
cmpl $0x0, 0x6365(%rip)      # 0xd220
jle 0x6f56
callq 0x2753
jmp 0x6f56
callq 0x2250
movl (%rax), %edi
movl %edi, %ebp
negl %ebp
cmpl $0x0, 0x6343(%rip)      # 0xd220
jle 0x6f56
movq 0x60fa(%rip), %rax      # 0xcfe0
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movl 0x6374(%rip), %eax      # 0xd268
movl %eax, 0xc(%rsp)
leaq 0x20e1(%rip), %rax      # 0x8fe0
leaq 0x20e1(%rip), %r13      # 0x8fe7
testb %bl, %bl
cmovneq %rax, %r13
callq 0x2200
movq %rax, %r10
subq $0x8, %rsp
leaq 0x2099(%rip), %rsi      # 0x8fb8
leaq 0x12c4(%rip), %rdx      # 0x81ea
leaq 0x203c(%rip), %rcx      # 0x8f69
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 0x6f56
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 0x26fd
jmp 0x6e73