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

/* Variables and functions */
size_t rand();
void shuffle_uint8(uint8_t *array, size_t n) {
  size_t i;
  for (i = n - 1; i > 0; i--) {
    size_t j = rand() % (i + 1);
    uint8_t t = array[j];
    array[j] = array[i];
    array[i] = t;
  }
}


x86 assembly (clang, -O0):
<shuffle_uint8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    1192 <shuffle_uint8+0x82>
mov    $0x0,%al
call   1030 <rand@plt>
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
xor    %edx,%edx
div    %rcx
mov    %rdx,-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    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    112c <shuffle_uint8+0x1c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle_uint8>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%rsi
je     116a <shuffle_uint8+0x5a>
mov    %rsi,%rbx
mov    %rdi,%r14
jmp    1151 <shuffle_uint8+0x41>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %edx,%edx
div    %rbx
mov    (%r14,%rdx,4),%eax
mov    -0x4(%r14,%rbx,4),%ecx
mov    %ecx,(%r14,%rdx,4)
mov    %eax,-0x4(%r14,%rbx,4)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
je     116a <shuffle_uint8+0x5a>
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rcx
or     %rbx,%rcx
shr    $0x20,%rcx
jne    1130 <shuffle_uint8+0x20>
xor    %edx,%edx
div    %ebx
jmp    1135 <shuffle_uint8+0x25>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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