// File: /workspace/github_c_makefile_star2_O1/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, %r12d
movq %rdx, %r14
movq %rsi, 0x10(%rsp)
movq %rdi, %r15
leaq (,%rdx,4), %rbp
movl $0x1, %edi
movq %rbp, %rsi
callq 0x22e0
movq %rax, %rbx
cmpl $0x3, 0x55fb(%rip)      # 0xd220
jge 0x7e15
testq %rbx, %rbx
je 0x7cb7
movl %r12d, 0x4(%rsp)
movq %r14, 0x8(%rsp)
leaq 0x1bde(%rip), %rdi      # 0x9823
xorl %r13d, %r13d
xorl %esi, %esi
xorl %eax, %eax
callq 0x23d0
testl %eax, %eax
js 0x7cc2
movl %eax, %r12d
movq %r15, 0x18(%rsp)
xorl %r15d, %r15d
leaq (%rbx,%r15), %rsi
movq %rbp, %rdx
subq %r15, %rdx
movl %r12d, %edi
callq 0x2110
movq %rax, %r14
testq %rax, %rax
js 0x7c7f
addq %r14, %r15
jmp 0x7c95
callq 0x2250
movl (%rax), %edi
movl %edi, %r13d
negl %r13d
cmpl $0x0, 0x558d(%rip)      # 0xd220
jg 0x7ca1
testq %r14, %r14
js 0x7ca8
cmpq %rbp, %r15
jb 0x7c60
jmp 0x7ca8
callq 0x2c40
jmp 0x7c95
movl %r12d, %edi
callq 0x2090
movq 0x18(%rsp), %r15
jmp 0x7cdc
movl $0xfffffff4, %r13d      # imm = 0xFFFFFFF4
jmp 0x7e03
callq 0x2250
movl (%rax), %edi
movl %edi, %r13d
negl %r13d
cmpl $0x0, 0x554a(%rip)      # 0xd220
jg 0x7e53
testl %r13d, %r13d
movq 0x10(%rsp), %rsi
je 0x7d06
movq %rbx, %rdi
callq 0x2170
cmpl $0x2, 0x552b(%rip)      # 0xd220
jle 0x7e03
movl $0x791, %r9d            # imm = 0x791
jmp 0x7e63
movq 0x8(%rsp), %r13
testq %r13, %r13
sete %al
movl 0x4(%rsp), %ecx
xorb $0x1, %cl
orb %al, %cl
jne 0x7d33
xorl %eax, %eax
movq %r13, %rcx
movups (%r15,%rax), %xmm0
movups %xmm0, (%rsi,%rax)
addq $0x10, %rax
decq %rcx
jne 0x7d21
testq %r13, %r13
je 0x7def
movabsq $0x3fffffffffffffff, %r14 # imm = 0x3FFFFFFFFFFFFFFF
leaq 0x1a94(%rip), %rbp      # 0x97e1
movq %rsi, %r15
xorl %r12d, %r12d
movslq (%rbx,%r12,4), %rax
xorl %edx, %edx
divq %r13
movq %rdx, %rax
shlq $0x4, %rax
movups (%rsi,%rax), %xmm0
movaps %xmm0, 0x20(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rsi,%rax)
movaps 0x20(%rsp), %xmm0
movups %xmm0, (%r15)
cmpl $0x3, 0x549c(%rip)      # 0xd220
jge 0x7d94
incq %r12
addq $0x10, %r15
cmpq %r12, %r13
jne 0x7d53
jmp 0x7def
movq %rdx, %r10
addq %rsi, %rax
movq 0x8(%r15), %r11
andq %r14, %r11
movq 0x8(%rax), %r13
andq %r14, %r13
movq 0x5231(%rip), %rax      # 0xcfe0
movq (%rax), %rdi
movl 0x54af(%rip), %r8d      # 0xd268
leaq 0x1a38(%rip), %rsi      # 0x97f8
leaq 0x434(%rip), %rdx       # 0x81fb
movq %rbp, %rcx
movl $0x7ab, %r9d            # imm = 0x7AB
xorl %eax, %eax
pushq %r11
pushq %r10
pushq %r13
movq 0x20(%rsp), %r13
pushq %r12
callq 0x2390
movq 0x30(%rsp), %rsi
addq $0x20, %rsp
jmp 0x7d86
movq %rbx, %rdi
callq 0x2170
xorl %r13d, %r13d
cmpl $0x3, 0x541f(%rip)      # 0xd220
jge 0x7e5d
movl %r13d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x51c4(%rip), %rax      # 0xcfe0
movq (%rax), %rdi
movl 0x5442(%rip), %r8d      # 0xd268
leaq 0xe69(%rip), %rsi       # 0x8c96
leaq 0x3c7(%rip), %rdx       # 0x81fb
leaq 0x19a6(%rip), %rcx      # 0x97e1
movl $0x78a, %r9d            # imm = 0x78A
xorl %eax, %eax
pushq %rbp
pushq %rbx
callq 0x2390
addq $0x10, %rsp
jmp 0x7c2b
callq 0x2c8b
jmp 0x7cdc
movl $0x7ae, %r9d            # imm = 0x7AE
movq 0x5176(%rip), %rax      # 0xcfe0
movq (%rax), %rdi
movl 0x53f4(%rip), %r8d      # 0xd268
subq $0x8, %rsp
leaq 0xe34(%rip), %rsi       # 0x8cb3
leaq 0x375(%rip), %rdx       # 0x81fb
leaq 0x1954(%rip), %rcx      # 0x97e1
xorl %eax, %eax
pushq %rbx
callq 0x2390
addq $0x10, %rsp
jmp 0x7e03