#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 array[], size_t n) {
  size_t i, j;
  int temp;
  if (n <= 1)
    return;
  for (i = 0; i < n - 1; i++) {
    j = rand() % n;
    temp = array[j];
    array[j] = array[i];
    array[i] = temp;
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x1,-0x10(%rbp)
ja     1130 <shuffle+0x20>
jmp    11a3 <shuffle+0x93>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11a3 <shuffle+0x93>
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    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <shuffle+0x28>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%rsi
jae    112a <shuffle+0x1a>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %rsi,%r14
mov    %rdi,%r12
lea    -0x1(%rsi),%r15
xor    %ebx,%ebx
jmp    115e <shuffle+0x4e>
nopl   0x0(%rax,%rax,1)
xor    %edx,%edx
div    %r14
mov    (%r12,%rdx,4),%eax
mov    (%r12,%rbx,4),%ecx
mov    %ecx,(%r12,%rdx,4)
mov    %eax,(%r12,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r15
je     111e <shuffle+0xe>
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rcx
or     %r14,%rcx
shr    $0x20,%rcx
jne    1140 <shuffle+0x30>
xor    %edx,%edx
div    %r14d
jmp    1145 <shuffle+0x35>

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
%8 = load i64, i64* %4
%9 = icmp ule i64 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %2
br label %39
11: ; preds = %2
store i64 0, i64* %5
br label %12
12: ; preds = %36, %11
%13 = load i64, i64* %5
%14 = load i64, i64* %4
%15 = sub i64 %14, 1
%16 = icmp ult i64 %13, %15
br i1 %16, label %17, label %39
17: ; preds = %12
%18 = call i64 (...) @rand()
%19 = load i64, i64* %4
%20 = urem i64 %18, %19
store i64 %20, i64* %6
%21 = load i32*, i32** %3
%22 = load i64, i64* %6
%23 = getelementptr inbounds i32, i32* %21, i64 %22
%24 = load i32, i32* %23
store i32 %24, i32* %7
%25 = load i32*, i32** %3
%26 = load i64, i64* %5
%27 = getelementptr inbounds i32, i32* %25, i64 %26
%28 = load i32, i32* %27
%29 = load i32*, i32** %3
%30 = load i64, i64* %6
%31 = getelementptr inbounds i32, i32* %29, i64 %30
store i32 %28, i32* %31
%32 = load i32, i32* %7
%33 = load i32*, i32** %3
%34 = load i64, i64* %5
%35 = getelementptr inbounds i32, i32* %33, i64 %34
store i32 %32, i32* %35
br label %36
36: ; preds = %17
%37 = load i64, i64* %5
%38 = add i64 %37, 1
store i64 %38, i64* %5
br label %12
39: ; preds = %10, %12
ret void
}

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