#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
size_t RAND_MAX;
int /*<<< orphan*/ memcpy(char *, char *, size_t);
int /*<<< orphan*/ rand();
__attribute__((always_)) void shuffle(void *array, size_t n, size_t size) {
  char tmp[size];
  char *arr = (char *)array;
  if (n > 1) {
    for (size_t i = 0; i < n - 1; ++i) {
      size_t rnd = (size_t)rand();
      size_t j = i + rnd / (RAND_MAX / (n - i) + 1);
      memcpy(tmp, arr + j * size, size);
      memcpy(arr + j * size, arr + i * size, size);
      memcpy(arr + i * size, tmp, size);
    }
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x1,-0x10(%rbp)
jbe    1256 <shuffle+0x136>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    1251 <shuffle+0x131>
mov    $0x0,%al
call   1040 <rand@plt>
mov    -0x50(%rbp),%rdi
cltq
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2e35(%rip),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
sub    -0x38(%rbp),%rcx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
add    $0x1,%rcx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x48(%rbp),%rax
imul   -0x18(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x48(%rbp),%rax
imul   -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rax
imul   -0x18(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x50(%rbp),%rsi
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
imul   -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1176 <shuffle+0x56>
jmp    1256 <shuffle+0x136>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,-0x30(%rbp)
mov    %rsp,%rcx
mov    %rdx,-0x38(%rbp)
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
cmp    $0x2,%rsi
jb     1220 <shuffle+0x100>
mov    %rsi,%r14
xor    %ebx,%ebx
mov    -0x30(%rbp),%r13
mov    -0x38(%rbp),%r12
jmp    11c6 <shuffle+0xa6>
nopw   0x0(%rax,%rax,1)
xor    %edx,%edx
div    %rsi
mov    %rax,%r15
add    %rbx,%r15
imul   %r12,%r15
add    -0x30(%rbp),%r15
mov    -0x40(%rbp),%r14
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <memcpy@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1030 <memcpy@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1030 <memcpy@plt>
add    $0x1,%rbx
mov    -0x48(%rbp),%r14
add    $0xffffffffffffffff,%r14
add    %r12,%r13
cmp    $0x1,%r14
je     1220 <shuffle+0x100>
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,%ecx
mov    0x2e12(%rip),%rax
mov    (%rax),%rax
mov    %rax,%rdx
or     %r14,%rdx
shr    $0x20,%rdx
je     11f0 <shuffle+0xd0>
xor    %edx,%edx
div    %r14
mov    %rax,%rsi
jmp    11f7 <shuffle+0xd7>
nop
xor    %edx,%edx
div    %r14d
mov    %eax,%esi
movslq %ecx,%rax
add    $0x1,%rsi
mov    %rax,%rdx
or     %rsi,%rdx
shr    $0x20,%rdx
mov    %r14,-0x48(%rbp)
jne    1170 <shuffle+0x50>
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
mov    %eax,%r15d
jmp    1178 <shuffle+0x58>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define void @shuffle(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%13 = load i64, i64* %6
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %7
%15 = alloca i8, i64 %13
store i64 %13, i64* %8
%16 = load i8*, i8** %4
store i8* %16, i8** %9
%17 = load i64, i64* %5
%18 = icmp ugt i64 %17, 1
br i1 %18, label %19, label %68
19: ; preds = %3
store i64 0, i64* %10
br label %20
20: ; preds = %64, %19
%21 = load i64, i64* %10
%22 = load i64, i64* %5
%23 = sub i64 %22, 1
%24 = icmp ult i64 %21, %23
br i1 %24, label %25, label %67
25: ; preds = %20
%26 = call i32 (...) @rand()
%27 = sext i32 %26 to i64
store i64 %27, i64* %11
%28 = load i64, i64* %10
%29 = load i64, i64* %11
%30 = load i64, i64* @RAND_MAX
%31 = load i64, i64* %5
%32 = load i64, i64* %10
%33 = sub i64 %31, %32
%34 = udiv i64 %30, %33
%35 = add i64 %34, 1
%36 = udiv i64 %29, %35
%37 = add i64 %28, %36
store i64 %37, i64* %12
%38 = load i8*, i8** %9
%39 = load i64, i64* %12
%40 = load i64, i64* %6
%41 = mul i64 %39, %40
%42 = getelementptr inbounds i8, i8* %38, i64 %41
%43 = load i64, i64* %6
%44 = call i32 @memcpy(i8* %15, i8* %42, i64 %43)
%45 = load i8*, i8** %9
%46 = load i64, i64* %12
%47 = load i64, i64* %6
%48 = mul i64 %46, %47
%49 = getelementptr inbounds i8, i8* %45, i64 %48
%50 = load i8*, i8** %9
%51 = load i64, i64* %10
%52 = load i64, i64* %6
%53 = mul i64 %51, %52
%54 = getelementptr inbounds i8, i8* %50, i64 %53
%55 = load i64, i64* %6
%56 = call i32 @memcpy(i8* %49, i8* %54, i64 %55)
%57 = load i8*, i8** %9
%58 = load i64, i64* %10
%59 = load i64, i64* %6
%60 = mul i64 %58, %59
%61 = getelementptr inbounds i8, i8* %57, i64 %60
%62 = load i64, i64* %6
%63 = call i32 @memcpy(i8* %61, i8* %15, i64 %62)
br label %64
64: ; preds = %25
%65 = load i64, i64* %10
%66 = add i64 %65, 1
store i64 %66, i64* %10
br label %20
67: ; preds = %20
br label %68
68: ; preds = %67, %3
%69 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define void @shuffle(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8, i64 %2
%5 = icmp ugt i64 %1, 1
br i1 %5, label %6, label %27
6: ; preds = %3
%7 = add i64 %1, -1
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ %25, %8 ], [ 0, %6 ]
%10 = call i32 (...) @rand()
%11 = sext i32 %10 to i64
%12 = load i64, i64* @RAND_MAX
%13 = sub i64 %1, %9
%14 = udiv i64 %12, %13
%15 = add i64 %14, 1
%16 = udiv i64 %11, %15
%17 = add i64 %16, %9
%18 = mul i64 %17, %2
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = call i32 @memcpy(i8* %4, i8* %19, i64 %2)
%21 = mul i64 %9, %2
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = call i32 @memcpy(i8* %19, i8* %22, i64 %2)
%24 = call i32 @memcpy(i8* %22, i8* %4, i64 %2)
%25 = add nuw i64 %9, 1
%26 = icmp eq i64 %25, %7
br i1 %26, label %27, label %8
27: ; preds = %8, %3
ret void
}