#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*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ swap(int *, int *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void shuffle_array(int arr[], int n) {
  srand(time(NULL));
  int i;
  for (i = n - 1; i > 0; i--) {
    int j = rand() % (i + 1);
    swap(&arr[i], &arr[j]);
  }
  for (i = 0; i < n; i++)
    printf("%d ", arr[i]);
  printf("\n");
}


x86 assembly (clang, -O0):
<shuffle_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    11c6 <shuffle_array+0x76>
mov    $0x0,%al
call   1070 <rand@plt>
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1060 <swap@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1178 <shuffle_array+0x28>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1200 <shuffle_array+0xb0>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11cd <shuffle_array+0x7d>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle_array>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    %r14d,%r15d
cmp    $0x2,%r14d
jl     11b9 <shuffle_array+0x59>
mov    %r15,%rbp
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rbp),%rbx
xor    %eax,%eax
call   1080 <rand@plt>
cltd
idiv   %ebp
mov    %ebx,%eax
lea    (%r12,%rax,4),%rdi
movslq %edx,%rax
lea    (%r12,%rax,4),%rsi
call   1070 <swap@plt>
cmp    $0x2,%rbp
mov    %rbx,%rbp
ja     1190 <shuffle_array+0x30>
test   %r14d,%r14d
jle    11e7 <shuffle_array+0x87>
lea    0xe3b(%rip),%r14
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    (%r12,%rbp,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    11d0 <shuffle_array+0x70>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @shuffle_array(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = call i32 @time(i32* null)
%8 = call i32 @srand(i32 %7)
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %5
br label %11
11: ; preds = %28, %2
%12 = load i32, i32* %5
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %11
%15 = call i32 (...) @rand()
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
%18 = srem i32 %15, %17
store i32 %18, i32* %6
%19 = load i32*, i32** %3
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32*, i32** %3
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = call i32 @swap(i32* %22, i32* %26)
br label %28
28: ; preds = %14
%29 = load i32, i32* %5
%30 = add nsw i32 %29, -1
store i32 %30, i32* %5
br label %11
31: ; preds = %11
store i32 0, i32* %5
br label %32
32: ; preds = %43, %31
%33 = load i32, i32* %5
%34 = load i32, i32* %4
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %46
36: ; preds = %32
%37 = load i32*, i32** %3
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %36
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %32
46: ; preds = %32
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
define void @shuffle_array(i32* %0, i32 %1) {
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = icmp sgt i32 %1, 1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = zext i32 %1 to i64
br label %12
8: ; preds = %12, %2
%9 = icmp sgt i32 %1, 0
br i1 %9, label %10, label %31
10: ; preds = %8
%11 = zext i32 %1 to i64
br label %24
12: ; preds = %6, %12
%13 = phi i64 [ %7, %6 ], [ %14, %12 ]
%14 = add nsw i64 %13, -1
%15 = tail call i32 (...) @rand()
%16 = trunc i64 %13 to i32
%17 = srem i32 %15, %16
%18 = and i64 %14, 4294967295
%19 = getelementptr inbounds i32, i32* %0, i64 %18
%20 = sext i32 %17 to i64
%21 = getelementptr inbounds i32, i32* %0, i64 %20
%22 = tail call i32 @swap(i32* %19, i32* %21)
%23 = icmp ugt i64 %13, 2
br i1 %23, label %12, label %8
24: ; preds = %10, %24
%25 = phi i64 [ 0, %10 ], [ %29, %24 ]
%26 = getelementptr inbounds i32, i32* %0, i64 %25
%27 = load i32, i32* %26
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = add nuw nsw i64 %25, 1
%30 = icmp eq i64 %29, %11
br i1 %30, label %31, label %24
31: ; preds = %24, %8
%32 = tail call i32 @putchar(i32 10)
ret void
}