#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 */
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
size_t RAND_MAX;
size_t rand();
void shuffle(uint32_t *array, size_t n) {
  if (n > 1) {
    size_t i;
    for (i = 0; i < n - 1; i++) {
      size_t j = i + rand() / (RAND_MAX / (n - i) + 1);
      uint32_t t = array[j];
      array[j] = array[i];
      array[i] = t;
    }
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x1,-0x10(%rbp)
jbe    11d8 <shuffle+0xc8>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11d3 <shuffle+0xc3>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,-0x38(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
sub    -0x18(%rbp),%rcx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
add    $0x1,%rcx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
mov    %rax,-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    1133 <shuffle+0x23>
jmp    11d8 <shuffle+0xc8>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%rsi
jb     11af <shuffle+0x9f>
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
mov    0x2eb7(%rip),%r12
jmp    1169 <shuffle+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rcx,%rax
xor    %edx,%edx
div    %rsi
add    %rbx,%rax
mov    (%r14,%rax,4),%ecx
mov    (%r14,%rbx,4),%edx
mov    %edx,(%r14,%rax,4)
mov    %ecx,(%r14,%rbx,4)
add    $0x1,%rbx
add    $0xffffffffffffffff,%r15
cmp    $0x1,%r15
je     11af <shuffle+0x9f>
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rcx
mov    (%r12),%rax
mov    %rax,%rdx
or     %r15,%rdx
shr    $0x20,%rdx
je     1190 <shuffle+0x80>
xor    %edx,%edx
div    %r15
mov    %rax,%rsi
jmp    1197 <shuffle+0x87>
nopl   (%rax)
xor    %edx,%edx
div    %r15d
mov    %eax,%esi
add    $0x1,%rsi
mov    %rcx,%rax
or     %rsi,%rax
shr    $0x20,%rax
jne    1140 <shuffle+0x30>
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
jmp    1148 <shuffle+0x38>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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