#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *malloc(size_t);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ printf(char *, char *);
size_t rand_to_max(size_t);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
size_t strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  size_t length;
  char *text, *dest;
  srand(time(NULL));
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <text>\a\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  text = argv[1];
  length = strlen(text);
  bool relocated[length];
  memset(relocated, 0, length);
  dest = malloc(length + 1);
  for (size_t i = 0; i < length; i++) {
    size_t index;
    while (index = rand_to_max(length), relocated[index])
      ;
    dest[i] = text[index];
    relocated[index] = true;
  }
  dest[length] = '\0';
  printf("%s\n", dest);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
cmpl   $0x2,-0x8(%rbp)
je     11ea <main+0x5a>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe29(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    12c1 <main+0x131>
jmp    1262 <main+0xd2>
mov    -0x18(%rbp),%rdi
call   1050 <rand_to_max@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
mov    %rcx,-0x48(%rbp)
mov    -0x48(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     1289 <main+0xf9>
jmp    1262 <main+0xd2>
mov    -0x50(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x48(%rbp),%rdx
mov    (%rcx,%rdx,1),%sil
mov    -0x28(%rbp),%rcx
mov    -0x40(%rbp),%rdx
mov    %sil,(%rcx,%rdx,1)
mov    -0x48(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    124f <main+0xbf>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rsi
lea    0xd3b(%rip),%rdi
call   1040 <printf@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
cmp    $0x2,%ebx
jne    1253 <main+0xc3>
mov    0x8(%r14),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1060 <memset@plt>
lea    0x1(%r15),%rdi
call   10a0 <malloc@plt>
mov    %rax,%r12
test   %r15,%r15
je     1227 <main+0x97>
xor    %r13d,%r13d
nop
mov    %r15,%rdi
call   1050 <rand_to_max@plt>
cmpl   $0x0,(%rbx,%rax,4)
jne    1200 <main+0x70>
movzbl (%r14,%rax,1),%ecx
mov    %cl,(%r12,%r13,1)
movl   $0x1,(%rbx,%rax,4)
add    $0x1,%r13
cmp    %r15,%r13
jne    1200 <main+0x70>
movb   $0x0,(%r12,%r15,1)
lea    0xde0(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd9a(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"Usage: %s <text>\07\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 @time(i32* null)
%14 = call i32 @srand(i32 %13)
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %25
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %7
%29 = load i8*, i8** %7
%30 = call i64 @strlen(i8* %29)
store i64 %30, i64* %6
%31 = load i64, i64* %6
%32 = call i8* @llvm.stacksave()
store i8* %32, i8** %9
%33 = alloca i32, i64 %31
store i64 %31, i64* %10
%34 = load i64, i64* %6
%35 = call i32 @memset(i32* %33, i32 0, i64 %34)
%36 = load i64, i64* %6
%37 = add i64 %36, 1
%38 = call i8* @malloc(i64 %37)
store i8* %38, i8** %8
store i64 0, i64* %11
br label %39
39: ; preds = %62, %25
%40 = load i64, i64* %11
%41 = load i64, i64* %6
%42 = icmp ult i64 %40, %41
br i1 %42, label %43, label %65
43: ; preds = %39
br label %44
44: ; preds = %51, %43
%45 = load i64, i64* %6
%46 = call i64 @rand_to_max(i64 %45)
store i64 %46, i64* %12
%47 = load i64, i64* %12
%48 = getelementptr inbounds i32, i32* %33, i64 %47
%49 = load i32, i32* %48
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %44
br label %44
52: ; preds = %44
%53 = load i8*, i8** %7
%54 = load i64, i64* %12
%55 = getelementptr inbounds i8, i8* %53, i64 %54
%56 = load i8, i8* %55
%57 = load i8*, i8** %8
%58 = load i64, i64* %11
%59 = getelementptr inbounds i8, i8* %57, i64 %58
store i8 %56, i8* %59
%60 = load i64, i64* %12
%61 = getelementptr inbounds i32, i32* %33, i64 %60
store i32 1, i32* %61
br label %62
62: ; preds = %52
%63 = load i64, i64* %11
%64 = add i64 %63, 1
store i64 %64, i64* %11
br label %39
65: ; preds = %39
%66 = load i8*, i8** %8
%67 = load i64, i64* %6
%68 = getelementptr inbounds i8, i8* %66, i64 %67
store i8 0, i8* %68
%69 = load i8*, i8** %8
%70 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %69)
%71 = load i32, i32* @EXIT_SUCCESS
store i32 %71, i32* %3
%72 = load i8*, i8** %9
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"Usage: %s <text>\07\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = icmp eq i32 %0, 2
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i64 @strlen(i8* dereferenceable(1) %14)
%16 = alloca i32, i64 %15
%17 = call i32 @memset(i32* %16, i32 0, i64 %15)
%18 = add i64 %15, 1
%19 = call i8* @malloc(i64 %18)
%20 = icmp eq i64 %15, 0
br i1 %20, label %23, label %21
21: ; preds = %12, %32
%22 = phi i64 [ %37, %32 ], [ 0, %12 ]
br label %27
23: ; preds = %32, %12
%24 = getelementptr inbounds i8, i8* %19, i64 %15
store i8 0, i8* %24
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%26 = load i32, i32* @EXIT_SUCCESS
ret i32 %26
27: ; preds = %21, %27
%28 = call i64 @rand_to_max(i64 %15)
%29 = getelementptr inbounds i32, i32* %16, i64 %28
%30 = load i32, i32* %29
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %27
32: ; preds = %27
%33 = getelementptr inbounds i32, i32* %16, i64 %28
%34 = getelementptr inbounds i8, i8* %14, i64 %28
%35 = load i8, i8* %34
%36 = getelementptr inbounds i8, i8* %19, i64 %22
store i8 %35, i8* %36
store i32 1, i32* %33
%37 = add nuw i64 %22, 1
%38 = icmp eq i64 %37, %15
br i1 %38, label %23, label %21
}