#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 */
size_t rand();
void shuffle(char *a, size_t size) {
  for (size_t i = size - 1; i > 0; i--) {
    int n = rand() % size;
    char tmp = a[i];
    a[i] = a[n];
    a[n] = tmp;
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    118e <shuffle+0x7e>
mov    $0x0,%al
call   1030 <rand@plt>
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    %edx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1d(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    112c <shuffle+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
add    $0xffffffffffffffff,%rbx
je     116a <shuffle+0x5a>
mov    %rsi,%r14
mov    %rdi,%r15
jmp    1150 <shuffle+0x40>
cs nopw 0x0(%rax,%rax,1)
xor    %edx,%edx
div    %r14
movzbl (%r15,%rbx,1),%eax
movslq %edx,%rcx
movzbl (%r15,%rcx,1),%edx
mov    %dl,(%r15,%rbx,1)
mov    %al,(%r15,%rcx,1)
add    $0xffffffffffffffff,%rbx
je     116a <shuffle+0x5a>
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rcx
or     %r14,%rcx
shr    $0x20,%rcx
jne    1130 <shuffle+0x20>
xor    %edx,%edx
div    %r14d
jmp    1135 <shuffle+0x25>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @shuffle(i8* nocapture %0, i64 %1) {
%3 = add i64 %1, -1
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %6
5: ; preds = %6, %2
ret void
6: ; preds = %2, %6
%7 = phi i64 [ %16, %6 ], [ %3, %2 ]
%8 = tail call i64 (...) @rand()
%9 = urem i64 %8, %1
%10 = getelementptr inbounds i8, i8* %0, i64 %7
%11 = load i8, i8* %10
%12 = shl i64 %9, 32
%13 = ashr exact i64 %12, 32
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
store i8 %15, i8* %10
store i8 %11, i8* %14
%16 = add i64 %7, -1
%17 = icmp eq i64 %16, 0
br i1 %17, label %5, label %6
}