#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*/ uint16_t;

/* Variables and functions */
size_t RAND_MAX;
size_t rand();
void array_shuffle(uint16_t *a, size_t n) {
  size_t i;
  for (i = 0; i < n - 1; i++) {
    size_t j = i + rand() / (RAND_MAX / (n - i) + 1);
    uint16_t tmp = a[j];
    a[j] = a[i];
    a[i] = tmp;
  }
}


x86 assembly (clang, -O0):
<array_shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11c8 <array_shuffle+0xb8>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,-0x38(%rbp)
mov    0x2e91(%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    1128 <array_shuffle+0x18>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_shuffle>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%rsi
je     11af <array_shuffle+0x9f>
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
mov    0x2eb7(%rip),%r12
jmp    1169 <array_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 <array_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 <array_shuffle+0x80>
xor    %edx,%edx
div    %r15
mov    %rax,%rsi
jmp    1197 <array_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 <array_shuffle+0x30>
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
jmp    1148 <array_shuffle+0x38>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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