#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 */
double *allocateDoubleVector(int);
double *scalarMultiplyVector(double *a, double scalar, int n) {
  int i;
  double *b;
  b = allocateDoubleVector(n);
  for (i = 0; i < n; i++)
    b[i] = scalar * a[i];
  return b;
}


x86 assembly (clang, -O0):
<scalarMultiplyVector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <allocateDoubleVector@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1170 <scalarMultiplyVector+0x60>
movsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1137 <scalarMultiplyVector+0x27>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scalarMultiplyVector>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
movapd %xmm0,(%rsp)
mov    %rdi,%rbx
mov    %esi,%edi
call   1030 <allocateDoubleVector@plt>
movapd (%rsp),%xmm3
test   %ebp,%ebp
jle    1295 <scalarMultiplyVector+0x185>
mov    %ebp,%ecx
cmp    $0x4,%ebp
jb     1155 <scalarMultiplyVector+0x45>
lea    (%rbx,%rcx,8),%rdx
cmp    %rdx,%rax
jae    11ec <scalarMultiplyVector+0xdc>
lea    (%rax,%rcx,8),%rdx
cmp    %rbx,%rdx
jbe    11ec <scalarMultiplyVector+0xdc>
xor    %edx,%edx
mov    %rdx,%rsi
not    %rsi
add    %rcx,%rsi
mov    %rcx,%rdi
and    $0x3,%rdi
je     1188 <scalarMultiplyVector+0x78>
nopl   0x0(%rax)
movsd  (%rbx,%rdx,8),%xmm0
mulsd  %xmm3,%xmm0
movsd  %xmm0,(%rax,%rdx,8)
add    $0x1,%rdx
add    $0xffffffffffffffff,%rdi
jne    1170 <scalarMultiplyVector+0x60>
cmp    $0x3,%rsi
jb     1295 <scalarMultiplyVector+0x185>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  (%rbx,%rdx,8),%xmm0
mulsd  %xmm3,%xmm0
movsd  %xmm0,(%rax,%rdx,8)
movsd  0x8(%rbx,%rdx,8),%xmm0
mulsd  %xmm3,%xmm0
movsd  %xmm0,0x8(%rax,%rdx,8)
movsd  0x10(%rbx,%rdx,8),%xmm0
mulsd  %xmm3,%xmm0
movsd  %xmm0,0x10(%rax,%rdx,8)
movsd  0x18(%rbx,%rdx,8),%xmm0
mulsd  %xmm3,%xmm0
movsd  %xmm0,0x18(%rax,%rdx,8)
add    $0x4,%rdx
cmp    %rdx,%rcx
jne    11a0 <scalarMultiplyVector+0x90>
jmp    1295 <scalarMultiplyVector+0x185>
mov    %ecx,%edx
and    $0xfffffffc,%edx
movapd %xmm3,%xmm0
unpcklpd %xmm3,%xmm0
lea    -0x4(%rdx),%rsi
mov    %rsi,%rbp
shr    $0x2,%rbp
add    $0x1,%rbp
test   %rsi,%rsi
je     129c <scalarMultiplyVector+0x18c>
mov    %rbp,%rdi
and    $0xfffffffffffffffe,%rdi
xor    %esi,%esi
nopw   0x0(%rax,%rax,1)
movupd (%rbx,%rsi,8),%xmm1
movupd 0x10(%rbx,%rsi,8),%xmm2
mulpd  %xmm0,%xmm1
mulpd  %xmm0,%xmm2
movupd %xmm1,(%rax,%rsi,8)
movupd %xmm2,0x10(%rax,%rsi,8)
movupd 0x20(%rbx,%rsi,8),%xmm1
movupd 0x30(%rbx,%rsi,8),%xmm2
mulpd  %xmm0,%xmm1
mulpd  %xmm0,%xmm2
movupd %xmm1,0x20(%rax,%rsi,8)
movupd %xmm2,0x30(%rax,%rsi,8)
add    $0x8,%rsi
add    $0xfffffffffffffffe,%rdi
jne    1220 <scalarMultiplyVector+0x110>
test   $0x1,%bpl
je     128c <scalarMultiplyVector+0x17c>
movupd (%rbx,%rsi,8),%xmm1
movupd 0x10(%rbx,%rsi,8),%xmm2
mulpd  %xmm0,%xmm1
mulpd  %xmm0,%xmm2
movupd %xmm1,(%rax,%rsi,8)
movupd %xmm2,0x10(%rax,%rsi,8)
cmp    %rcx,%rdx
jne    1157 <scalarMultiplyVector+0x47>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
xor    %esi,%esi
test   $0x1,%bpl
jne    126e <scalarMultiplyVector+0x15e>
jmp    128c <scalarMultiplyVector+0x17c>

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

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