// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movl %ecx, 0x4(%rsp)
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
leaq (,%rdx,4), %r13
movl $0x1, %edi
movq %r13, %rsi
callq 0x22e0
movq %rax, %rbx
cmpl $0x3, 0x46f9(%rip)      # 0xc220
jge 0x7cf4
testq %rbx, %rbx
je 0x7b73
movq %r15, 0x8(%rsp)
leaq 0x1cd5(%rip), %rdi      # 0x9813
xorl %esi, %esi
xorl %eax, %eax
callq 0x23d0
testl %eax, %eax
js 0x7b7e
movl %eax, %ebp
xorl %r15d, %r15d
leaq (%rbx,%r15), %rsi
movq %r13, %rdx
subq %r15, %rdx
movl %ebp, %edi
callq 0x2110
testq %rax, %rax
js 0x7b9b
addq %rax, %r15
cmpq %r13, %r15
jb 0x7b50
xorl %r15d, %r15d
jmp 0x7bb5
movl $0xfffffff4, %r15d      # imm = 0xFFFFFFF4
jmp 0x7ce2
callq 0x2250
movl (%rax), %edi
movl %edi, %r15d
negl %r15d
cmpl $0x0, 0x468e(%rip)      # 0xc220
jle 0x7bbc
callq 0x2bbf
jmp 0x7bbc
callq 0x2250
movl (%rax), %edi
movl %edi, %r15d
negl %r15d
cmpl $0x0, 0x4671(%rip)      # 0xc220
jg 0x7d74
movl %ebp, %edi
callq 0x2090
testl %r15d, %r15d
je 0x7be1
movq %rbx, %rdi
callq 0x2170
cmpl $0x2, 0x4650(%rip)      # 0xc220
jle 0x7ce2
movl $0x791, %r9d            # imm = 0x791
jmp 0x7d39
testq %r14, %r14
sete %al
movl 0x4(%rsp), %ecx
xorb $0x1, %cl
orb %al, %cl
jne 0x7c17
xorl %eax, %eax
movq %r14, %rcx
movq 0x8(%rsp), %rdx
movups (%rdx,%rax), %xmm0
movups %xmm0, (%r12,%rax)
addq $0x10, %rax
decq %rcx
jne 0x7bfc
movl 0x460b(%rip), %r13d     # 0xc220
jmp 0x7c27
movl 0x4602(%rip), %r13d     # 0xc220
testq %r14, %r14
je 0x7cd1
movq %r12, %r15
xorl %ebp, %ebp
movslq (%rbx,%rbp,4), %rax
xorl %edx, %edx
divq %r14
movq %rdx, %rax
shlq $0x4, %rax
movups (%r12,%rax), %xmm0
movaps %xmm0, 0x10(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%r12,%rax)
movaps 0x10(%rsp), %xmm0
movups %xmm0, (%r15)
cmpl $0x3, %r13d
jge 0x7c6c
incq %rbp
addq $0x10, %r15
cmpq %rbp, %r14
jne 0x7c2c
jmp 0x7cd1
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 0x434f(%rip), %rax      # 0xbfe0
movq (%rax), %rdi
movl 0x45cd(%rip), %r8d      # 0xc268
leaq 0x1b46(%rip), %rsi      # 0x97e8
leaq 0x542(%rip), %rdx       # 0x81eb
leaq 0x1b21(%rip), %rcx      # 0x97d1
movl $0x7ab, %r9d            # imm = 0x7AB
xorl %eax, %eax
pushq %r11
pushq %r10
pushq %r13
pushq %rbp
callq 0x2390
addq $0x20, %rsp
movl 0x4551(%rip), %r13d     # 0xc220
jmp 0x7c5e
movq %rbx, %rdi
callq 0x2170
xorl %r15d, %r15d
cmpl $0x3, %r13d
jge 0x7d33
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x42e5(%rip), %rax      # 0xbfe0
movq (%rax), %rdi
movl 0x4563(%rip), %r8d      # 0xc268
leaq 0xf7a(%rip), %rsi       # 0x8c86
leaq 0x4d8(%rip), %rdx       # 0x81eb
leaq 0x1ab7(%rip), %rcx      # 0x97d1
movl $0x78a, %r9d            # imm = 0x78A
xorl %eax, %eax
pushq %r13
pushq %rbx
callq 0x2390
addq $0x10, %rsp
jmp 0x7b2d
movl $0x7ae, %r9d            # imm = 0x7AE
movq 0x42a0(%rip), %rax      # 0xbfe0
movq (%rax), %rdi
movl 0x451e(%rip), %r8d      # 0xc268
subq $0x8, %rsp
leaq 0xf4e(%rip), %rsi       # 0x8ca3
leaq 0x48f(%rip), %rdx       # 0x81eb
leaq 0x1a6e(%rip), %rcx      # 0x97d1
xorl %eax, %eax
pushq %rbx
callq 0x2390
addq $0x10, %rsp
jmp 0x7ce2
callq 0x2b74
jmp 0x7bb5