// File: /workspace/github_c_makefile_star2_O2/00pauln00[P]yapio/yapio.c
// Function: yapio_blk_md_randomize
static int
yapio_blk_md_randomize(const yapio_blk_md_t *md_in, yapio_blk_md_t *md_out,
                       size_t num_mds, bool initialize_md_out)
{
    size_t buf_sz = num_mds * sizeof(int);
    int *array_of_randoms = YAPIO_MALLOC(buf_sz);
    if (!array_of_randoms)
        return -ENOMEM;

    int rc = yapio_read_from_dev_urandom((void *)array_of_randoms, buf_sz);
    if (rc)
    {
        YAPIO_FREE(array_of_randoms);
        return rc;
    }

    size_t i;
    if (initialize_md_out)
    {
        /* Initialize the output array with a copy of the input array.
         */
        for (i = 0; i < num_mds; i++)
            md_out[i] = md_in[i];
    }

    /* Swap output array items based on the random data in the array.
     */
    for (i = 0; i < num_mds; i++)
    {
        unsigned long swap_idx = array_of_randoms[i] % num_mds;
        yapio_blk_md_t md_tmp = md_out[swap_idx];
        md_out[swap_idx] = md_out[i];
        md_out[i] = md_tmp;

        unsigned long x = md_out[swap_idx].ybm_blk_number;
        unsigned long y = md_out[i].ybm_blk_number;

        log_msg(YAPIO_LL_DEBUG, "swapped %zu:%lu <-> %zu:%lu",
                i, x, swap_idx, y);
    }

    YAPIO_FREE(array_of_randoms);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, 0x14(%rsp)
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
leaq (,%rdx,4), %r13
pushq $0x1
popq %rdi
movq %r13, %rsi
callq 0x22d0
movq %rax, %rbx
cmpl $0x3, 0x4f95(%rip)      # 0xc218
jge 0x747e
testq %rbx, %rbx
je 0x72d2
leaq 0x2542(%rip), %rdi      # 0x97d7
xorl %esi, %esi
xorl %eax, %eax
callq 0x23c0
testl %eax, %eax
js 0x72db
movl %eax, %ebp
movq %r15, 0x8(%rsp)
xorl %r15d, %r15d
leaq (%rbx,%r15), %rsi
movq %r13, %rdx
subq %r15, %rdx
movl %ebp, %edi
callq 0x2100
testq %rax, %rax
js 0x7341
addq %rax, %r15
cmpq %r13, %r15
jb 0x72ac
xorl %r13d, %r13d
jmp 0x735b
pushq $-0xc
popq %r13
jmp 0x746c
callq 0x2240
movl (%rax), %edi
movl %edi, %r13d
negl %r13d
cmpl $0x0, 0x4f29(%rip)      # 0xc218
jle 0x7367
movq 0x4ce8(%rip), %rax      # 0xbfe0
movq (%rax), %rbp
movl 0x4f67(%rip), %eax      # 0xc268
movl %eax, 0x8(%rsp)
callq 0x21f0
movq %rax, %r10
subq $0x8, %rsp
leaq 0x24cc(%rip), %rsi      # 0x97e4
leaq 0xe7f(%rip), %rdx       # 0x819e
leaq 0x24d6(%rip), %rcx      # 0x97fc
movq %rbp, %rdi
movl 0x10(%rsp), %r8d
movl $0x72d, %r9d            # imm = 0x72D
xorl %eax, %eax
pushq %r10
callq 0x2380
popq %rcx
popq %rdx
jmp 0x7367
callq 0x2240
movl (%rax), %edi
movl %edi, %r13d
negl %r13d
cmpl $0x0, 0x4ec3(%rip)      # 0xc218
jg 0x74fa
movq 0x8(%rsp), %r15
movl %ebp, %edi
callq 0x2080
testl %r13d, %r13d
je 0x738c
movq %rbx, %rdi
callq 0x2160
cmpl $0x2, 0x4e9d(%rip)      # 0xc218
jle 0x746c
movl $0x791, %r9d            # imm = 0x791
jmp 0x74c1
cmpb $0x0, 0x14(%rsp)
je 0x73ae
xorl %eax, %eax
movq %r14, %rcx
subq $0x1, %rcx
jb 0x73ae
movups (%r15,%rax), %xmm0
movups %xmm0, (%r12,%rax)
addq $0x10, %rax
jmp 0x7398
movq %r12, %r15
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0x7458
movslq (%rbx,%rbp,4), %rax
xorl %edx, %edx
divq %r14
movq %rdx, %rax
shlq $0x4, %rax
movups (%r12,%rax), %xmm0
movaps %xmm0, 0x20(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%r12,%rax)
movaps 0x20(%rsp), %xmm0
movups %xmm0, (%r15)
cmpl $0x3, 0x4e29(%rip)      # 0xc218
jge 0x73fa
incq %rbp
addq $0x10, %r15
jmp 0x73b3
movq %rdx, %r10
addq %r12, %rax
movq 0x8(%r15), %r11
movabsq $0x3fffffffffffffff, %rcx # imm = 0x3FFFFFFFFFFFFFFF
andq %rcx, %r11
movq 0x8(%rax), %r13
andq %rcx, %r13
movq 0x4bc1(%rip), %rax      # 0xbfe0
movq (%rax), %rdi
movl 0x4e3f(%rip), %r8d      # 0xc268
leaq 0x237c(%rip), %rsi      # 0x97ac
leaq 0xd78(%rip), %rdx       # 0x81af
leaq 0x2357(%rip), %rcx      # 0x9795
movl $0x7ab, %r9d            # imm = 0x7AB
xorl %eax, %eax
pushq %r11
pushq %r10
pushq %r13
pushq %rbp
callq 0x2380
addq $0x20, %rsp
jmp 0x73f1
movq %rbx, %rdi
callq 0x2160
xorl %r13d, %r13d
cmpl $0x3, 0x4dae(%rip)      # 0xc218
jge 0x74bb
movl %r13d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4b5b(%rip), %rax      # 0xbfe0
movq (%rax), %rdi
movl 0x4dd9(%rip), %r8d      # 0xc268
leaq 0x17b4(%rip), %rsi      # 0x8c4a
leaq 0xd12(%rip), %rdx       # 0x81af
leaq 0x22f1(%rip), %rcx      # 0x9795
movl $0x78a, %r9d            # imm = 0x78A
xorl %eax, %eax
pushq %r13
pushq %rbx
callq 0x2380
popq %rcx
popq %rdx
jmp 0x7289
movl $0x7ae, %r9d            # imm = 0x7AE
movq 0x4b18(%rip), %rax      # 0xbfe0
movq (%rax), %rdi
movl 0x4d96(%rip), %r8d      # 0xc268
subq $0x8, %rsp
leaq 0x178a(%rip), %rsi      # 0x8c67
leaq 0xccb(%rip), %rdx       # 0x81af
leaq 0x22aa(%rip), %rcx      # 0x9795
xorl %eax, %eax
pushq %rbx
callq 0x2380
popq %rcx
popq %rdx
jmp 0x746c
movq 0x4adf(%rip), %rax      # 0xbfe0
movq (%rax), %rax
movq %rax, 0x18(%rsp)
movl 0x4d58(%rip), %r15d     # 0xc268
callq 0x21f0
movq %rax, %r10
subq $0x8, %rsp
leaq 0x22f5(%rip), %rsi      # 0x9818
leaq 0xc74(%rip), %rdx       # 0x819e
leaq 0x22cb(%rip), %rcx      # 0x97fc
movq 0x20(%rsp), %rdi
movl %r15d, %r8d
movl $0x739, %r9d            # imm = 0x739
xorl %eax, %eax
pushq %r10
callq 0x2380
popq %rcx
popq %rdx
jmp 0x735b