#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*/ __m128;

/* Variables and functions */
int /*<<< orphan*/ _mm_add_ps(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_mul_ps(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_set1_ps(float);
void saxpy_sse(float *restrict x, float *restrict y, float a, int n) {
  __m128 *xx = (__m128 *)x;
  __m128 *yy = (__m128 *)y;
  int k = n / 4;
  __m128 aa = _mm_set1_ps(a);
  for (int i = 0; i < k; i++) {
    __m128 z = _mm_mul_ps(aa, xx[i]);
    yy[i] = _mm_add_ps(z, yy[i]);
  }
}


x86 assembly (clang, -O0):
<saxpy_sse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movss  %xmm0,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
movss  -0x14(%rbp),%xmm0
call   1040 <_mm_set1_ps@plt>
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11ca <saxpy_sse+0x9a>
mov    -0x30(%rbp),%edi
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1030 <_mm_mul_ps@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1050 <_mm_add_ps@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    117a <saxpy_sse+0x4a>
add    $0x40,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define void @saxpy_sse(float* noalias %0, float* noalias %1, float %2, i32 %3) {
%5 = alloca float*
%6 = alloca float*
%7 = alloca float
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store float* %0, float** %5
store float* %1, float** %6
store float %2, float* %7
store i32 %3, i32* %8
%15 = load float*, float** %5
%16 = bitcast float* %15 to i32*
store i32* %16, i32** %9
%17 = load float*, float** %6
%18 = bitcast float* %17 to i32*
store i32* %18, i32** %10
%19 = load i32, i32* %8
%20 = sdiv i32 %19, 4
store i32 %20, i32* %11
%21 = load float, float* %7
%22 = call i32 @_mm_set1_ps(float %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_ps(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_ps(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 @saxpy_sse(float* noalias nocapture %0, float* noalias nocapture %1, float %2, i32 %3) {
%5 = tail call i32 @_mm_set1_ps(float %2)
%6 = icmp sgt i32 %3, 3
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = lshr i32 %3, 2
%9 = zext i32 %8 to i64
br label %11
10: ; preds = %11, %4
ret void
11: ; preds = %7, %11
%12 = phi i64 [ 0, %7 ], [ %21, %11 ]
%13 = getelementptr inbounds float, float* %0, i64 %12
%14 = bitcast float* %13 to i32*
%15 = load i32, i32* %14
%16 = tail call i32 @_mm_mul_ps(i32 %5, i32 %15)
%17 = getelementptr inbounds float, float* %1, i64 %12
%18 = bitcast float* %17 to i32*
%19 = load i32, i32* %18
%20 = tail call i32 @_mm_add_ps(i32 %16, i32 %19)
store i32 %20, i32* %18
%21 = add nuw nsw i64 %12, 1
%22 = icmp eq i64 %21, %9
br i1 %22, label %10, label %11
}