#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 */
typedef int /*<<< orphan*/ time_t;
struct random_data {
  int /*<<< orphan*/ *state;
};
typedef size_t int32_t;

/* Variables and functions */
int /*<<< orphan*/ __initstate_r(int /*<<< orphan*/, int *, int,
                                 struct random_data *);
int /*<<< orphan*/ __random_r(struct random_data *, size_t *);
size_t strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *strfry(char *string) {
  static int init = 0;
  static struct random_data rdata;
  size_t len, i;
  if (!init) {
    static int state[8] = {1, 2, 3, 4, 5, 6, 7, 8};
    rdata.state = NULL;
    __initstate_r(time((time_t *)NULL), state, 8, &rdata);
    init = 1;
  }
  len = strlen(string);
  for (i = 0; i < len; ++i) {
    int32_t j;
    char c;
    __random_r(&rdata, &j);
    j %= len;
    c = string[i];
    string[i] = string[j];
    string[j] = c;
  }
  return string;
}


x86 assembly (clang, -O0):
<strfry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpl   $0x0,0x2f25(%rip)
jne    1191 <strfry+0x51>
movq   $0x0,0x2f1c(%rip)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
lea    0x2eda(%rip),%rsi
mov    $0x8,%edx
lea    0x2efe(%rip),%rcx
call   1050 <__initstate_r@plt>
movl   $0x1,0x2ee7(%rip)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1218 <strfry+0xd8>
lea    0x2ec5(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <__random_r@plt>
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x21(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a6 <strfry+0x66>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strfry>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
cmpb   $0x0,0x2f21(%rip)
jne    118f <strfry+0x4f>
movq   $0x0,0x2f1c(%rip)
lea    0x2f15(%rip),%rbx
xor    %edi,%edi
call   1060 <time@plt>
lea    0x2ed7(%rip),%rsi
mov    %eax,%edi
mov    $0x8,%edx
mov    %rbx,%rcx
call   1050 <__initstate_r@plt>
movb   $0x1,0x2ee9(%rip)
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     11f3 <strfry+0xb3>
mov    %rax,%r13
xor    %ebx,%ebx
lea    0x2ed8(%rip),%r15
lea    0x8(%rsp),%r12
jmp    11d0 <strfry+0x90>
nop
xor    %edx,%edx
div    %r13
movzbl (%r14,%rbx,1),%eax
movzbl (%r14,%rdx,1),%ecx
mov    %cl,(%r14,%rbx,1)
mov    %al,(%r14,%rdx,1)
add    $0x1,%rbx
cmp    %rbx,%r13
je     11f3 <strfry+0xb3>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <__random_r@plt>
mov    0x8(%rsp),%rax
mov    %rax,%rcx
or     %r13,%rcx
shr    $0x20,%rcx
jne    11b0 <strfry+0x70>
xor    %edx,%edx
div    %r13d
jmp    11b5 <strfry+0x75>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.random_data = type { i32* }
@strfry.init = internal global i32 0
@strfry.rdata = internal global %struct.random_data zeroinitializer
@strfry.state = internal global [8 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8]
define i8* @strfry(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8
store i8* %0, i8** %2
%7 = load i32, i32* @strfry.init
%8 = icmp ne i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %1
store i32* null, i32** getelementptr inbounds (%struct.random_data, %struct.random_data* @strfry.rdata, i32 0, i32 0)
%10 = call i32 @time(i32* null)
%11 = call i32 @__initstate_r(i32 %10, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @strfry.state, i64 0, i64 0), i32 8, %struct.random_data* @strfry.rdata)
store i32 1, i32* @strfry.init
br label %12
12: ; preds = %9, %1
%13 = load i8*, i8** %2
%14 = call i64 @strlen(i8* %13)
store i64 %14, i64* %3
store i64 0, i64* %4
br label %15
15: ; preds = %39, %12
%16 = load i64, i64* %4
%17 = load i64, i64* %3
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %42
19: ; preds = %15
%20 = call i32 @__random_r(%struct.random_data* @strfry.rdata, i64* %5)
%21 = load i64, i64* %3
%22 = load i64, i64* %5
%23 = urem i64 %22, %21
store i64 %23, i64* %5
%24 = load i8*, i8** %2
%25 = load i64, i64* %4
%26 = getelementptr inbounds i8, i8* %24, i64 %25
%27 = load i8, i8* %26
store i8 %27, i8* %6
%28 = load i8*, i8** %2
%29 = load i64, i64* %5
%30 = getelementptr inbounds i8, i8* %28, i64 %29
%31 = load i8, i8* %30
%32 = load i8*, i8** %2
%33 = load i64, i64* %4
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8 %31, i8* %34
%35 = load i8, i8* %6
%36 = load i8*, i8** %2
%37 = load i64, i64* %5
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8 %35, i8* %38
br label %39
39: ; preds = %19
%40 = load i64, i64* %4
%41 = add i64 %40, 1
store i64 %41, i64* %4
br label %15
42: ; preds = %15
%43 = load i8*, i8** %2
ret i8* %43
}

LLVM IR (-O2):
%struct.random_data = type { i32* }
@strfry.init = internal unnamed_addr global i1 false
@strfry.rdata = internal global %struct.random_data zeroinitializer
@strfry.state = internal global [8 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8]
define i8* @strfry(i8* returned %0) {
%2 = alloca i64
%3 = load i1, i1* @strfry.init
br i1 %3, label %7, label %4
4: ; preds = %1
store i32* null, i32** getelementptr inbounds (%struct.random_data, %struct.random_data* @strfry.rdata, i64 0, i32 0)
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @__initstate_r(i32 %5, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @strfry.state, i64 0, i64 0), i32 8, %struct.random_data* @strfry.rdata)
store i1 true, i1* @strfry.init
br label %7
7: ; preds = %4, %1
%8 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %23, label %10
10: ; preds = %7
%11 = bitcast i64* %2 to i8*
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %21, %12 ]
%14 = call i32 @__random_r(%struct.random_data* @strfry.rdata, i64* %2)
%15 = load i64, i64* %2
%16 = urem i64 %15, %8
%17 = getelementptr inbounds i8, i8* %0, i64 %13
%18 = load i8, i8* %17
%19 = getelementptr inbounds i8, i8* %0, i64 %16
%20 = load i8, i8* %19
store i8 %20, i8* %17
store i8 %18, i8* %19
%21 = add nuw i64 %13, 1
%22 = icmp eq i64 %21, %8
br i1 %22, label %23, label %12
23: ; preds = %12, %7
ret i8* %0
}