#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 */
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ swap(int *, int *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void shuffle(int *data, int size) {
  int i, j;
  srand(time(NULL));
  for (i = 0; i < size - 1; ++i) {
    j = rand() % (size - i) + i;
    swap(data + i, data + j);
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11be <shuffle+0x7e>
mov    $0x0,%al
call   1060 <rand@plt>
mov    -0xc(%rbp),%ecx
sub    -0x10(%rbp),%ecx
cltd
idiv   %ecx
add    -0x10(%rbp),%edx
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1050 <swap@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1166 <shuffle+0x26>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %rdi,%r14
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
cmp    $0x2,%r15d
jl     119e <shuffle+0x5e>
lea    -0x1(%r15),%r12d
mov    %r14,%r13
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <rand@plt>
cltd
idiv   %r15d
movslq %edx,%rax
add    %rbx,%rax
lea    (%r14,%rax,4),%rsi
mov    %r13,%rdi
call   1050 <swap@plt>
add    $0x1,%rbx
add    $0xffffffff,%r15d
add    $0x4,%r13
cmp    %rbx,%r12
jne    1170 <shuffle+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @shuffle(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = call i32 @time(i32* null)
%8 = call i32 @srand(i32 %7)
store i32 0, i32* %5
br label %9
9: ; preds = %31, %2
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 1
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %34
14: ; preds = %9
%15 = call i32 (...) @rand()
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = sub nsw i32 %16, %17
%19 = srem i32 %15, %18
%20 = load i32, i32* %5
%21 = add nsw i32 %19, %20
store i32 %21, i32* %6
%22 = load i32*, i32** %3
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32*, i32** %3
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = call i32 @swap(i32* %25, i32* %29)
br label %31
31: ; preds = %14
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %9
34: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @shuffle(i32* %0, i32 %1) {
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = icmp sgt i32 %1, 1
br i1 %5, label %6, label %22
6: ; preds = %2
%7 = add nsw i32 %1, -1
%8 = zext i32 %7 to i64
br label %9
9: ; preds = %6, %9
%10 = phi i64 [ 0, %6 ], [ %20, %9 ]
%11 = tail call i32 (...) @rand()
%12 = trunc i64 %10 to i32
%13 = sub nsw i32 %1, %12
%14 = srem i32 %11, %13
%15 = add nsw i32 %14, %12
%16 = getelementptr inbounds i32, i32* %0, i64 %10
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = tail call i32 @swap(i32* %16, i32* %18)
%20 = add nuw nsw i64 %10, 1
%21 = icmp eq i64 %20, %8
br i1 %21, label %22, label %9
22: ; preds = %9, %2
ret void
}