#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 random(int, int);
void randomize_in_place(int *A, int n) {
  int i;
  int temp;
  int rand;
  for (i = 0; i < n; i++) {
    rand = random(i, n);
    temp = A[i];
    A[i] = A[rand];
    A[rand] = temp;
  }
}


x86 assembly (clang, -O0):
<randomize_in_place>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1180 <randomize_in_place+0x70>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <random@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <randomize_in_place+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomize_in_place>:
push   %r15
push   %r14
push   %rbx
test   %esi,%esi
jle    1155 <randomize_in_place+0x45>
mov    %rdi,%r15
mov    %esi,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14d,%esi
call   1030 <random@plt>
mov    (%r15,%rbx,4),%ecx
cltq
mov    (%r15,%rax,4),%edx
mov    %edx,(%r15,%rbx,4)
mov    %ecx,(%r15,%rax,4)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1130 <randomize_in_place+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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