// File: /workspace/github_c_makefile_star2_O0/00pauln00[P]yapio/yapio.c
// Function: yapio_test_context_setup_distributed_random_or_strided
static int
yapio_test_context_setup_distributed_random_or_strided(yapio_test_ctx_t *ytc)
{
    const yapio_test_group_t *ytg = ytc->ytc_group;
    const size_t nblks_per_rank = ytg->ytg_num_blks_per_rank;
    const int nranks = ytg->ytg_num_ranks;

    if (ytc->ytc_io_pattern != YAPIO_IOP_RANDOM &&
        ytc->ytc_io_pattern != YAPIO_IOP_STRIDED)
        return -EINVAL;

    else if (nblks_per_rank % nranks)
        return -EINVAL;

    yapio_blk_md_t *md_recv =
        yapio_test_context_alloc(ytc, YAPIO_TEST_CTX_MDH_IN, nblks_per_rank);

    if (!md_recv)
        return -errno;

    yapio_blk_md_t *md_send =
        yapio_test_context_alloc(ytc, YAPIO_TEST_CTX_MDH_OUT, nblks_per_rank);

    if (!md_send)
        return -errno;

    const bool strided =
        ytc->ytc_io_pattern == YAPIO_IOP_STRIDED ? true : false;

    size_t src_idx;
    const int nblks_div_nranks = nblks_per_rank / nranks;

//XXX open all FDs here for FPP
//    int skips_left = ytc->ytc_sparse_io;
    if (strided)
    {
        int i, j, total = 0;
        for (i = 0, total = 0; i < nranks; i++)
        {
            int skips_left = ytc->ytc_sparse_io;
            for (j = 0; j < nblks_div_nranks; j++, total++)
            {
                src_idx = (nranks * j) + i;
#if 0 //backwards + strided is broken
                if (ytc->ytc_backwards)
                    src_idx = (nranks * (nblks_div_nranks - j) - 1 + i);
#endif
                bool skip_io = skip_io_or_not(nblks_div_nranks - j, skips_left);

                if (!ytc->ytc_read && skip_io)
                {
                    log_msg(YAPIO_LL_DEBUG, "NN update writer rank for op total = %d\n", total);
                    yapio_source_md_update_writer_rank(src_idx, i);
                }

                md_send[total] = yapioSourceBlkMd[src_idx];
                if (skip_io)
                {
                    log_msg(YAPIO_LL_DEBUG, "skip IO # %d\n", i);
                    md_send[total].ybm_skip_io = 1;
                    skips_left--;
                }
            }
        }
    }
    else
    {
        yapio_blk_md_randomize(yapioSourceBlkMd, md_send, nblks_per_rank,
                               true);

        select_holes(ytg->ytg_num_blks_per_rank, ytc->ytc_sparse_io, md_send);

        if (!ytc->ytc_read)
        {
            for (src_idx = 0; src_idx < nblks_per_rank; src_idx++)
            {
                if (md_send[src_idx].ybm_skip_io)
                    continue;

                const int rank = src_idx / nblks_div_nranks;

                unsigned long send = md_send[src_idx].ybm_blk_number;
                unsigned long src = yapioSourceBlkMd[src_idx].ybm_blk_number;

                log_msg(YAPIO_LL_TRACE,
                        "%zu: blk-num:%zu:%zu old-rank=%d new-rank=%d",
                        src_idx, send, src, md_send[src_idx].ybm_writer_rank,
                        rank);

                /* This rank's yapioSourceBlkMd array must be updated with the
                 * rank which is about to write this block.
                 */
                const size_t update_idx =
                    md_send[src_idx].ybm_blk_number % nblks_per_rank;

                log_msg(YAPIO_LL_DEBUG, "update writer rank for op #%zu\n", src_idx);
                yapio_source_md_update_writer_rank(update_idx, rank);
                md_send[src_idx].ybm_writer_rank = rank;
            }
        }
    }

    int send_recv_cnt = nblks_div_nranks * sizeof(yapio_blk_md_t);

    MPI_OP_START;
    int rc = MPI_Alltoall(md_send, send_recv_cnt, MPI_BYTE,
                          md_recv, send_recv_cnt, MPI_BYTE,
                          yapioMyTestGroup->ytg_comm);
    MPI_OP_END;

    if (rc != MPI_SUCCESS)
    {
        log_msg(YAPIO_LL_ERROR, "MPI_Alltoall: %d", rc);
        return rc;
    }

    return strided ? 0 : yapio_blk_md_randomize(md_recv, md_recv,
                                                nblks_per_rank, false);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0xe8, %rsp
movq %rdi, 0xd8(%rsp)
movq 0xd8(%rsp), %rax
movq 0xa0(%rax), %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rax
movq 0xb020(%rax), %rax
movq %rax, 0xc8(%rsp)
movq 0xd0(%rsp), %rax
movl 0xb01c(%rax), %eax
movl %eax, 0xc4(%rsp)
movq 0xd8(%rsp), %rax
cmpl $0x1, 0xc(%rax)
je 0x8cf1
movq 0xd8(%rsp), %rax
cmpl $0x2, 0xc(%rax)
je 0x8cf1
movl $0xffffffea, 0xe4(%rsp) # imm = 0xFFFFFFEA
jmp 0x940f
movq 0xc8(%rsp), %rax
movslq 0xc4(%rsp), %rcx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
je 0x8d1c
movl $0xffffffea, 0xe4(%rsp) # imm = 0xFFFFFFEA
jmp 0x940f
jmp 0x8d1e
movq 0xd8(%rsp), %rdi
movq 0xc8(%rsp), %rdx
xorl %esi, %esi
callq 0x9430
movq %rax, 0xb8(%rsp)
cmpq $0x0, 0xb8(%rsp)
jne 0x8d60
callq 0x2230
movq %rax, %rcx
xorl %eax, %eax
subl (%rcx), %eax
movl %eax, 0xe4(%rsp)
jmp 0x940f
movq 0xd8(%rsp), %rdi
movq 0xc8(%rsp), %rdx
movl $0x1, %esi
callq 0x9430
movq %rax, 0xb0(%rsp)
cmpq $0x0, 0xb0(%rsp)
jne 0x8da5
callq 0x2230
movq %rax, %rcx
xorl %eax, %eax
subl (%rcx), %eax
movl %eax, 0xe4(%rsp)
jmp 0x940f
movq 0xd8(%rsp), %rax
movl 0xc(%rax), %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x2, %edx
cmovel %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0xaf(%rsp)
movq 0xc8(%rsp), %rax
movslq 0xc4(%rsp), %rcx
xorl %edx, %edx
divq %rcx
movl %eax, 0x9c(%rsp)
testb $0x1, 0xaf(%rsp)
je 0x9061
movl $0x0, 0x90(%rsp)
movl $0x0, 0x98(%rsp)
movl $0x0, 0x90(%rsp)
movl 0x98(%rsp), %eax
cmpl 0xc4(%rsp), %eax
jge 0x905c
movq 0xd8(%rsp), %rax
movl 0xa8(%rax), %eax
movl %eax, 0x8c(%rsp)
movl $0x0, 0x94(%rsp)
movl 0x94(%rsp), %eax
cmpl 0x9c(%rsp), %eax
jge 0x9044
movl 0xc4(%rsp), %eax
imull 0x94(%rsp), %eax
addl 0x98(%rsp), %eax
cltq
movq %rax, 0xa0(%rsp)
movl 0x9c(%rsp), %edi
subl 0x94(%rsp), %edi
movl 0x8c(%rsp), %esi
callq 0x9870
andb $0x1, %al
movb %al, 0x8b(%rsp)
movq 0xd8(%rsp), %rax
movb (%rax), %al
shrb $0x3, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x8f31
testb $0x1, 0x8b(%rsp)
je 0x8f31
movl $0x3, %eax
cmpl 0x6342(%rip), %eax      # 0xf210
jg 0x8f1d
movq 0x6109(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, 0x58(%rsp)
movl $0x3, %edi
callq 0x4890
movq 0x58(%rsp), %rdi
movq %rax, %rdx
movl 0x6398(%rip), %r8d      # 0xf290
movl 0x90(%rsp), %eax
leaq 0x399a(%rip), %rsi      # 0xc8a0
leaq 0x39cb(%rip), %rcx      # 0xc8d8
movl $0x847, %r9d            # imm = 0x847
movl %eax, (%rsp)
movb $0x0, %al
callq 0x2370
movq 0xa0(%rsp), %rdi
movl 0x98(%rsp), %esi
callq 0x98e0
movq 0xb0(%rsp), %rax
movslq 0x90(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x6311(%rip), %rcx      # 0xf260
movq 0xa0(%rsp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
testb $0x1, 0x8b(%rsp)
je 0x901b
movl $0x3, %eax
cmpl 0x628b(%rip), %eax      # 0xf210
jg 0x8fd4
movq 0x6052(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, 0x50(%rsp)
movl $0x3, %edi
callq 0x4890
movq 0x50(%rsp), %rdi
movq %rax, %rdx
movl 0x62e1(%rip), %r8d      # 0xf290
movl 0x98(%rsp), %eax
leaq 0x3829(%rip), %rsi      # 0xc7e6
leaq 0x3914(%rip), %rcx      # 0xc8d8
movl $0x84e, %r9d            # imm = 0x84E
movl %eax, (%rsp)
movb $0x0, %al
callq 0x2370
movq 0xb0(%rsp), %rax
movslq 0x90(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
andq 0x8(%rax), %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movl 0x8c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x8c(%rsp)
jmp 0x901d
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
movl 0x90(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x90(%rsp)
jmp 0x8e4b
jmp 0x9046
movl 0x98(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x98(%rsp)
jmp 0x8e17
jmp 0x9302
movq 0x61f8(%rip), %rdi      # 0xf260
movq 0xb0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
movl $0x1, %ecx
callq 0x9a20
movq 0xd0(%rsp), %rax
movq 0xb020(%rax), %rax
movl %eax, %edi
movq 0xd8(%rsp), %rax
movl 0xa8(%rax), %esi
movq 0xb0(%rsp), %rdx
callq 0x9e40
movq 0xd8(%rsp), %rax
movb (%rax), %al
shrb $0x3, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x9300
movq $0x0, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
cmpq 0xc8(%rsp), %rax
jae 0x92fe
movq 0xb0(%rsp), %rax
movq 0xa0(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x3f, %rax
cmpq $0x0, %rax
je 0x9115
jmp 0x92e5
movq 0xa0(%rsp), %rax
movslq 0x9c(%rsp), %rcx
xorl %edx, %edx
divq %rcx
movl %eax, 0x84(%rsp)
movq 0xb0(%rsp), %rcx
movq 0xa0(%rsp), %rax
shlq $0x4, %rax
addq %rax, %rcx
movabsq $0x3fffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFFF
andq 0x8(%rcx), %rax
movq %rax, 0x78(%rsp)
movq 0x60fe(%rip), %rcx      # 0xf260
movq 0xa0(%rsp), %rax
shlq $0x4, %rax
addq %rax, %rcx
movabsq $0x3fffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFFF
andq 0x8(%rcx), %rax
movq %rax, 0x70(%rsp)
movl $0x4, %eax
cmpl 0x6081(%rip), %eax      # 0xf210
jg 0x9222
movq 0x5e44(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, 0x48(%rsp)
movl $0x4, %edi
callq 0x4890
movq 0x48(%rsp), %rdi
movq %rax, %rdx
movl 0x60d3(%rip), %r8d      # 0xf290
movq 0xa0(%rsp), %r14
movq 0x78(%rsp), %rbx
movq 0x70(%rsp), %r11
movq 0xb0(%rsp), %rax
movq 0xa0(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %r10d
movl 0x84(%rsp), %eax
leaq 0x3718(%rip), %rsi      # 0xc90f
leaq 0x36da(%rip), %rcx      # 0xc8d8
movl $0x86b, %r9d            # imm = 0x86B
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movl %eax, 0x20(%rsp)
movb $0x0, %al
callq 0x2370
movq 0xb0(%rsp), %rcx
movq 0xa0(%rsp), %rax
shlq $0x4, %rax
addq %rax, %rcx
movabsq $0x3fffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFFF
andq 0x8(%rcx), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq 0xc8(%rsp)
movq %rdx, 0x68(%rsp)
movl $0x3, %eax
cmpl 0x5fad(%rip), %eax      # 0xf210
jg 0x92b4
movq 0x5d74(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, 0x40(%rsp)
movl $0x3, %edi
callq 0x4890
movq 0x40(%rsp), %rdi
movq %rax, %rdx
movl 0x6003(%rip), %r8d      # 0xf290
movq 0xa0(%rsp), %rax
leaq 0x36af(%rip), %rsi      # 0xc94b
leaq 0x3635(%rip), %rcx      # 0xc8d8
movl $0x873, %r9d            # imm = 0x873
movq %rax, (%rsp)
movb $0x0, %al
callq 0x2370
movq 0x68(%rsp), %rdi
movl 0x84(%rsp), %esi
callq 0x98e0
movl 0x84(%rsp), %ecx
movq 0xb0(%rsp), %rax
movq 0xa0(%rsp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq 0xa0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xa0(%rsp)
jmp 0x90d5
jmp 0x9300
jmp 0x9302
movslq 0x9c(%rsp), %rax
shlq $0x4, %rax
movl %eax, 0x64(%rsp)
leaq 0xe107df(%rip), %rdi    # 0xe19af8
callq 0x2350
movq 0xb0(%rsp), %rdi
movl 0x64(%rsp), %esi
movq 0xb8(%rsp), %rcx
movl 0x64(%rsp), %r8d
movq 0x5f12(%rip), %rax      # 0xf250
movq (%rax), %rax
movq 0x5ca8(%rip), %r9       # 0xeff0
movq %r9, %rdx
movq %rax, (%rsp)
callq 0x2090
movl %eax, 0x60(%rsp)
leaq 0xe10799(%rip), %rdi    # 0xe19af8
callq 0x2390
cmpl $0x0, 0x60(%rsp)
je 0x93cf
movl $0x1, %eax
cmpl 0x5e9a(%rip), %eax      # 0xf210
jg 0x93c2
movq 0x5c61(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, 0x38(%rsp)
movl $0x1, %edi
callq 0x4890
movq 0x38(%rsp), %rdi
movq %rax, %rdx
movl 0x5ef0(%rip), %r8d      # 0xf290
movl 0x60(%rsp), %eax
leaq 0x35cf(%rip), %rsi      # 0xc97a
leaq 0x3526(%rip), %rcx      # 0xc8d8
movl $0x884, %r9d            # imm = 0x884
movl %eax, (%rsp)
movb $0x0, %al
callq 0x2370
movl 0x60(%rsp), %eax
movl %eax, 0xe4(%rsp)
jmp 0x940f
testb $0x1, 0xaf(%rsp)
je 0x93e1
xorl %eax, %eax
movl %eax, 0x34(%rsp)
jmp 0x9404
movq 0xb8(%rsp), %rdi
movq 0xb8(%rsp), %rsi
movq 0xc8(%rsp), %rdx
xorl %ecx, %ecx
callq 0x9a20
movl %eax, 0x34(%rsp)
movl 0x34(%rsp), %eax
movl %eax, 0xe4(%rsp)
movl 0xe4(%rsp), %eax
addq $0xe8, %rsp
popq %rbx
popq %r14
retq
nopw %cs:(%rax,%rax)