#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);
int randint(int, int);
int main() {
  int arr[1000];
  int i;
  int r = 0;
  int t = 0;
  int mid = 1000 / 2;
  for (i = 0; i < 1000; i++) {
    printf("%d\n", i);
    arr[i] = i;
  }
  for (i = 0; i < 1000; i++) {
    r = randint(i, 1000);
    printf("%d\n", r);
    t = arr[i];
    arr[i] = arr[r];
    arr[r] = t;
  }
  for (i = 0; i < 1000; i++) {
    printf("%d\n", arr[i]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xfb8(%rbp)
movl   $0x0,-0xfbc(%rbp)
movl   $0x1f4,-0xfc0(%rbp)
movl   $0x0,-0xfb4(%rbp)
cmpl   $0x3e8,-0xfb4(%rbp)
jge    11a4 <main+0x84>
mov    -0xfb4(%rbp),%esi
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
mov    -0xfb4(%rbp),%ecx
movslq -0xfb4(%rbp),%rax
mov    %ecx,-0xfb0(%rbp,%rax,4)
mov    -0xfb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb4(%rbp)
jmp    115a <main+0x3a>
movl   $0x0,-0xfb4(%rbp)
cmpl   $0x3e8,-0xfb4(%rbp)
jge    123e <main+0x11e>
mov    -0xfb4(%rbp),%edi
mov    $0x3e8,%esi
call   1040 <randint@plt>
mov    %eax,-0xfb8(%rbp)
mov    -0xfb8(%rbp),%esi
lea    0xe1f(%rip),%rdi
call   1030 <printf@plt>
movslq -0xfb4(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%eax
mov    %eax,-0xfbc(%rbp)
movslq -0xfb8(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%ecx
movslq -0xfb4(%rbp),%rax
mov    %ecx,-0xfb0(%rbp,%rax,4)
mov    -0xfbc(%rbp),%ecx
movslq -0xfb8(%rbp),%rax
mov    %ecx,-0xfb0(%rbp,%rax,4)
mov    -0xfb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb4(%rbp)
jmp    11ae <main+0x8e>
movl   $0x0,-0xfb4(%rbp)
cmpl   $0x3e8,-0xfb4(%rbp)
jge    1286 <main+0x166>
movslq -0xfb4(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%esi
lea    0xd93(%rip),%rdi
call   1030 <printf@plt>
mov    -0xfb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb4(%rbp)
jmp    1248 <main+0x128>
mov    -0x4(%rbp),%eax
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0xfa0,%rsp
xor    %ebx,%ebx
lea    0xecc(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %ebx,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    1140 <main+0x20>
xor    %ebx,%ebx
lea    0xe9d(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    $0x3e8,%esi
call   1040 <randint@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    (%rsp,%rbx,4),%eax
movslq %ebp,%rcx
mov    (%rsp,%rcx,4),%edx
mov    %edx,(%rsp,%rbx,4)
mov    %eax,(%rsp,%rcx,4)
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    1170 <main+0x50>
xor    %ebp,%ebp
lea    0xe53(%rip),%rbx
nopl   (%rax)
mov    (%rsp,%rbp,4),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    $0x3e8,%rbp
jne    11b0 <main+0x90>
xor    %eax,%eax
add    $0xfa0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [1000 x i32]
%2 = bitcast [1000 x i32]* %1 to i8*
br label %3
3: ; preds = %0, %3
%4 = phi i64 [ 0, %0 ], [ %8, %3 ]
%5 = trunc i64 %4 to i32
%6 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %4
store i32 %5, i32* %7
%8 = add nuw nsw i64 %4, 1
%9 = icmp eq i64 %8, 1000
br i1 %9, label %10, label %3
10: ; preds = %3, %10
%11 = phi i64 [ %20, %10 ], [ 0, %3 ]
%12 = trunc i64 %11 to i32
%13 = tail call i32 @randint(i32 %12, i32 1000)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %11
%16 = load i32, i32* %15
%17 = sext i32 %13 to i64
%18 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %17
%19 = load i32, i32* %18
store i32 %19, i32* %15
store i32 %16, i32* %18
%20 = add nuw nsw i64 %11, 1
%21 = icmp eq i64 %20, 1000
br i1 %21, label %22, label %10
22: ; preds = %10, %22
%23 = phi i64 [ %27, %22 ], [ 0, %10 ]
%24 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = add nuw nsw i64 %23, 1
%28 = icmp eq i64 %27, 1000
br i1 %28, label %29, label %22
29: ; preds = %22
ret i32 0
}