#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 /*<<< orphan*/ array_sequential(int *, size_t);
size_t rand();
void array_randomize(int *array, size_t length) {
  array_sequential(array, length);
  size_t ii, rr;
  int temp;
  for (ii = 0; ii < length; ii++) {
    rr = rand() % length;
    temp = array[rr];
    array[rr] = array[ii];
    array[ii] = temp;
  }
}


x86 assembly (clang, -O0):
<array_randomize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <array_sequential@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a9 <array_randomize+0x89>
mov    $0x0,%al
call   1030 <rand@plt>
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
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    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1145 <array_randomize+0x25>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_randomize>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <array_sequential@plt>
test   %r14,%r14
je     1178 <array_randomize+0x58>
xor    %ebx,%ebx
jmp    115e <array_randomize+0x3e>
nopl   0x0(%rax)
xor    %edx,%edx
div    %r14
mov    (%r15,%rdx,4),%eax
mov    (%r15,%rbx,4),%ecx
mov    %ecx,(%r15,%rdx,4)
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
je     1178 <array_randomize+0x58>
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rcx
or     %r14,%rcx
shr    $0x20,%rcx
jne    1140 <array_randomize+0x20>
xor    %edx,%edx
div    %r14d
jmp    1145 <array_randomize+0x25>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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