#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 rand();
void random_permutation(unsigned char *a) {
  int i, j, x;
  for (i = 0; i < 1988; i++) {
    a[i] = i;
  }
  for (i = 0; i < 1988 - 2; i++) {
    j = (rand() % (1988 - 1 - i)) + i + 1;
    x = a[j];
    a[j] = a[i];
    a[i] = x;
  }
  if (a[1988 - 1] == 1988 - 1) {
    a[1988 - 1] = a[1988 - 2];
    a[1988 - 2] = 1988 - 1;
  }
}


x86 assembly (clang, -O0):
<random_permutation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x7c4,-0xc(%rbp)
jge    114e <random_permutation+0x3e>
mov    -0xc(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <random_permutation+0x13>
movl   $0x0,-0xc(%rbp)
cmpl   $0x7c2,-0xc(%rbp)
jge    11c2 <random_permutation+0xb2>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x7c3,%ecx
sub    -0xc(%rbp),%ecx
cltd
idiv   %ecx
mov    %edx,%eax
add    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1155 <random_permutation+0x45>
mov    -0x8(%rbp),%rax
movzbl 0x7c3(%rax),%eax
cmp    $0x7c3,%eax
jne    11f7 <random_permutation+0xe7>
mov    -0x8(%rbp),%rax
mov    0x7c2(%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x7c3(%rax)
mov    -0x8(%rbp),%rax
movb   $0xc3,0x7c2(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_permutation>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
movdqa 0xee1(%rip),%xmm0
mov    $0x30,%eax
movdqa 0xee4(%rip),%xmm1
movdqa 0xeec(%rip),%xmm2
movdqa 0xef4(%rip),%xmm3
movdqa 0xefc(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movdqu %xmm0,-0x30(%r14,%rax,1)
movdqa %xmm0,%xmm5
paddb  %xmm1,%xmm5
movdqu %xmm5,-0x20(%r14,%rax,1)
movdqa %xmm0,%xmm5
paddb  %xmm2,%xmm5
movdqu %xmm5,-0x10(%r14,%rax,1)
movdqa %xmm0,%xmm5
paddb  %xmm3,%xmm5
movdqu %xmm5,(%r14,%rax,1)
paddb  %xmm4,%xmm0
add    $0x40,%rax
cmp    $0x7f0,%rax
jne    1150 <random_permutation+0x40>
movl   $0xc3c2c1c0,0x7c0(%r14)
c0 c1 c2 c3
mov    $0x7c3,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1030 <rand@plt>
cltd
idiv   %ebp
lea    (%rbx,%rdx,1),%eax
add    $0x1,%eax
cltq
movzbl (%r14,%rax,1),%ecx
movzbl (%r14,%rbx,1),%edx
mov    %dl,(%r14,%rax,1)
mov    %cl,(%r14,%rbx,1)
lea    0x1(%rbx),%rax
add    $0xffffffff,%ebp
mov    %rax,%rbx
cmp    $0x7c2,%rax
jne    11b0 <random_permutation+0xa0>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @random_permutation(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %6
6: ; preds = %16, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 1988
br i1 %8, label %9, label %19
9: ; preds = %6
%10 = load i32, i32* %3
%11 = trunc i32 %10 to i8
%12 = load i8*, i8** %2
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
store i8 %11, i8* %15
br label %16
16: ; preds = %9
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %6
19: ; preds = %6
store i32 0, i32* %3
br label %20
20: ; preds = %52, %19
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 1986
br i1 %22, label %23, label %55
23: ; preds = %20
%24 = call i32 (...) @rand()
%25 = load i32, i32* %3
%26 = sub nsw i32 1987, %25
%27 = srem i32 %24, %26
%28 = load i32, i32* %3
%29 = add nsw i32 %27, %28
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
%31 = load i8*, i8** %2
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
store i32 %36, i32* %5
%37 = load i8*, i8** %2
%38 = load i32, i32* %3
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
%42 = load i8*, i8** %2
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 %41, i8* %45
%46 = load i32, i32* %5
%47 = trunc i32 %46 to i8
%48 = load i8*, i8** %2
%49 = load i32, i32* %3
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 %47, i8* %51
br label %52
52: ; preds = %23
%53 = load i32, i32* %3
%54 = add nsw i32 %53, 1
store i32 %54, i32* %3
br label %20
55: ; preds = %20
%56 = load i8*, i8** %2
%57 = getelementptr inbounds i8, i8* %56, i64 1987
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = icmp eq i32 %59, 1987
br i1 %60, label %61, label %69
61: ; preds = %55
%62 = load i8*, i8** %2
%63 = getelementptr inbounds i8, i8* %62, i64 1986
%64 = load i8, i8* %63
%65 = load i8*, i8** %2
%66 = getelementptr inbounds i8, i8* %65, i64 1987
store i8 %64, i8* %66
%67 = load i8*, i8** %2
%68 = getelementptr inbounds i8, i8* %67, i64 1986
store i8 -61, i8* %68
br label %69
69: ; preds = %61, %55
ret void
}

LLVM IR (-O2):
define void @random_permutation(i8* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ 0, %1 ], [ %19, %2 ]
%4 = phi <16 x i8> [ <i8 0, i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15>, %1 ], [ %20, %2 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %3
%6 = bitcast i8* %5 to <16 x i8>*
store <16 x i8> %4, <16 x i8>* %6
%7 = or i64 %3, 16
%8 = add <16 x i8> %4, <i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16>
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = bitcast i8* %9 to <16 x i8>*
store <16 x i8> %8, <16 x i8>* %10
%11 = or i64 %3, 32
%12 = add <16 x i8> %4, <i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32>
%13 = getelementptr inbounds i8, i8* %0, i64 %11
%14 = bitcast i8* %13 to <16 x i8>*
store <16 x i8> %12, <16 x i8>* %14
%15 = or i64 %3, 48
%16 = add <16 x i8> %4, <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>
%17 = getelementptr inbounds i8, i8* %0, i64 %15
%18 = bitcast i8* %17 to <16 x i8>*
store <16 x i8> %16, <16 x i8>* %18
%19 = add nuw nsw i64 %3, 64
%20 = add <16 x i8> %4, <i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64>
%21 = icmp eq i64 %19, 1984
br i1 %21, label %22, label %2
22: ; preds = %2
%23 = getelementptr inbounds i8, i8* %0, i64 1984
store i8 -64, i8* %23
%24 = getelementptr inbounds i8, i8* %0, i64 1985
store i8 -63, i8* %24
%25 = getelementptr inbounds i8, i8* %0, i64 1986
store i8 -62, i8* %25
%26 = getelementptr inbounds i8, i8* %0, i64 1987
store i8 -61, i8* %26
br label %27
27: ; preds = %22, %27
%28 = phi i64 [ %33, %27 ], [ 0, %22 ]
%29 = tail call i32 (...) @rand()
%30 = trunc i64 %28 to i32
%31 = sub i32 1987, %30
%32 = srem i32 %29, %31
%33 = add nuw nsw i64 %28, 1
%34 = trunc i64 %33 to i32
%35 = add i32 %32, %34
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %0, i64 %36
%38 = load i8, i8* %37
%39 = getelementptr inbounds i8, i8* %0, i64 %28
%40 = load i8, i8* %39
store i8 %40, i8* %37
store i8 %38, i8* %39
%41 = icmp eq i64 %33, 1986
br i1 %41, label %42, label %27
42: ; preds = %27
ret void
}