#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);
double *vector_copy(double *v, int n) {
  double *copy;
  int i;
  copy = (double *)malloc(n * sizeof(double));
  for (i = 0; i < n; i++) {
    copy[i] = v[i];
  }
  return copy;
}


x86 assembly (clang, -O0):
<vector_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    116d <vector_copy+0x5d>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1139 <vector_copy+0x29>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vector_copy>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0x0(,%r14,8),%edi
call   1030 <malloc@plt>
test   %r14d,%r14d
jle    1294 <vector_copy+0x184>
mov    %r14d,%r9d
cmp    $0x4,%r14d
jb     114b <vector_copy+0x3b>
lea    (%rbx,%r9,8),%rcx
cmp    %rcx,%rax
jae    11bc <vector_copy+0xac>
lea    (%rax,%r9,8),%rcx
cmp    %rbx,%rcx
jbe    11bc <vector_copy+0xac>
xor    %edx,%edx
mov    %rdx,%rsi
not    %rsi
add    %r9,%rsi
mov    %r9,%rdi
and    $0x3,%rdi
je     1174 <vector_copy+0x64>
nop
movsd  (%rbx,%rdx,8),%xmm0
movsd  %xmm0,(%rax,%rdx,8)
add    $0x1,%rdx
add    $0xffffffffffffffff,%rdi
jne    1160 <vector_copy+0x50>
cmp    $0x3,%rsi
jb     1294 <vector_copy+0x184>
xchg   %ax,%ax
movsd  (%rbx,%rdx,8),%xmm0
movsd  %xmm0,(%rax,%rdx,8)
movsd  0x8(%rbx,%rdx,8),%xmm0
movsd  %xmm0,0x8(%rax,%rdx,8)
movsd  0x10(%rbx,%rdx,8),%xmm0
movsd  %xmm0,0x10(%rax,%rdx,8)
movsd  0x18(%rbx,%rdx,8),%xmm0
movsd  %xmm0,0x18(%rax,%rdx,8)
add    $0x4,%rdx
cmp    %rdx,%r9
jne    1180 <vector_copy+0x70>
jmp    1294 <vector_copy+0x184>
mov    %r9d,%edx
and    $0xfffffffc,%edx
lea    -0x4(%rdx),%rcx
mov    %rcx,%rdi
shr    $0x2,%rdi
add    $0x1,%rdi
mov    %edi,%r8d
and    $0x3,%r8d
cmp    $0xc,%rcx
jae    11e2 <vector_copy+0xd2>
xor    %esi,%esi
jmp    1248 <vector_copy+0x138>
and    $0xfffffffffffffffc,%rdi
xor    %esi,%esi
nopl   0x0(%rax,%rax,1)
movups (%rbx,%rsi,8),%xmm0
movups 0x10(%rbx,%rsi,8),%xmm1
movups %xmm0,(%rax,%rsi,8)
movups %xmm1,0x10(%rax,%rsi,8)
movups 0x20(%rbx,%rsi,8),%xmm0
movups 0x30(%rbx,%rsi,8),%xmm1
movups %xmm0,0x20(%rax,%rsi,8)
movups %xmm1,0x30(%rax,%rsi,8)
movups 0x40(%rbx,%rsi,8),%xmm0
movups 0x50(%rbx,%rsi,8),%xmm1
movups %xmm0,0x40(%rax,%rsi,8)
movups %xmm1,0x50(%rax,%rsi,8)
movups 0x60(%rbx,%rsi,8),%xmm0
movups 0x70(%rbx,%rsi,8),%xmm1
movups %xmm0,0x60(%rax,%rsi,8)
movups %xmm1,0x70(%rax,%rsi,8)
add    $0x10,%rsi
add    $0xfffffffffffffffc,%rdi
jne    11f0 <vector_copy+0xe0>
test   %r8,%r8
je     128b <vector_copy+0x17b>
lea    (%rax,%rsi,8),%rdi
add    $0x10,%rdi
lea    (%rbx,%rsi,8),%rsi
add    $0x10,%rsi
shl    $0x5,%r8
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movups -0x10(%rsi,%rcx,1),%xmm0
movups (%rsi,%rcx,1),%xmm1
movups %xmm0,-0x10(%rdi,%rcx,1)
movups %xmm1,(%rdi,%rcx,1)
add    $0x20,%rcx
cmp    %rcx,%r8
jne    1270 <vector_copy+0x160>
cmp    %r9,%rdx
jne    114d <vector_copy+0x3d>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define double* @vector_copy(double* nocapture %0, i32 %1) {
%3 = shl i32 %1, 3
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to double*
%6 = inttoptr i64 %4 to i8*
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %134
8: ; preds = %2
%9 = zext i32 %1 to i64
%10 = icmp ult i32 %1, 4
br i1 %10, label %97, label %11
11: ; preds = %8
%12 = getelementptr double, double* %5, i64 %9
%13 = getelementptr double, double* %0, i64 %9
%14 = bitcast double* %13 to i8*
%15 = icmp ult i8* %6, %14
%16 = icmp ugt double* %12, %0
%17 = and i1 %15, %16
br i1 %17, label %97, label %18
18: ; preds = %11
%19 = and i64 %9, 4294967292
%20 = add nsw i64 %19, -4
%21 = lshr exact i64 %20, 2
%22 = add nuw nsw i64 %21, 1
%23 = and i64 %22, 3
%24 = icmp ult i64 %20, 12
br i1 %24, label %76, label %25
25: ; preds = %18
%26 = and i64 %22, 9223372036854775804
br label %27
27: ; preds = %27, %25
%28 = phi i64 [ 0, %25 ], [ %73, %27 ]
%29 = phi i64 [ 0, %25 ], [ %74, %27 ]
%30 = getelementptr inbounds double, double* %0, i64 %28
%31 = bitcast double* %30 to <2 x double>*
%32 = load <2 x double>, <2 x double>* %31
%33 = getelementptr inbounds double, double* %30, i64 2
%34 = bitcast double* %33 to <2 x double>*
%35 = load <2 x double>, <2 x double>* %34
%36 = getelementptr inbounds double, double* %5, i64 %28
%37 = bitcast double* %36 to <2 x double>*
store <2 x double> %32, <2 x double>* %37
%38 = getelementptr inbounds double, double* %36, i64 2
%39 = bitcast double* %38 to <2 x double>*
store <2 x double> %35, <2 x double>* %39
%40 = or i64 %28, 4
%41 = getelementptr inbounds double, double* %0, i64 %40
%42 = bitcast double* %41 to <2 x double>*
%43 = load <2 x double>, <2 x double>* %42
%44 = getelementptr inbounds double, double* %41, i64 2
%45 = bitcast double* %44 to <2 x double>*
%46 = load <2 x double>, <2 x double>* %45
%47 = getelementptr inbounds double, double* %5, i64 %40
%48 = bitcast double* %47 to <2 x double>*
store <2 x double> %43, <2 x double>* %48
%49 = getelementptr inbounds double, double* %47, i64 2
%50 = bitcast double* %49 to <2 x double>*
store <2 x double> %46, <2 x double>* %50
%51 = or i64 %28, 8
%52 = getelementptr inbounds double, double* %0, i64 %51
%53 = bitcast double* %52 to <2 x double>*
%54 = load <2 x double>, <2 x double>* %53
%55 = getelementptr inbounds double, double* %52, i64 2
%56 = bitcast double* %55 to <2 x double>*
%57 = load <2 x double>, <2 x double>* %56
%58 = getelementptr inbounds double, double* %5, i64 %51
%59 = bitcast double* %58 to <2 x double>*
store <2 x double> %54, <2 x double>* %59
%60 = getelementptr inbounds double, double* %58, i64 2
%61 = bitcast double* %60 to <2 x double>*
store <2 x double> %57, <2 x double>* %61
%62 = or i64 %28, 12
%63 = getelementptr inbounds double, double* %0, i64 %62
%64 = bitcast double* %63 to <2 x double>*
%65 = load <2 x double>, <2 x double>* %64
%66 = getelementptr inbounds double, double* %63, i64 2
%67 = bitcast double* %66 to <2 x double>*
%68 = load <2 x double>, <2 x double>* %67
%69 = getelementptr inbounds double, double* %5, i64 %62
%70 = bitcast double* %69 to <2 x double>*
store <2 x double> %65, <2 x double>* %70
%71 = getelementptr inbounds double, double* %69, i64 2
%72 = bitcast double* %71 to <2 x double>*
store <2 x double> %68, <2 x double>* %72
%73 = add nuw i64 %28, 16
%74 = add nuw i64 %29, 4
%75 = icmp eq i64 %74, %26
br i1 %75, label %76, label %27
76: ; preds = %27, %18
%77 = phi i64 [ 0, %18 ], [ %73, %27 ]
%78 = icmp eq i64 %23, 0
br i1 %78, label %95, label %79
79: ; preds = %76, %79
%80 = phi i64 [ %92, %79 ], [ %77, %76 ]
%81 = phi i64 [ %93, %79 ], [ 0, %76 ]
%82 = getelementptr inbounds double, double* %0, i64 %80
%83 = bitcast double* %82 to <2 x double>*
%84 = load <2 x double>, <2 x double>* %83
%85 = getelementptr inbounds double, double* %82, i64 2
%86 = bitcast double* %85 to <2 x double>*
%87 = load <2 x double>, <2 x double>* %86
%88 = getelementptr inbounds double, double* %5, i64 %80
%89 = bitcast double* %88 to <2 x double>*
store <2 x double> %84, <2 x double>* %89
%90 = getelementptr inbounds double, double* %88, i64 2
%91 = bitcast double* %90 to <2 x double>*
store <2 x double> %87, <2 x double>* %91
%92 = add nuw i64 %80, 4
%93 = add i64 %81, 1
%94 = icmp eq i64 %93, %23
br i1 %94, label %95, label %79
95: ; preds = %79, %76
%96 = icmp eq i64 %19, %9
br i1 %96, label %134, label %97
97: ; preds = %11, %8, %95
%98 = phi i64 [ 0, %11 ], [ 0, %8 ], [ %19, %95 ]
%99 = xor i64 %98, -1
%100 = add nsw i64 %99, %9
%101 = and i64 %9, 3
%102 = icmp eq i64 %101, 0
br i1 %102, label %112, label %103
103: ; preds = %97, %103
%104 = phi i64 [ %109, %103 ], [ %98, %97 ]
%105 = phi i64 [ %110, %103 ], [ 0, %97 ]
%106 = getelementptr inbounds double, double* %0, i64 %104
%107 = load double, double* %106
%108 = getelementptr inbounds double, double* %5, i64 %104
store double %107, double* %108
%109 = add nuw nsw i64 %104, 1
%110 = add i64 %105, 1
%111 = icmp eq i64 %110, %101
br i1 %111, label %112, label %103
112: ; preds = %103, %97
%113 = phi i64 [ %98, %97 ], [ %109, %103 ]
%114 = icmp ult i64 %100, 3
br i1 %114, label %134, label %115
115: ; preds = %112, %115
%116 = phi i64 [ %132, %115 ], [ %113, %112 ]
%117 = getelementptr inbounds double, double* %0, i64 %116
%118 = load double, double* %117
%119 = getelementptr inbounds double, double* %5, i64 %116
store double %118, double* %119
%120 = add nuw nsw i64 %116, 1
%121 = getelementptr inbounds double, double* %0, i64 %120
%122 = load double, double* %121
%123 = getelementptr inbounds double, double* %5, i64 %120
store double %122, double* %123
%124 = add nuw nsw i64 %116, 2
%125 = getelementptr inbounds double, double* %0, i64 %124
%126 = load double, double* %125
%127 = getelementptr inbounds double, double* %5, i64 %124
store double %126, double* %127
%128 = add nuw nsw i64 %116, 3
%129 = getelementptr inbounds double, double* %0, i64 %128
%130 = load double, double* %129
%131 = getelementptr inbounds double, double* %5, i64 %128
store double %130, double* %131
%132 = add nuw nsw i64 %116, 4
%133 = icmp eq i64 %132, %9
br i1 %133, label %134, label %115
134: ; preds = %112, %115, %95, %2
ret double* %5
}