#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 size_t u_int;

/* Variables and functions */
size_t arc4random_uniform(size_t);
void shuffle(unsigned char *arr, size_t length) {
  if (length < 2) {
    return;
  }
  for (u_int i = 0; i < (length - 1); i++) {
    u_int j = i + arc4random_uniform(length - i);
    unsigned char t = arr[j];
    arr[j] = arr[i];
    arr[i] = t;
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x2,-0x10(%rbp)
jae    1130 <shuffle+0x20>
jmp    11b3 <shuffle+0xa3>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11b3 <shuffle+0xa3>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
sub    -0x18(%rbp),%rdi
call   1030 <arc4random_uniform@plt>
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,1),%al
mov    %al,-0x21(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x21(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
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   %r14
push   %rbx
push   %rax
cmp    $0x2,%rsi
jb     1142 <shuffle+0x32>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %r14,%rdi
call   1030 <arc4random_uniform@plt>
movzbl (%rbx,%rax,1),%ecx
movzbl (%rbx),%edx
mov    %dl,(%rbx,%rax,1)
mov    %cl,(%rbx)
add    $0xffffffffffffffff,%r14
add    $0x1,%rbx
cmp    $0x1,%r14
jne    1120 <shuffle+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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