#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_range(int /*<<< orphan*/, int);
int /*<<< orphan*/ swap(int *, int *);
void fisher_yates_shuffle(int *arr, int n) {
  int i;
  for (i = n - 1; i > 0; i--) {
    int j = rand_int_range(0, i);
    swap(arr + i, arr + j);
  }
}


x86 assembly (clang, -O0):
<fisher_yates_shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    1180 <fisher_yates_shuffle+0x60>
mov    -0x10(%rbp),%esi
xor    %edi,%edi
call   1030 <rand_int_range@plt>
mov    %eax,-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   1040 <swap@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1138 <fisher_yates_shuffle+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fisher_yates_shuffle>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%esi
jl     1159 <fisher_yates_shuffle+0x39>
mov    %rdi,%r14
mov    %esi,%ebx
nop
lea    -0x1(%rbx),%r15
xor    %edi,%edi
mov    %r15d,%esi
call   1030 <rand_int_range@plt>
mov    %r15d,%ecx
lea    (%r14,%rcx,4),%rdi
cltq
lea    (%r14,%rax,4),%rsi
call   1040 <swap@plt>
cmp    $0x2,%rbx
mov    %r15,%rbx
ja     1130 <fisher_yates_shuffle+0x10>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @fisher_yates_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 = load i32, i32* %4
%8 = sub nsw i32 %7, 1
store i32 %8, i32* %5
br label %9
9: ; preds = %24, %2
%10 = load i32, i32* %5
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %27
12: ; preds = %9
%13 = load i32, i32* %5
%14 = call i32 @rand_int_range(i32 0, i32 %13)
store i32 %14, i32* %6
%15 = load i32*, i32** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32*, i32** %3
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = call i32 @swap(i32* %18, i32* %22)
br label %24
24: ; preds = %12
%25 = load i32, i32* %5
%26 = add nsw i32 %25, -1
store i32 %26, i32* %5
br label %9
27: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @fisher_yates_shuffle(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %17
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ %5, %4 ], [ %8, %6 ]
%8 = add nsw i64 %7, -1
%9 = trunc i64 %8 to i32
%10 = tail call i32 @rand_int_range(i32 0, i32 %9)
%11 = and i64 %8, 4294967295
%12 = getelementptr inbounds i32, i32* %0, i64 %11
%13 = sext i32 %10 to i64
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = tail call i32 @swap(i32* %12, i32* %14)
%16 = icmp ugt i64 %7, 2
br i1 %16, label %6, label %17
17: ; preds = %6, %2
ret void
}