#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 *, char *);
size_t rand();
void shuffle(char *array, size_t n) {
  if (n > 1) {
    size_t i;
    for (i = 0; i < n; i++) {
      size_t j = rand() % n;
      printf("%s\n", array);
      char t = array[j];
      array[j] = array[i];
      array[i] = t;
    }
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x1,-0x10(%rbp)
jbe    11bc <shuffle+0x9c>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11b7 <shuffle+0x97>
mov    $0x0,%al
call   1040 <rand@plt>
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x21(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1143 <shuffle+0x23>
jmp    11bc <shuffle+0x9c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x2,%rsi
jb     118b <shuffle+0x6b>
mov    %rsi,%r14
mov    %rdi,%r12
xor    %ebx,%ebx
lea    0xec2(%rip),%r15
jmp    116e <shuffle+0x4e>
xor    %edx,%edx
div    %r14
mov    %rdx,%r13
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <printf@plt>
movzbl (%r12,%r13,1),%eax
movzbl (%r12,%rbx,1),%ecx
mov    %cl,(%r12,%r13,1)
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
je     118b <shuffle+0x6b>
xor    %eax,%eax
call   1040 <rand@plt>
mov    %rax,%rcx
or     %r14,%rcx
shr    $0x20,%rcx
jne    1140 <shuffle+0x20>
xor    %edx,%edx
div    %r14d
mov    %edx,%r13d
jmp    1148 <shuffle+0x28>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define void @shuffle(i8* %0, i64 %1) {
%3 = icmp ugt i64 %1, 1
br i1 %3, label %4, label %15
4: ; preds = %2, %4
%5 = phi i64 [ %13, %4 ], [ 0, %2 ]
%6 = tail call i64 (...) @rand()
%7 = urem i64 %6, %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %0, i64 %5
%12 = load i8, i8* %11
store i8 %12, i8* %9
store i8 %10, i8* %11
%13 = add nuw i64 %5, 1
%14 = icmp eq i64 %13, %1
br i1 %14, label %15, label %4
15: ; preds = %4, %2
ret void
}