#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();
void _shuffle(int *elements, size_t num_elements) {
  size_t i, pos;
  int swap;
  for (i = 0; i < num_elements; i++) {
    pos = rand() % num_elements;
    swap = elements[i];
    elements[i] = elements[pos];
    elements[pos] = swap;
  }
}


x86 assembly (clang, -O0):
<_shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    118c <_shuffle+0x7c>
mov    $0x0,%al
call   1030 <rand@plt>
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <_shuffle+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_shuffle>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     1168 <_shuffle+0x58>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
jmp    114e <_shuffle+0x3e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edx,%edx
div    %r14
mov    (%r15,%rbx,4),%eax
mov    (%r15,%rdx,4),%ecx
mov    %ecx,(%r15,%rbx,4)
mov    %eax,(%r15,%rdx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
je     1168 <_shuffle+0x58>
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rcx
or     %r14,%rcx
shr    $0x20,%rcx
jne    1130 <_shuffle+0x20>
xor    %edx,%edx
div    %r14d
jmp    1135 <_shuffle+0x25>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @_shuffle(i32* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %14, label %4
4: ; preds = %2, %4
%5 = phi i64 [ %12, %4 ], [ 0, %2 ]
%6 = tail call i64 (...) @rand()
%7 = urem i64 %6, %1
%8 = getelementptr inbounds i32, i32* %0, i64 %5
%9 = load i32, i32* %8
%10 = getelementptr inbounds i32, i32* %0, i64 %7
%11 = load i32, i32* %10
store i32 %11, i32* %8
store i32 %9, i32* %10
%12 = add nuw i64 %5, 1
%13 = icmp eq i64 %12, %1
br i1 %13, label %14, label %4
14: ; preds = %4, %2
ret void
}