#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 permute(size_t n, uint8_t *p) {
  for (size_t i = n - 1; i >= 1; i--) {
    size_t j = rand() % (i + 1);
    uint8_t elem_j = p[j];
    p[j] = p[i];
    p[i] = elem_j;
  }
}


x86 assembly (clang, -O0):
<permute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x1,-0x18(%rbp)
jb     1192 <permute+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    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    112c <permute+0x1c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permute>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%rdi
je     116a <permute+0x5a>
mov    %rsi,%r14
mov    %rdi,%rbx
jmp    1151 <permute+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 <permute+0x5a>
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rcx
or     %rbx,%rcx
shr    $0x20,%rcx
jne    1130 <permute+0x20>
xor    %edx,%edx
div    %ebx
jmp    1135 <permute+0x25>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @permute(i64 %0, i32* %1) {
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
store i64 %0, i64* %3
store i32* %1, i32** %4
%8 = load i64, i64* %3
%9 = sub i64 %8, 1
store i64 %9, i64* %5
br label %10
10: ; preds = %33, %2
%11 = load i64, i64* %5
%12 = icmp uge i64 %11, 1
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** %4
%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** %4
%23 = load i64, i64* %5
%24 = getelementptr inbounds i32, i32* %22, i64 %23
%25 = load i32, i32* %24
%26 = load i32*, i32** %4
%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** %4
%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 @permute(i64 %0, i32* nocapture %1) {
%3 = add i64 %0, -1
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %6
5: ; preds = %6, %2
ret void
6: ; preds = %2, %6
%7 = phi i64 [ %15, %6 ], [ %3, %2 ]
%8 = phi i64 [ %7, %6 ], [ %0, %2 ]
%9 = tail call i64 (...) @rand()
%10 = urem i64 %9, %8
%11 = getelementptr inbounds i32, i32* %1, i64 %10
%12 = load i32, i32* %11
%13 = getelementptr inbounds i32, i32* %1, i64 %7
%14 = load i32, i32* %13
store i32 %14, i32* %11
store i32 %12, i32* %13
%15 = add i64 %7, -1
%16 = icmp eq i64 %15, 0
br i1 %16, label %5, label %6
}