#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 gen_dest(int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main(void) {
  int data[12];
  srand(time(0));
  for (int i = 0; i < 12; i++) {
    data[i] = i;
  }
  int sort_count = 0;
  while (sort_count++ < 12) {
    int source_pos = rand() % 12;
    int target_pos = gen_dest(source_pos);
    int temp = data[target_pos];
    data[target_pos] = data[source_pos];
    data[source_pos] = temp;
  }
  for (int i = 0; i < 12; i++) {
    printf("%d ", data[i]);
  }
  printf("\nAll done!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0x44(%rbp)
cmpl   $0xc,-0x44(%rbp)
jge    1197 <main+0x47>
mov    -0x44(%rbp),%ecx
movslq -0x44(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1174 <main+0x24>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x48(%rbp)
cmp    $0xc,%eax
jge    11fa <main+0xaa>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0xc,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4c(%rbp)
mov    -0x4c(%rbp),%edi
call   1060 <gen_dest@plt>
mov    %eax,-0x50(%rbp)
movslq -0x50(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
mov    %eax,-0x54(%rbp)
movslq -0x4c(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%ecx
movslq -0x50(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x54(%rbp),%ecx
movslq -0x4c(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,4)
jmp    119e <main+0x4e>
movl   $0x0,-0x58(%rbp)
cmpl   $0xc,-0x58(%rbp)
jge    122f <main+0xdf>
movslq -0x58(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1201 <main+0xb1>
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movaps 0xe85(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xe8a(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe8e(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
mov    $0xc,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1080 <rand@plt>
movslq %eax,%rbx
imul   $0x2aaaaaab,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x21,%rax
add    %ecx,%eax
shl    $0x2,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%ebx
mov    %ebx,%edi
call   1070 <gen_dest@plt>
cltq
mov    (%rsp,%rax,4),%ecx
movslq %ebx,%rdx
mov    (%rsp,%rdx,4),%esi
mov    %esi,(%rsp,%rax,4)
mov    %ecx,(%rsp,%rdx,4)
add    $0xffffffff,%ebp
jne    11a0 <main+0x40>
mov    (%rsp),%esi
lea    0xe43(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x24(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x28(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd9c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
@str = [11 x i8] c"\0AAll done!\00"
define i32 @main() {
%1 = alloca [12 x i32]
%2 = bitcast [12 x i32]* %1 to i8*
%3 = tail call i32 @time(i32 0)
%4 = tail call i32 @srand(i32 %3)
%5 = bitcast [12 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* %5
%6 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 4
%7 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> <i32 4, i32 5, i32 6, i32 7>, <4 x i32>* %7
%8 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 8
%9 = bitcast i32* %8 to <4 x i32>*
store <4 x i32> <i32 8, i32 9, i32 10, i32 11>, <4 x i32>* %9
br label %10
10: ; preds = %0, %10
%11 = phi i32 [ %12, %10 ], [ 0, %0 ]
%12 = add nuw nsw i32 %11, 1
%13 = tail call i32 (...) @rand()
%14 = srem i32 %13, 12
%15 = tail call i32 @gen_dest(i32 %14)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = sext i32 %14 to i64
%20 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 %19
%21 = load i32, i32* %20
store i32 %21, i32* %17
store i32 %18, i32* %20
%22 = icmp eq i32 %12, 12
br i1 %22, label %23, label %10
23: ; preds = %10
%24 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 11
%25 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 10
%26 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 9
%27 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 7
%28 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 6
%29 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 5
%30 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 0
%31 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 3
%32 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 2
%33 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 1
%34 = load i32, i32* %30
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %33
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %32
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %31
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %6
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %29
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %28
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %27
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %8
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %26
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %52)
%54 = load i32, i32* %25
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %54)
%56 = load i32, i32* %24
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %56)
%58 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
ret i32 0
}