#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 int /*<<< orphan*/ __m128d;

/* Variables and functions */
int /*<<< orphan*/ _mm_add_pd(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_mul_pd(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_set1_pd(double);
void daxpy_sse(double *restrict x, double *restrict y, double a, int n) {
  __m128d *xx = (__m128d *)x;
  __m128d *yy = (__m128d *)y;
  int k = n / 2;
  __m128d aa = _mm_set1_pd(a);
  for (int i = 0; i < k; i++) {
    __m128d z = _mm_mul_pd(aa, xx[i]);
    yy[i] = _mm_add_pd(z, yy[i]);
  }
}


x86 assembly (clang, -O0):
<daxpy_sse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <_mm_set1_pd@plt>
mov    %eax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11ca <daxpy_sse+0x9a>
mov    -0x38(%rbp),%edi
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1050 <_mm_mul_pd@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1040 <_mm_add_pd@plt>
mov    %eax,%edx
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    117a <daxpy_sse+0x4a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<daxpy_sse>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
call   1030 <_mm_set1_pd@plt>
cmp    $0x2,%r14d
jl     1182 <daxpy_sse+0x52>
mov    %eax,%r12d
shr    %r14d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15,%rbp,4),%esi
mov    %r12d,%edi
call   1050 <_mm_mul_pd@plt>
mov    (%rbx,%rbp,4),%esi
mov    %eax,%edi
call   1040 <_mm_add_pd@plt>
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1160 <daxpy_sse+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @daxpy_sse(double* noalias %0, double* noalias %1, double %2, i32 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store double* %0, double** %5
store double* %1, double** %6
store double %2, double* %7
store i32 %3, i32* %8
%15 = load double*, double** %5
%16 = bitcast double* %15 to i32*
store i32* %16, i32** %9
%17 = load double*, double** %6
%18 = bitcast double* %17 to i32*
store i32* %18, i32** %10
%19 = load i32, i32* %8
%20 = sdiv i32 %19, 2
store i32 %20, i32* %11
%21 = load double, double* %7
%22 = call i32 @_mm_set1_pd(double %21)
store i32 %22, i32* %12
store i32 0, i32* %13
br label %23
23: ; preds = %46, %4
%24 = load i32, i32* %13
%25 = load i32, i32* %11
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %49
27: ; preds = %23
%28 = load i32, i32* %12
%29 = load i32*, i32** %9
%30 = load i32, i32* %13
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = call i32 @_mm_mul_pd(i32 %28, i32 %33)
store i32 %34, i32* %14
%35 = load i32, i32* %14
%36 = load i32*, i32** %10
%37 = load i32, i32* %13
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = call i32 @_mm_add_pd(i32 %35, i32 %40)
%42 = load i32*, i32** %10
%43 = load i32, i32* %13
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
store i32 %41, i32* %45
br label %46
46: ; preds = %27
%47 = load i32, i32* %13
%48 = add nsw i32 %47, 1
store i32 %48, i32* %13
br label %23
49: ; preds = %23
ret void
}

LLVM IR (-O2):
define void @daxpy_sse(double* noalias nocapture %0, double* noalias nocapture %1, double %2, i32 %3) {
%5 = bitcast double* %0 to i32*
%6 = bitcast double* %1 to i32*
%7 = tail call i32 @_mm_set1_pd(double %2)
%8 = icmp sgt i32 %3, 1
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = lshr i32 %3, 1
%11 = zext i32 %10 to i64
br label %13
12: ; preds = %13, %4
ret void
13: ; preds = %9, %13
%14 = phi i64 [ 0, %9 ], [ %21, %13 ]
%15 = getelementptr inbounds i32, i32* %5, i64 %14
%16 = load i32, i32* %15
%17 = tail call i32 @_mm_mul_pd(i32 %7, i32 %16)
%18 = getelementptr inbounds i32, i32* %6, i64 %14
%19 = load i32, i32* %18
%20 = tail call i32 @_mm_add_pd(i32 %17, i32 %19)
store i32 %20, i32* %18
%21 = add nuw nsw i64 %14, 1
%22 = icmp eq i64 %21, %11
br i1 %22, label %12, label %13
}