#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 */
typedef double clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
double clock();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ vecadd(double *, double *, int /*<<< orphan*/, int);
int main(int argc, char **argv) {
  clock_t start, end;
  double *arr1 = (double *)malloc((sizeof(double)) * 300000000);
  double *arr2 = (double *)malloc((sizeof(double)) * 300000000);
  long i;
  if (!arr1 || !arr2) {
    printf("cannot allocate\n");
    exit(1);
  }
  for (i = 0; i < 300000000; i++) {
    arr1[i] = (double)i;
    arr2[i] = (double)i;
  }
  start = clock();
  vecadd(arr1, arr2, 0, 300000000);
  end = clock();
  printf("time %fs\n", ((double)end - start) / CLOCKS_PER_SEC);
  free(arr1);
  free(arr2);
  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)
mov    $0x8f0d1800,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x8f0d1800,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11a8 <main+0x48>
cmpq   $0x0,-0x30(%rbp)
jne    11c0 <main+0x60>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movq   $0x0,-0x38(%rbp)
cmpq   $0x11e1a300,-0x38(%rbp)
11
jge    120d <main+0xad>
cvtsi2sdq -0x38(%rbp),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
cvtsi2sdq -0x38(%rbp),%xmm0
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11c8 <main+0x68>
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
xor    %edx,%edx
mov    $0x11e1a300,%ecx
call   1060 <vecadd@plt>
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
mov    0x2d9e(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdbc(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x8f0d1800,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    $0x8f0d1800,%edi
call   1080 <malloc@plt>
test   %r14,%r14
je     13b7 <main+0x247>
mov    %rax,%rbx
test   %rax,%rax
je     13b7 <main+0x247>
mov    $0x8f0d1800,%eax
mov    %rbx,%rcx
add    %rax,%rcx
cmp    %rcx,%r14
jae    123f <main+0xcf>
mov    %r14,%rcx
add    %rax,%rcx
cmp    %rcx,%rbx
jae    123f <main+0xcf>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%r14,%rax,8)
movsd  %xmm0,(%rbx,%rax,8)
lea    0x1(%rax),%rcx
xorps  %xmm0,%xmm0
cvtsi2sd %rcx,%xmm0
movsd  %xmm0,0x8(%r14,%rax,8)
movsd  %xmm0,0x8(%rbx,%rax,8)
lea    0x2(%rax),%rcx
xorps  %xmm0,%xmm0
cvtsi2sd %rcx,%xmm0
movsd  %xmm0,0x10(%r14,%rax,8)
movsd  %xmm0,0x10(%rbx,%rax,8)
lea    0x3(%rax),%rcx
xorps  %xmm0,%xmm0
cvtsi2sd %rcx,%xmm0
movsd  %xmm0,0x18(%r14,%rax,8)
movsd  %xmm0,0x18(%rbx,%rax,8)
add    $0x4,%rax
cmp    $0x11e1a300,%rax
jne    11d0 <main+0x60>
jmp    135a <main+0x1ea>
movdqa 0xdb9(%rip),%xmm0
mov    $0x6,%eax
movdqa 0xdbc(%rip),%xmm1
movdqa 0xdc4(%rip),%xmm2
movdqa 0xdcc(%rip),%xmm3
movdqa 0xdd4(%rip),%xmm4
nopl   0x0(%rax)
movdqa %xmm0,%xmm5
paddq  %xmm1,%xmm5
movq   %xmm0,%rcx
xorps  %xmm6,%xmm6
cvtsi2sd %rcx,%xmm6
pshufd $0xee,%xmm0,%xmm7
movq   %xmm7,%rcx
xorps  %xmm7,%xmm7
cvtsi2sd %rcx,%xmm7
unpcklpd %xmm7,%xmm6
movq   %xmm5,%rcx
xorps  %xmm7,%xmm7
cvtsi2sd %rcx,%xmm7
pshufd $0xee,%xmm5,%xmm5
movq   %xmm5,%rcx
xorps  %xmm5,%xmm5
cvtsi2sd %rcx,%xmm5
unpcklpd %xmm5,%xmm7
movupd %xmm6,-0x30(%r14,%rax,8)
movupd %xmm7,-0x20(%r14,%rax,8)
movupd %xmm6,-0x30(%rbx,%rax,8)
movupd %xmm7,-0x20(%rbx,%rax,8)
movdqa %xmm0,%xmm5
paddq  %xmm2,%xmm5
movdqa %xmm0,%xmm6
paddq  %xmm3,%xmm6
movq   %xmm5,%rcx
xorps  %xmm7,%xmm7
cvtsi2sd %rcx,%xmm7
pshufd $0xee,%xmm5,%xmm5
movq   %xmm5,%rcx
xorps  %xmm5,%xmm5
cvtsi2sd %rcx,%xmm5
unpcklpd %xmm5,%xmm7
movq   %xmm6,%rcx
xorps  %xmm5,%xmm5
cvtsi2sd %rcx,%xmm5
pshufd $0xee,%xmm6,%xmm6
movq   %xmm6,%rcx
xorps  %xmm6,%xmm6
cvtsi2sd %rcx,%xmm6
unpcklpd %xmm6,%xmm5
movupd %xmm7,-0x10(%r14,%rax,8)
movupd %xmm5,(%r14,%rax,8)
movupd %xmm7,-0x10(%rbx,%rax,8)
movupd %xmm5,(%rbx,%rax,8)
paddq  %xmm4,%xmm0
add    $0x8,%rax
cmp    $0x11e1a306,%rax
jne    1270 <main+0x100>
xor    %eax,%eax
call   1050 <clock@plt>
movq   %xmm0,(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    $0x11e1a300,%ecx
call   1070 <vecadd@plt>
xor    %eax,%eax
call   1050 <clock@plt>
subsd  (%rsp),%xmm0
mov    0x2c5d(%rip),%rax
divsd  (%rax),%xmm0
lea    0xcba(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xc9c(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"cannot allocate\0A\00"
@.str.1 = [10 x i8] c"time %fs\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca double*
%9 = alloca double*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i64 @malloc(i32 -1894967296)
%12 = inttoptr i64 %11 to double*
store double* %12, double** %8
%13 = call i64 @malloc(i32 -1894967296)
%14 = inttoptr i64 %13 to double*
store double* %14, double** %9
%15 = load double*, double** %8
%16 = icmp ne double* %15, null
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load double*, double** %9
%19 = icmp ne double* %18, null
br i1 %19, label %23, label %20
20: ; preds = %17, %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %17
store i64 0, i64* %10
br label %24
24: ; preds = %38, %23
%25 = load i64, i64* %10
%26 = icmp slt i64 %25, 300000000
br i1 %26, label %27, label %41
27: ; preds = %24
%28 = load i64, i64* %10
%29 = sitofp i64 %28 to double
%30 = load double*, double** %8
%31 = load i64, i64* %10
%32 = getelementptr inbounds double, double* %30, i64 %31
store double %29, double* %32
%33 = load i64, i64* %10
%34 = sitofp i64 %33 to double
%35 = load double*, double** %9
%36 = load i64, i64* %10
%37 = getelementptr inbounds double, double* %35, i64 %36
store double %34, double* %37
br label %38
38: ; preds = %27
%39 = load i64, i64* %10
%40 = add nsw i64 %39, 1
store i64 %40, i64* %10
br label %24
41: ; preds = %24
%42 = call double (...) @clock()
store double %42, double* %6
%43 = load double*, double** %8
%44 = load double*, double** %9
%45 = call i32 @vecadd(double* %43, double* %44, i32 0, i32 300000000)
%46 = call double (...) @clock()
store double %46, double* %7
%47 = load double, double* %7
%48 = load double, double* %6
%49 = fsub double %47, %48
%50 = load double, double* @CLOCKS_PER_SEC
%51 = fdiv double %49, %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %51)
%53 = load double*, double** %8
%54 = call i32 @free(double* %53)
%55 = load double*, double** %9
%56 = call i32 @free(double* %55)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"time %fs\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@str = [16 x i8] c"cannot allocate\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 -1894967296)
%4 = inttoptr i64 %3 to double*
%5 = tail call i64 @malloc(i32 -1894967296)
%6 = inttoptr i64 %5 to double*
%7 = icmp ne i64 %3, 0
%8 = icmp ne i64 %5, 0
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %50
10: ; preds = %2
%11 = inttoptr i64 %5 to i8*
%12 = inttoptr i64 %3 to i8*
%13 = getelementptr double, double* %4, i64 300000000
%14 = bitcast double* %13 to i8*
%15 = getelementptr double, double* %6, i64 300000000
%16 = bitcast double* %15 to i8*
%17 = icmp ult i8* %12, %16
%18 = icmp ult i8* %11, %14
%19 = and i1 %17, %18
br i1 %19, label %53, label %20
20: ; preds = %10, %20
%21 = phi i64 [ %47, %20 ], [ 0, %10 ]
%22 = phi <2 x i64> [ %48, %20 ], [ <i64 0, i64 1>, %10 ]
%23 = add <2 x i64> %22, <i64 2, i64 2>
%24 = sitofp <2 x i64> %22 to <2 x double>
%25 = sitofp <2 x i64> %23 to <2 x double>
%26 = getelementptr inbounds double, double* %4, i64 %21
%27 = bitcast double* %26 to <2 x double>*
store <2 x double> %24, <2 x double>* %27
%28 = getelementptr inbounds double, double* %26, i64 2
%29 = bitcast double* %28 to <2 x double>*
store <2 x double> %25, <2 x double>* %29
%30 = getelementptr inbounds double, double* %6, i64 %21
%31 = bitcast double* %30 to <2 x double>*
store <2 x double> %24, <2 x double>* %31
%32 = getelementptr inbounds double, double* %30, i64 2
%33 = bitcast double* %32 to <2 x double>*
store <2 x double> %25, <2 x double>* %33
%34 = or i64 %21, 4
%35 = add <2 x i64> %22, <i64 4, i64 4>
%36 = add <2 x i64> %22, <i64 6, i64 6>
%37 = sitofp <2 x i64> %35 to <2 x double>
%38 = sitofp <2 x i64> %36 to <2 x double>
%39 = getelementptr inbounds double, double* %4, i64 %34
%40 = bitcast double* %39 to <2 x double>*
store <2 x double> %37, <2 x double>* %40
%41 = getelementptr inbounds double, double* %39, i64 2
%42 = bitcast double* %41 to <2 x double>*
store <2 x double> %38, <2 x double>* %42
%43 = getelementptr inbounds double, double* %6, i64 %34
%44 = bitcast double* %43 to <2 x double>*
store <2 x double> %37, <2 x double>* %44
%45 = getelementptr inbounds double, double* %43, i64 2
%46 = bitcast double* %45 to <2 x double>*
store <2 x double> %38, <2 x double>* %46
%47 = add nuw nsw i64 %21, 8
%48 = add <2 x i64> %22, <i64 8, i64 8>
%49 = icmp eq i64 %47, 300000000
br i1 %49, label %72, label %20
50: ; preds = %2
%51 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%52 = tail call i32 @exit(i32 1)
unreachable
53: ; preds = %10, %53
%54 = phi i64 [ %70, %53 ], [ 0, %10 ]
%55 = sitofp i64 %54 to double
%56 = getelementptr inbounds double, double* %4, i64 %54
store double %55, double* %56
%57 = getelementptr inbounds double, double* %6, i64 %54
store double %55, double* %57
%58 = or i64 %54, 1
%59 = sitofp i64 %58 to double
%60 = getelementptr inbounds double, double* %4, i64 %58
store double %59, double* %60
%61 = getelementptr inbounds double, double* %6, i64 %58
store double %59, double* %61
%62 = or i64 %54, 2
%63 = sitofp i64 %62 to double
%64 = getelementptr inbounds double, double* %4, i64 %62
store double %63, double* %64
%65 = getelementptr inbounds double, double* %6, i64 %62
store double %63, double* %65
%66 = or i64 %54, 3
%67 = sitofp i64 %66 to double
%68 = getelementptr inbounds double, double* %4, i64 %66
store double %67, double* %68
%69 = getelementptr inbounds double, double* %6, i64 %66
store double %67, double* %69
%70 = add nuw nsw i64 %54, 4
%71 = icmp eq i64 %70, 300000000
br i1 %71, label %72, label %53
72: ; preds = %20, %53
%73 = tail call double (...) @clock()
%74 = tail call i32 @vecadd(double* %4, double* %6, i32 0, i32 300000000)
%75 = tail call double (...) @clock()
%76 = fsub double %75, %73
%77 = load double, double* @CLOCKS_PER_SEC
%78 = fdiv double %76, %77
%79 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %78)
%80 = tail call i32 @free(double* %4)
%81 = tail call i32 @free(double* %6)
ret i32 0
}