#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 */
scalar_t__ prng(int /*<<< orphan*/, unsigned int);
void prng_array_shuffle(unsigned char *ptr, unsigned int length) {
  unsigned int i = 0, randval = 0;
  unsigned char tmpval = 0;
  for (i = 0; i < length; i++) {
    randval = (unsigned int)prng(0, length - 1);
    tmpval = ptr[i];
    ptr[i] = ptr[randval];
    ptr[randval] = tmpval;
  }
}


x86 assembly (clang, -O0):
<prng_array_shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1190 <prng_array_shuffle+0x80>
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
xor    %edi,%edi
call   1030 <prng@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x15(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1138 <prng_array_shuffle+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prng_array_shuffle>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
je     1153 <prng_array_shuffle+0x43>
mov    %esi,%r15d
mov    %rdi,%rbx
mov    %esi,%r14d
add    $0xffffffff,%r15d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r15d,%esi
call   1030 <prng@plt>
movzbl (%rbx,%rbp,1),%ecx
mov    %eax,%eax
movzbl (%rbx,%rax,1),%edx
mov    %dl,(%rbx,%rbp,1)
mov    %cl,(%rbx,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1130 <prng_array_shuffle+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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