#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 */
void vec_mul(size_t n, double r, double *x) {
  for (size_t i = 0; i < n; i++) {
    x[i] *= r;
  }
}


x86 assembly (clang, -O0):
<vec_mul>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    114f <vec_mul+0x4f>
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1119 <vec_mul+0x19>
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec_mul>:
test   %rdi,%rdi
je     11e7 <vec_mul+0xe7>
cmp    $0x4,%rdi
jae    1116 <vec_mul+0x16>
xor    %eax,%eax
jmp    11d0 <vec_mul+0xd0>
mov    %rdi,%rax
and    $0xfffffffffffffffc,%rax
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x4(%rax),%rcx
mov    %rcx,%r8
shr    $0x2,%r8
add    $0x1,%r8
test   %rcx,%rcx
je     11e8 <vec_mul+0xe8>
mov    %r8,%rdx
and    $0xfffffffffffffffe,%rdx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
movupd (%rsi,%rcx,8),%xmm2
movupd 0x10(%rsi,%rcx,8),%xmm3
movupd 0x20(%rsi,%rcx,8),%xmm4
movupd 0x30(%rsi,%rcx,8),%xmm5
mulpd  %xmm1,%xmm2
mulpd  %xmm1,%xmm3
movupd %xmm2,(%rsi,%rcx,8)
movupd %xmm3,0x10(%rsi,%rcx,8)
mulpd  %xmm1,%xmm4
mulpd  %xmm1,%xmm5
movupd %xmm4,0x20(%rsi,%rcx,8)
movupd %xmm5,0x30(%rsi,%rcx,8)
add    $0x8,%rcx
add    $0xfffffffffffffffe,%rdx
jne    1150 <vec_mul+0x50>
test   $0x1,%r8b
je     11bc <vec_mul+0xbc>
movupd (%rsi,%rcx,8),%xmm2
movupd 0x10(%rsi,%rcx,8),%xmm3
mulpd  %xmm1,%xmm2
mulpd  %xmm1,%xmm3
movupd %xmm2,(%rsi,%rcx,8)
movupd %xmm3,0x10(%rsi,%rcx,8)
cmp    %rdi,%rax
je     11e7 <vec_mul+0xe7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rsi,%rax,8),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rsi,%rax,8)
add    $0x1,%rax
cmp    %rax,%rdi
jne    11d0 <vec_mul+0xd0>
ret
xor    %ecx,%ecx
test   $0x1,%r8b
jne    119e <vec_mul+0x9e>
jmp    11bc <vec_mul+0xbc>

LLVM IR (-O0):
define void @vec_mul(i64 %0, double %1, double* %2) {
%4 = alloca i64
%5 = alloca double
%6 = alloca double*
%7 = alloca i64
store i64 %0, i64* %4
store double %1, double* %5
store double* %2, double** %6
store i64 0, i64* %7
br label %8
8: ; preds = %19, %3
%9 = load i64, i64* %7
%10 = load i64, i64* %4
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = load double, double* %5
%14 = load double*, double** %6
%15 = load i64, i64* %7
%16 = getelementptr inbounds double, double* %14, i64 %15
%17 = load double, double* %16
%18 = fmul double %17, %13
store double %18, double* %16
br label %19
19: ; preds = %12
%20 = load i64, i64* %7
%21 = add i64 %20, 1
store i64 %21, i64* %7
br label %8
22: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @vec_mul(i64 %0, double %1, double* nocapture %2) {
%4 = icmp eq i64 %0, 0
br i1 %4, label %65, label %5
5: ; preds = %3
%6 = icmp ult i64 %0, 4
br i1 %6, label %63, label %7
7: ; preds = %5
%8 = and i64 %0, -4
%9 = insertelement <2 x double> poison, double %1, i64 0
%10 = shufflevector <2 x double> %9, <2 x double> poison, <2 x i32> zeroinitializer
%11 = insertelement <2 x double> poison, double %1, i64 0
%12 = shufflevector <2 x double> %11, <2 x double> poison, <2 x i32> zeroinitializer
%13 = add i64 %8, -4
%14 = lshr exact i64 %13, 2
%15 = add nuw nsw i64 %14, 1
%16 = and i64 %15, 1
%17 = icmp eq i64 %13, 0
br i1 %17, label %47, label %18
18: ; preds = %7
%19 = and i64 %15, 9223372036854775806
br label %20
20: ; preds = %20, %18
%21 = phi i64 [ 0, %18 ], [ %44, %20 ]
%22 = phi i64 [ 0, %18 ], [ %45, %20 ]
%23 = getelementptr inbounds double, double* %2, i64 %21
%24 = bitcast double* %23 to <2 x double>*
%25 = load <2 x double>, <2 x double>* %24
%26 = getelementptr inbounds double, double* %23, i64 2
%27 = bitcast double* %26 to <2 x double>*
%28 = load <2 x double>, <2 x double>* %27
%29 = fmul <2 x double> %25, %10
%30 = fmul <2 x double> %28, %12
%31 = bitcast double* %23 to <2 x double>*
store <2 x double> %29, <2 x double>* %31
%32 = bitcast double* %26 to <2 x double>*
store <2 x double> %30, <2 x double>* %32
%33 = or i64 %21, 4
%34 = getelementptr inbounds double, double* %2, i64 %33
%35 = bitcast double* %34 to <2 x double>*
%36 = load <2 x double>, <2 x double>* %35
%37 = getelementptr inbounds double, double* %34, i64 2
%38 = bitcast double* %37 to <2 x double>*
%39 = load <2 x double>, <2 x double>* %38
%40 = fmul <2 x double> %36, %10
%41 = fmul <2 x double> %39, %12
%42 = bitcast double* %34 to <2 x double>*
store <2 x double> %40, <2 x double>* %42
%43 = bitcast double* %37 to <2 x double>*
store <2 x double> %41, <2 x double>* %43
%44 = add nuw i64 %21, 8
%45 = add i64 %22, 2
%46 = icmp eq i64 %45, %19
br i1 %46, label %47, label %20
47: ; preds = %20, %7
%48 = phi i64 [ 0, %7 ], [ %44, %20 ]
%49 = icmp eq i64 %16, 0
br i1 %49, label %61, label %50
50: ; preds = %47
%51 = getelementptr inbounds double, double* %2, i64 %48
%52 = bitcast double* %51 to <2 x double>*
%53 = load <2 x double>, <2 x double>* %52
%54 = getelementptr inbounds double, double* %51, i64 2
%55 = bitcast double* %54 to <2 x double>*
%56 = load <2 x double>, <2 x double>* %55
%57 = fmul <2 x double> %53, %10
%58 = fmul <2 x double> %56, %12
%59 = bitcast double* %51 to <2 x double>*
store <2 x double> %57, <2 x double>* %59
%60 = bitcast double* %54 to <2 x double>*
store <2 x double> %58, <2 x double>* %60
br label %61
61: ; preds = %47, %50
%62 = icmp eq i64 %8, %0
br i1 %62, label %65, label %63
63: ; preds = %5, %61
%64 = phi i64 [ 0, %5 ], [ %8, %61 ]
br label %66
65: ; preds = %66, %61, %3
ret void
66: ; preds = %63, %66
%67 = phi i64 [ %71, %66 ], [ %64, %63 ]
%68 = getelementptr inbounds double, double* %2, i64 %67
%69 = load double, double* %68
%70 = fmul double %69, %1
store double %70, double* %68
%71 = add nuw i64 %67, 1
%72 = icmp eq i64 %71, %0
br i1 %72, label %65, label %66
}