#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);
void *block_Kbyte() {
  int i;
  char *mem = (char *)malloc(100000 * 1024);
  char *mem1 = (char *)malloc(1024 * 100000);
  for (i = 0; i < 100000; i++) {
    memcpy(mem1, mem, 1024);
    mem1 = mem1 + 1024;
    mem = mem + 1024;
  }
}


x86 assembly (clang, -O0):
<block_Kbyte>:
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    1194 <block_Kbyte+0x74>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x400,%edx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x400,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x400,%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114b <block_Kbyte+0x2b>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<block_Kbyte>:
push   %r15
push   %r14
push   %rbx
mov    $0x61a8000,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    $0x61a8000,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r15,%rbx,1),%rdi
lea    (%r14,%rbx,1),%rsi
mov    $0x400,%edx
call   1030 <memcpy@plt>
add    $0x400,%rbx
cmp    $0x61a8000,%ebx
jne    1150 <block_Kbyte+0x30>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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