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


x86 assembly (clang, -O0):
<block_MByte_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x6400000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x6400000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x64,-0xc(%rbp)
jge    11a5 <block_MByte_random+0x75>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
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    $0x100000,%edx
call   1030 <memcpy@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115b <block_MByte_random+0x2b>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

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

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

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