#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 */
struct xs_prng {
  int dummy;
};

/* Variables and functions */
size_t get_rand_n(struct xs_prng *, size_t);
void shuffle(struct xs_prng *rng, int *arr, size_t arr_size) {
  int tmp;
  size_t i, j;
  for (i = 0; i < (arr_size - 1); i++) {
    j = i + get_rand_n(rng, arr_size - i);
    tmp = arr[i];
    arr[i] = arr[j];
    arr[j] = tmp;
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11ab <shuffle+0x9b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    -0x28(%rbp),%rsi
call   1030 <get_rand_n@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    112c <shuffle+0x1c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%rdx
je     115c <shuffle+0x4c>
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <get_rand_n@plt>
add    %rbx,%rax
mov    (%r14,%rbx,4),%ecx
mov    (%r14,%rax,4),%edx
mov    %edx,(%r14,%rbx,4)
mov    %ecx,(%r14,%rax,4)
add    $0x1,%rbx
add    $0xffffffffffffffff,%r12
cmp    $0x1,%r12
jne    1130 <shuffle+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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