#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 int /*<<< orphan*/ state;
typedef size_t int32_t;

/* Variables and functions */
int /*<<< orphan*/ __initstate_r(int, char *, int, struct random_data *);
int /*<<< orphan*/ __random_r(struct random_data *, size_t *);
int getpid();
size_t strlen(char *);
int time(int /*<<< orphan*/ *);
char *strfry(char *string) {
  static int init;
  static struct random_data rdata;
  size_t len, i;
  if (!init) {
    static char state[32];
    rdata.state = NULL;
    __initstate_r(time((time_t *)NULL) ^ getpid(), state, sizeof(state),
                  &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,0x2efd(%rip)
jne    11ae <strfry+0x5e>
movq   $0x0,0x2ef4(%rip)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x28(%rbp),%edi
xor    %eax,%edi
lea    0x2edd(%rip),%rsi
mov    $0x20,%edx
lea    0x2ec9(%rip),%rcx
call   1060 <__initstate_r@plt>
movl   $0x1,0x2eb2(%rip)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1235 <strfry+0xe5>
lea    0x2e90(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <__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    11c3 <strfry+0x73>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strfry>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
cmpb   $0x0,0x2efa(%rip)
jne    11a9 <strfry+0x59>
movq   $0x0,0x2ef5(%rip)
lea    0x2eee(%rip),%rbx
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
xor    %eax,%ebp
lea    0x2edd(%rip),%rsi
mov    %ebp,%edi
mov    $0x20,%edx
mov    %rbx,%rcx
call   1060 <__initstate_r@plt>
movb   $0x1,0x2eb7(%rip)
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     1212 <strfry+0xc2>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0x2ea6(%rip),%r15
lea    0x8(%rsp),%r12
jmp    11f0 <strfry+0xa0>
nopl   0x0(%rax)
xor    %edx,%edx
div    %rbx
movzbl (%r14,%rbp,1),%eax
movzbl (%r14,%rdx,1),%ecx
mov    %cl,(%r14,%rbp,1)
mov    %al,(%r14,%rdx,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
je     1212 <strfry+0xc2>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <__random_r@plt>
mov    0x8(%rsp),%rax
mov    %rax,%rcx
or     %rbx,%rcx
shr    $0x20,%rcx
jne    11d0 <strfry+0x80>
xor    %edx,%edx
div    %ebx
jmp    11d5 <strfry+0x85>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
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 [32 x i8] zeroinitializer
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 %14, 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 (...) @getpid()
%12 = xor i32 %10, %11
%13 = call i32 @__initstate_r(i32 %12, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @strfry.state, i64 0, i64 0), i32 32, %struct.random_data* @strfry.rdata)
store i32 1, i32* @strfry.init
br label %14
14: ; preds = %9, %1
%15 = load i8*, i8** %2
%16 = call i64 @strlen(i8* %15)
store i64 %16, i64* %3
store i64 0, i64* %4
br label %17
17: ; preds = %41, %14
%18 = load i64, i64* %4
%19 = load i64, i64* %3
%20 = icmp ult i64 %18, %19
br i1 %20, label %21, label %44
21: ; preds = %17
%22 = call i32 @__random_r(%struct.random_data* @strfry.rdata, i64* %5)
%23 = load i64, i64* %3
%24 = load i64, i64* %5
%25 = urem i64 %24, %23
store i64 %25, i64* %5
%26 = load i8*, i8** %2
%27 = load i64, i64* %4
%28 = getelementptr inbounds i8, i8* %26, i64 %27
%29 = load i8, i8* %28
store i8 %29, i8* %6
%30 = load i8*, i8** %2
%31 = load i64, i64* %5
%32 = getelementptr inbounds i8, i8* %30, i64 %31
%33 = load i8, i8* %32
%34 = load i8*, i8** %2
%35 = load i64, i64* %4
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8 %33, i8* %36
%37 = load i8, i8* %6
%38 = load i8*, i8** %2
%39 = load i64, i64* %5
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8 %37, i8* %40
br label %41
41: ; preds = %21
%42 = load i64, i64* %4
%43 = add i64 %42, 1
store i64 %43, i64* %4
br label %17
44: ; preds = %17
%45 = load i8*, i8** %2
ret i8* %45
}

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 [32 x i8] zeroinitializer
define i8* @strfry(i8* returned %0) {
%2 = alloca i64
%3 = load i1, i1* @strfry.init
br i1 %3, label %9, 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 (...) @getpid()
%7 = xor i32 %6, %5
%8 = tail call i32 @__initstate_r(i32 %7, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @strfry.state, i64 0, i64 0), i32 32, %struct.random_data* @strfry.rdata)
store i1 true, i1* @strfry.init
br label %9
9: ; preds = %4, %1
%10 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %25, label %12
12: ; preds = %9
%13 = bitcast i64* %2 to i8*
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ 0, %12 ], [ %23, %14 ]
%16 = call i32 @__random_r(%struct.random_data* @strfry.rdata, i64* %2)
%17 = load i64, i64* %2
%18 = urem i64 %17, %10
%19 = getelementptr inbounds i8, i8* %0, i64 %15
%20 = load i8, i8* %19
%21 = getelementptr inbounds i8, i8* %0, i64 %18
%22 = load i8, i8* %21
store i8 %22, i8* %19
store i8 %20, i8* %21
%23 = add nuw i64 %15, 1
%24 = icmp eq i64 %23, %10
br i1 %24, label %25, label %14
25: ; preds = %14, %9
ret i8* %0
}