#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 */
short *malloc(int);
int /*<<< orphan*/ memcpy2(char *, char *, int);
int main() {
  short *src = malloc(0x100000);
  short *dst = malloc(0x100000);
  if (src == NULL || dst == NULL)
    return -1;
  long long i;
  for (i = 0; i < 0xFF; i++) {
    memcpy2((char *)dst, (char *)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 <memcpy2@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 <memcpy2@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 i16*
%3 = alloca i16*
%4 = alloca i64
store i32 0, i32* %1
%5 = call i16* @malloc(i32 1048576)
store i16* %5, i16** %2
%6 = call i16* @malloc(i32 1048576)
store i16* %6, i16** %3
%7 = load i16*, i16** %2
%8 = icmp eq i16* %7, null
br i1 %8, label %12, label %9
9: ; preds = %0
%10 = load i16*, i16** %3
%11 = icmp eq i16* %10, null
br i1 %11, label %12, label %13
12: ; preds = %9, %0
store i32 -1, i32* %1
br label %27
13: ; preds = %9
store i64 0, i64* %4
br label %14
14: ; preds = %23, %13
%15 = load i64, i64* %4
%16 = icmp slt i64 %15, 255
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = load i16*, i16** %3
%19 = bitcast i16* %18 to i8*
%20 = load i16*, i16** %2
%21 = bitcast i16* %20 to i8*
%22 = call i32 @memcpy2(i8* %19, i8* %21, i32 1048576)
br label %23
23: ; preds = %17
%24 = load i64, i64* %4
%25 = add nsw i64 %24, 1
store i64 %25, i64* %4
br label %14
26: ; preds = %14
store i32 0, i32* %1
br label %27
27: ; preds = %26, %12
%28 = load i32, i32* %1
ret i32 %28
}

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