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


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

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

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

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