#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 */
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int rand();
void *block_KByte_random() {
  int i, r;
  char *mem = malloc(100000 * 1024);
  char *mem1 = malloc(1024 * 100000);
  for (i = 0; i < 100000; i++) {
    r = (rand() % (100000 * 1024) - 1024);
    memcpy(&mem1[r], &mem[r], 1024);
  }
}


x86 assembly (clang, -O0):
<block_KByte_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x61a8000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x61a8000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x186a0,-0xc(%rbp)
jge    11ae <block_KByte_random+0x7e>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x61a8000,%ecx
cltd
idiv   %ecx
sub    $0x400,%edx
mov    %edx,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
movslq -0x10(%rbp),%rax
add    %rax,%rsi
mov    $0x400,%edx
call   1030 <memcpy@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115b <block_KByte_random+0x2b>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<block_KByte_random>:
push   %rbp
push   %r14
push   %rbx
mov    $0x61a8000,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    $0x61a8000,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    $0x186a0,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x14f8b589,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x37,%rcx
add    %edx,%ecx
imul   $0x61a8000,%ecx,%ecx
sub    %ecx,%eax
cltq
lea    (%rbx,%rax,1),%rdi
add    $0xfffffffffffffc00,%rdi
lea    (%r14,%rax,1),%rsi
add    $0xfffffffffffffc00,%rsi
mov    $0x400,%edx
call   1030 <memcpy@plt>
add    $0xffffffff,%ebp
jne    1160 <block_KByte_random+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @block_KByte_random() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = call i8* @malloc(i32 102400000)
store i8* %6, i8** %4
%7 = call i8* @malloc(i32 102400000)
store i8* %7, i8** %5
store i32 0, i32* %2
br label %8
8: ; preds = %24, %0
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 100000
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 102400000
%14 = sub nsw i32 %13, 1024
store i32 %14, i32* %3
%15 = load i8*, i8** %5
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8*, i8** %4
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = call i32 @memcpy(i8* %18, i8* %22, i32 1024)
br label %24
24: ; preds = %11
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %8
27: ; preds = %8
%28 = load i8*, i8** %1
ret i8* %28
}

LLVM IR (-O2):
define noalias i8* @block_KByte_random() {
%1 = tail call dereferenceable_or_null(102400000) i8* @malloc(i32 102400000)
%2 = tail call dereferenceable_or_null(102400000) i8* @malloc(i32 102400000)
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ 0, %0 ], [ %12, %3 ]
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 102400000
%7 = add nsw i32 %6, -1024
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %2, i64 %8
%10 = getelementptr inbounds i8, i8* %1, i64 %8
%11 = tail call i32 @memcpy(i8* %9, i8* %10, i32 1024)
%12 = add nuw nsw i32 %4, 1
%13 = icmp eq i32 %12, 100000
br i1 %13, label %14, label %3
14: ; preds = %3
ret i8* undef
}