#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 main() {
  char *src = malloc(0x100000);
  char *dst = malloc(0x100000);
  if (src == NULL || dst == NULL)
    return -1;
  long long i;
  for (i = 0; i < 0xFF; i++) {
    memcpy(dst, src, 0x100000);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x100000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x100000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1161 <main+0x41>
cmpq   $0x0,-0x18(%rbp)
jne    116d <main+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ad <main+0x8d>
movq   $0x0,-0x20(%rbp)
cmpq   $0xff,-0x20(%rbp)
jge    11a6 <main+0x86>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x100000,%edx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1175 <main+0x55>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x100000,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    $0x100000,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    $0xffffffff,%eax
test   %r14,%r14
je     1178 <main+0x58>
test   %r15,%r15
je     1178 <main+0x58>
mov    $0xff,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x100000,%edx
call   1030 <memcpy@plt>
add    $0xffffffffffffffff,%rbx
jne    1160 <main+0x40>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @main() {
%1 = tail call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%2 = tail call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%3 = icmp eq i8* %1, null
%4 = icmp eq i8* %2, null
%5 = or i1 %3, %4
br i1 %5, label %11, label %6
6: ; preds = %0, %6
%7 = phi i64 [ %9, %6 ], [ 0, %0 ]
%8 = tail call i32 @memcpy(i8* %2, i8* %1, i32 1048576)
%9 = add nuw nsw i64 %7, 1
%10 = icmp eq i64 %9, 255
br i1 %10, label %11, label %6
11: ; preds = %6, %0
%12 = phi i32 [ -1, %0 ], [ 0, %6 ]
ret i32 %12
}