#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 shuffle(int X[(5 * 10)]) {
  int j, k, tmp;
  for (k = (5 * 10) - 1; k > 0; k--) {
    j = (rand() % (k + 1));
    tmp = X[j];
    X[j] = X[k];
    X[k] = tmp;
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x31,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    1180 <shuffle+0x70>
mov    $0x0,%al
call   1030 <rand@plt>
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1123 <shuffle+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x32,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <rand@plt>
cltd
idiv   %ebx
movslq %edx,%rax
mov    (%r14,%rax,4),%ecx
mov    -0x4(%r14,%rbx,4),%edx
mov    %edx,(%r14,%rax,4)
mov    %ecx,-0x4(%r14,%rbx,4)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1120 <shuffle+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @shuffle(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
store i32 49, i32* %4
br label %6
6: ; preds = %33, %1
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %36
9: ; preds = %6
%10 = call i32 (...) @rand()
%11 = load i32, i32* %4
%12 = add nsw i32 %11, 1
%13 = srem i32 %10, %12
store i32 %13, i32* %3
%14 = load i32*, i32** %2
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
%18 = load i32, i32* %17
store i32 %18, i32* %5
%19 = load i32*, i32** %2
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = load i32*, i32** %2
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
store i32 %23, i32* %27
%28 = load i32, i32* %5
%29 = load i32*, i32** %2
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
store i32 %28, i32* %32
br label %33
33: ; preds = %9
%34 = load i32, i32* %4
%35 = add nsw i32 %34, -1
store i32 %35, i32* %4
br label %6
36: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @shuffle(i32* nocapture %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i64 [ 49, %1 ], [ %13, %2 ]
%4 = tail call i32 (...) @rand()
%5 = trunc i64 %3 to i32
%6 = add i32 %5, 1
%7 = srem i32 %4, %6
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = load i32, i32* %9
%11 = getelementptr inbounds i32, i32* %0, i64 %3
%12 = load i32, i32* %11
store i32 %12, i32* %9
store i32 %10, i32* %11
%13 = add nsw i64 %3, -1
%14 = icmp ugt i64 %3, 1
br i1 %14, label %2, label %15
15: ; preds = %2
ret void
}