#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 size_t int32_t;

/* Variables and functions */
int random();
void memfry(int *string) {
  int i;
  for (i = 0; i < 1000; ++i) {
    int32_t j;
    int c;
    j = random() % 1000;
    c = string[i];
    string[i] = string[j];
    string[j] = c;
  }
}


x86 assembly (clang, -O0):
<memfry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3e8,-0xc(%rbp)
jge    1186 <memfry+0x76>
mov    $0x0,%al
call   1030 <random@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <memfry+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memfry>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <random@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
cltq
mov    (%r14,%rbx,4),%ecx
mov    (%r14,%rax,4),%edx
mov    %edx,(%r14,%rbx,4)
mov    %ecx,(%r14,%rax,4)
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    1120 <memfry+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @memfry(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %3
br label %6
6: ; preds = %30, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 1000
br i1 %8, label %9, label %33
9: ; preds = %6
%10 = call i32 (...) @random()
%11 = srem i32 %10, 1000
%12 = sext i32 %11 to i64
store i64 %12, i64* %4
%13 = load i32*, i32** %2
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = load i32, i32* %16
store i32 %17, i32* %5
%18 = load i32*, i32** %2
%19 = load i64, i64* %4
%20 = getelementptr inbounds i32, i32* %18, i64 %19
%21 = load i32, i32* %20
%22 = load i32*, i32** %2
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
store i32 %21, i32* %25
%26 = load i32, i32* %5
%27 = load i32*, i32** %2
%28 = load i64, i64* %4
%29 = getelementptr inbounds i32, i32* %27, i64 %28
store i32 %26, i32* %29
br label %30
30: ; preds = %9
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %6
33: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @memfry(i32* nocapture %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i64 [ 0, %1 ], [ %11, %2 ]
%4 = tail call i32 (...) @random()
%5 = srem i32 %4, 1000
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i32, i32* %0, i64 %3
%8 = load i32, i32* %7
%9 = getelementptr inbounds i32, i32* %0, i64 %6
%10 = load i32, i32* %9
store i32 %10, i32* %7
store i32 %8, i32* %9
%11 = add nuw nsw i64 %3, 1
%12 = icmp eq i64 %11, 1000
br i1 %12, label %13, label %2
13: ; preds = %2
ret void
}