#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 */
int /*<<< orphan*/ assert(int);
int atoi(char *);
int /*<<< orphan*/ exit(int);
double log_perf(char *, ...);
int *malloc(int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ printf(char *, double);
int main(int argc, char *argv[]) {
  int size, length, i;
  int *data;
  int *target;
  double bt, at;
  if (argc > 1) {
    size = atoi(argv[1]);
    length = size / sizeof(int);
    size = sizeof(int) * length;
  } else
    exit(1);
  log_perf("before init, size=%d", size);
  data = malloc(size);
  for (i = 0; i < length; i++)
    data[i] = i;
  log_perf("after init");
  target = malloc(size);
  bt = log_perf("after target malloc");
  memcpy(target, data, size);
  at = log_perf("after memcpy");
  for (i = 0; i < length; i++)
    assert(target[i] == i);
  printf("TIME: %f\n", (at - bt));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11bb <main+0x4b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shr    $0x2,%rax
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,-0x14(%rbp)
jmp    11c5 <main+0x55>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%esi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1070 <log_perf@plt>
mov    -0x14(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1211 <main+0xa1>
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e9 <main+0x79>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1070 <log_perf@plt>
mov    -0x14(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1070 <log_perf@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1070 <log_perf@plt>
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    129d <main+0x12d>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x1c(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1268 <main+0xf8>
movsd  -0x40(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
lea    0xd93(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     13f5 <main+0x285>
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
mov    %eax,%r12d
sar    $0x2,%r12d
mov    %eax,%r15d
and    $0xfffffffc,%r15d
lea    0xee8(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1070 <log_perf@plt>
mov    %r15d,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
cmp    $0x4,%r14d
jl     134c <main+0x1dc>
cmp    $0x2,%r12d
mov    $0x1,%eax
cmovge %r12d,%eax
cmp    $0x8,%eax
jae    11e0 <main+0x70>
xor    %ecx,%ecx
jmp    1340 <main+0x1d0>
mov    %eax,%ecx
and    $0x7ffffff8,%ecx
lea    -0x8(%rcx),%rdi
mov    %rdi,%rsi
shr    $0x3,%rsi
add    $0x1,%rsi
mov    %esi,%edx
and    $0x3,%edx
cmp    $0x18,%rdi
jae    1211 <main+0xa1>
movdqa 0xdf6(%rip),%xmm0
xor    %edi,%edi
jmp    12e8 <main+0x178>
and    $0xfffffffffffffffc,%rsi
movdqa 0xde3(%rip),%xmm0
xor    %edi,%edi
movdqa 0xde8(%rip),%xmm8
movdqa 0xdef(%rip),%xmm9
movdqa 0xdf6(%rip),%xmm10
movdqa 0xdfe(%rip),%xmm4
movdqa 0xe06(%rip),%xmm5
movdqa 0xe0e(%rip),%xmm6
movdqa 0xe16(%rip),%xmm7
movdqa 0xe1e(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movdqa %xmm0,%xmm2
paddd  %xmm8,%xmm2
movdqu %xmm0,(%rbx,%rdi,4)
movdqu %xmm2,0x10(%rbx,%rdi,4)
movdqa %xmm0,%xmm2
paddd  %xmm9,%xmm2
movdqa %xmm0,%xmm3
paddd  %xmm10,%xmm3
movdqu %xmm2,0x20(%rbx,%rdi,4)
movdqu %xmm3,0x30(%rbx,%rdi,4)
movdqa %xmm0,%xmm2
paddd  %xmm4,%xmm2
movdqa %xmm0,%xmm3
paddd  %xmm5,%xmm3
movdqu %xmm2,0x40(%rbx,%rdi,4)
movdqu %xmm3,0x50(%rbx,%rdi,4)
movdqa %xmm0,%xmm2
paddd  %xmm6,%xmm2
movdqa %xmm0,%xmm3
paddd  %xmm7,%xmm3
movdqu %xmm2,0x60(%rbx,%rdi,4)
movdqu %xmm3,0x70(%rbx,%rdi,4)
add    $0x20,%rdi
paddd  %xmm1,%xmm0
add    $0xfffffffffffffffc,%rsi
jne    1270 <main+0x100>
test   %rdx,%rdx
je     1330 <main+0x1c0>
lea    (%rbx,%rdi,4),%rsi
add    $0x10,%rsi
shl    $0x5,%rdx
xor    %edi,%edi
movdqa 0xd0d(%rip),%xmm1
movdqa 0xd15(%rip),%xmm2
nopl   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm3
paddd  %xmm1,%xmm3
movdqu %xmm0,-0x10(%rsi,%rdi,1)
movdqu %xmm3,(%rsi,%rdi,1)
paddd  %xmm2,%xmm0
add    $0x20,%rdi
cmp    %rdi,%rdx
jne    1310 <main+0x1a0>
cmp    %rax,%rcx
je     134c <main+0x1dc>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ecx,(%rbx,%rcx,4)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1340 <main+0x1d0>
lea    0xd52(%rip),%rdi
xor    %eax,%eax
call   1070 <log_perf@plt>
mov    %r15d,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
lea    0xd44(%rip),%rdi
xor    %eax,%eax
call   1070 <log_perf@plt>
movq   %xmm0,0x10(%rsp)
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1050 <memcpy@plt>
lea    0xd36(%rip),%rdi
xor    %eax,%eax
call   1070 <log_perf@plt>
movq   %xmm0,0x8(%rsp)
cmp    $0x4,%r14d
jl     13cc <main+0x25c>
cmp    $0x2,%r12d
mov    $0x1,%ebx
cmovge %r12d,%ebx
xor    %ebp,%ebp
mov    0x0(%r13,%rbp,4),%eax
xor    %edi,%edi
cmp    %rax,%rbp
sete   %dil
call   1040 <assert@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    13b0 <main+0x240>
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
lea    0xcf2(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"before init, size=%d\00"
@.str.1 = [11 x i8] c"after init\00"
@.str.2 = [20 x i8] c"after target malloc\00"
@.str.3 = [13 x i8] c"after memcpy\00"
@.str.4 = [10 x i8] c"TIME: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca double
%12 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %28
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = udiv i64 %21, 4
%23 = trunc i64 %22 to i32
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = mul i64 4, %25
%27 = trunc i64 %26 to i32
store i32 %27, i32* %6
br label %30
28: ; preds = %2
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %15
%31 = load i32, i32* %6
%32 = call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %6
%34 = call i32* @malloc(i32 %33)
store i32* %34, i32** %9
store i32 0, i32* %8
br label %35
35: ; preds = %45, %30
%36 = load i32, i32* %8
%37 = load i32, i32* %7
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %48
39: ; preds = %35
%40 = load i32, i32* %8
%41 = load i32*, i32** %9
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
store i32 %40, i32* %44
br label %45
45: ; preds = %39
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %35
48: ; preds = %35
%49 = call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%50 = load i32, i32* %6
%51 = call i32* @malloc(i32 %50)
store i32* %51, i32** %10
%52 = call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store double %52, double* %11
%53 = load i32*, i32** %10
%54 = load i32*, i32** %9
%55 = load i32, i32* %6
%56 = call i32 @memcpy(i32* %53, i32* %54, i32 %55)
%57 = call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store double %57, double* %12
store i32 0, i32* %8
br label %58
58: ; preds = %72, %48
%59 = load i32, i32* %8
%60 = load i32, i32* %7
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %75
62: ; preds = %58
%63 = load i32*, i32** %10
%64 = load i32, i32* %8
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %63, i64 %65
%67 = load i32, i32* %66
%68 = load i32, i32* %8
%69 = icmp eq i32 %67, %68
%70 = zext i1 %69 to i32
%71 = call i32 @assert(i32 %70)
br label %72
72: ; preds = %62
%73 = load i32, i32* %8
%74 = add nsw i32 %73, 1
store i32 %74, i32* %8
br label %58
75: ; preds = %58
%76 = load double, double* %12
%77 = load double, double* %11
%78 = fsub double %76, %77
%79 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), double %78)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"before init, size=%d\00"
@.str.1 = [11 x i8] c"after init\00"
@.str.2 = [20 x i8] c"after target malloc\00"
@.str.3 = [13 x i8] c"after memcpy\00"
@.str.4 = [10 x i8] c"TIME: %f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %81
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = ashr i32 %7, 2
%9 = and i32 %7, -4
%10 = tail call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = tail call i32* @malloc(i32 %9)
%12 = icmp sgt i32 %7, 3
br i1 %12, label %13, label %89
13: ; preds = %4
%14 = call i32 @llvm.smax.i32(i32 %8, i32 1)
%15 = zext i32 %14 to i64
%16 = icmp ult i32 %14, 8
br i1 %16, label %79, label %17
17: ; preds = %13
%18 = and i64 %15, 2147483640
%19 = add nsw i64 %18, -8
%20 = lshr exact i64 %19, 3
%21 = add nuw nsw i64 %20, 1
%22 = and i64 %21, 3
%23 = icmp ult i64 %19, 24
br i1 %23, label %60, label %24
24: ; preds = %17
%25 = and i64 %21, 4611686018427387900
br label %26
26: ; preds = %26, %24
%27 = phi i64 [ 0, %24 ], [ %56, %26 ]
%28 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %24 ], [ %57, %26 ]
%29 = phi i64 [ 0, %24 ], [ %58, %26 ]
%30 = add <4 x i32> %28, <i32 4, i32 4, i32 4, i32 4>
%31 = getelementptr inbounds i32, i32* %11, i64 %27
%32 = bitcast i32* %31 to <4 x i32>*
store <4 x i32> %28, <4 x i32>* %32
%33 = getelementptr inbounds i32, i32* %31, i64 4
%34 = bitcast i32* %33 to <4 x i32>*
store <4 x i32> %30, <4 x i32>* %34
%35 = or i64 %27, 8
%36 = add <4 x i32> %28, <i32 8, i32 8, i32 8, i32 8>
%37 = add <4 x i32> %28, <i32 12, i32 12, i32 12, i32 12>
%38 = getelementptr inbounds i32, i32* %11, i64 %35
%39 = bitcast i32* %38 to <4 x i32>*
store <4 x i32> %36, <4 x i32>* %39
%40 = getelementptr inbounds i32, i32* %38, i64 4
%41 = bitcast i32* %40 to <4 x i32>*
store <4 x i32> %37, <4 x i32>* %41
%42 = or i64 %27, 16
%43 = add <4 x i32> %28, <i32 16, i32 16, i32 16, i32 16>
%44 = add <4 x i32> %28, <i32 20, i32 20, i32 20, i32 20>
%45 = getelementptr inbounds i32, i32* %11, i64 %42
%46 = bitcast i32* %45 to <4 x i32>*
store <4 x i32> %43, <4 x i32>* %46
%47 = getelementptr inbounds i32, i32* %45, i64 4
%48 = bitcast i32* %47 to <4 x i32>*
store <4 x i32> %44, <4 x i32>* %48
%49 = or i64 %27, 24
%50 = add <4 x i32> %28, <i32 24, i32 24, i32 24, i32 24>
%51 = add <4 x i32> %28, <i32 28, i32 28, i32 28, i32 28>
%52 = getelementptr inbounds i32, i32* %11, i64 %49
%53 = bitcast i32* %52 to <4 x i32>*
store <4 x i32> %50, <4 x i32>* %53
%54 = getelementptr inbounds i32, i32* %52, i64 4
%55 = bitcast i32* %54 to <4 x i32>*
store <4 x i32> %51, <4 x i32>* %55
%56 = add nuw i64 %27, 32
%57 = add <4 x i32> %28, <i32 32, i32 32, i32 32, i32 32>
%58 = add i64 %29, 4
%59 = icmp eq i64 %58, %25
br i1 %59, label %60, label %26
60: ; preds = %26, %17
%61 = phi i64 [ 0, %17 ], [ %56, %26 ]
%62 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %17 ], [ %57, %26 ]
%63 = icmp eq i64 %22, 0
br i1 %63, label %77, label %64
64: ; preds = %60, %64
%65 = phi i64 [ %73, %64 ], [ %61, %60 ]
%66 = phi <4 x i32> [ %74, %64 ], [ %62, %60 ]
%67 = phi i64 [ %75, %64 ], [ 0, %60 ]
%68 = add <4 x i32> %66, <i32 4, i32 4, i32 4, i32 4>
%69 = getelementptr inbounds i32, i32* %11, i64 %65
%70 = bitcast i32* %69 to <4 x i32>*
store <4 x i32> %66, <4 x i32>* %70
%71 = getelementptr inbounds i32, i32* %69, i64 4
%72 = bitcast i32* %71 to <4 x i32>*
store <4 x i32> %68, <4 x i32>* %72
%73 = add nuw i64 %65, 8
%74 = add <4 x i32> %66, <i32 8, i32 8, i32 8, i32 8>
%75 = add i64 %67, 1
%76 = icmp eq i64 %75, %22
br i1 %76, label %77, label %64
77: ; preds = %64, %60
%78 = icmp eq i64 %18, %15
br i1 %78, label %89, label %79
79: ; preds = %13, %77
%80 = phi i64 [ 0, %13 ], [ %18, %77 ]
br label %83
81: ; preds = %2
%82 = tail call i32 @exit(i32 1)
unreachable
83: ; preds = %79, %83
%84 = phi i64 [ %87, %83 ], [ %80, %79 ]
%85 = getelementptr inbounds i32, i32* %11, i64 %84
%86 = trunc i64 %84 to i32
store i32 %86, i32* %85
%87 = add nuw nsw i64 %84, 1
%88 = icmp eq i64 %87, %15
br i1 %88, label %89, label %83
89: ; preds = %83, %77, %4
%90 = tail call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%91 = tail call i32* @malloc(i32 %9)
%92 = tail call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%93 = tail call i32 @memcpy(i32* %91, i32* %11, i32 %9)
%94 = tail call double (i8*, ...) @log_perf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br i1 %12, label %95, label %108
95: ; preds = %89
%96 = call i32 @llvm.smax.i32(i32 %8, i32 1)
%97 = zext i32 %96 to i64
br label %98
98: ; preds = %95, %98
%99 = phi i64 [ 0, %95 ], [ %106, %98 ]
%100 = getelementptr inbounds i32, i32* %91, i64 %99
%101 = load i32, i32* %100
%102 = zext i32 %101 to i64
%103 = icmp eq i64 %99, %102
%104 = zext i1 %103 to i32
%105 = tail call i32 @assert(i32 %104)
%106 = add nuw nsw i64 %99, 1
%107 = icmp eq i64 %106, %97
br i1 %107, label %108, label %98
108: ; preds = %98, %89
%109 = fsub double %94, %92
%110 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), double %109)
ret i32 0
}