// File: /workspace/github_c_makefile_star2_O0/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 %rbx
subq $0xc0, %rsp
movb %cl, %al
movq %rdi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movq %rdx, 0xa0(%rsp)
andb $0x1, %al
movb %al, 0x9f(%rsp)
movq 0xa0(%rsp), %rax
shlq $0x2, %rax
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rsi
movl $0x1, %edi
callq 0x22c0
movq %rax, 0x80(%rsp)
movl $0x3, %eax
cmpl 0x578c(%rip), %eax      # 0xf210
jg 0x9ae6
movq 0x5553(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, 0x38(%rsp)
movl $0x3, %edi
callq 0x4890
movq 0x38(%rsp), %rdi
movq %rax, %rdx
movl 0x57e2(%rip), %r8d      # 0xf290
movq 0x80(%rsp), %r10
movq 0x90(%rsp), %rax
shlq $0x0, %rax
leaq 0x2386(%rip), %rsi      # 0xbe4f
leaq 0x2eca(%rip), %rcx      # 0xc99a
movl $0x78a, %r9d            # imm = 0x78A
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x2370
movq 0x80(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x88(%rsp)
cmpq $0x0, 0x88(%rsp)
jne 0x9b1b
movl $0xfffffff4, 0xbc(%rsp) # imm = 0xFFFFFFF4
jmp 0x9e2a
movq 0x88(%rsp), %rdi
movq 0x90(%rsp), %rsi
callq 0x9f30
movl %eax, 0x74(%rsp)
cmpl $0x0, 0x74(%rsp)
je 0x9bb4
movq 0x88(%rsp), %rdi
callq 0x2150
movl $0x3, %eax
cmpl 0x56bd(%rip), %eax      # 0xf210
jg 0x9ba4
movq 0x5484(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, 0x30(%rsp)
movl $0x3, %edi
callq 0x4890
movq 0x30(%rsp), %rdi
movq %rax, %rdx
movl 0x5713(%rip), %r8d      # 0xf290
movq 0x88(%rsp), %rax
leaq 0x22e0(%rip), %rsi      # 0xbe6c
leaq 0x2e07(%rip), %rcx      # 0xc99a
movl $0x791, %r9d            # imm = 0x791
movq %rax, (%rsp)
movb $0x0, %al
callq 0x2370
movl 0x74(%rsp), %eax
movl %eax, 0xbc(%rsp)
jmp 0x9e2a
testb $0x1, 0x9f(%rsp)
je 0x9c1e
movq $0x0, 0x68(%rsp)
movq 0x68(%rsp), %rax
cmpq 0xa0(%rsp), %rax
jae 0x9c1c
movq 0xa8(%rsp), %rax
movq 0x68(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0xb0(%rsp), %rcx
movq 0x68(%rsp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x9bc7
jmp 0x9c1e
movq $0x0, 0x68(%rsp)
movq 0x68(%rsp), %rax
cmpq 0xa0(%rsp), %rax
jae 0x9db6
movq 0x88(%rsp), %rax
movq 0x68(%rsp), %rcx
movslq (%rax,%rcx,4), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq 0xa0(%rsp)
movq %rdx, 0x60(%rsp)
movq 0xa8(%rsp), %rax
movq 0x60(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, 0x50(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x58(%rsp)
movq 0xa8(%rsp), %rax
movq 0x60(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0xa8(%rsp), %rcx
movq 0x68(%rsp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq 0xa8(%rsp), %rax
movq 0x68(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x50(%rsp), %rcx
movq %rcx, (%rax)
movq 0x58(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0xa8(%rsp), %rcx
movq 0x60(%rsp), %rax
shlq $0x4, %rax
addq %rax, %rcx
movabsq $0x3fffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFFF
andq 0x8(%rcx), %rax
movq %rax, 0x48(%rsp)
movq 0xa8(%rsp), %rcx
movq 0x68(%rsp), %rax
shlq $0x4, %rax
addq %rax, %rcx
movabsq $0x3fffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFFF
andq 0x8(%rcx), %rax
movq %rax, 0x40(%rsp)
movl $0x3, %eax
cmpl 0x54db(%rip), %eax      # 0xf210
jg 0x9da1
movq 0x52a2(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, 0x28(%rsp)
movl $0x3, %edi
callq 0x4890
movq 0x28(%rsp), %rdi
movq %rax, %rdx
movl 0x5531(%rip), %r8d      # 0xf290
movq 0x68(%rsp), %rbx
movq 0x48(%rsp), %r11
movq 0x60(%rsp), %r10
movq 0x40(%rsp), %rax
leaq 0x2c37(%rip), %rsi      # 0xc9b1
leaq 0x2c19(%rip), %rcx      # 0xc99a
movl $0x7ab, %r9d            # imm = 0x7AB
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movb $0x0, %al
callq 0x2370
jmp 0x9da3
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x9c27
movq 0x88(%rsp), %rdi
callq 0x2150
movl $0x3, %eax
cmpl 0x5442(%rip), %eax      # 0xf210
jg 0x9e1f
movq 0x5209(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movl $0x3, %edi
callq 0x4890
movq 0x20(%rsp), %rdi
movq %rax, %rdx
movl 0x5498(%rip), %r8d      # 0xf290
movq 0x88(%rsp), %rax
leaq 0x2065(%rip), %rsi      # 0xbe6c
leaq 0x2b8c(%rip), %rcx      # 0xc99a
movl $0x7ae, %r9d            # imm = 0x7AE
movq %rax, (%rsp)
movb $0x0, %al
callq 0x2370
movl $0x0, 0xbc(%rsp)
movl 0xbc(%rsp), %eax
addq $0xc0, %rsp
popq %rbx
retq
nopw (%rax,%rax)