void helper_double_2(double *buf) {
  for (int j = 0; j < 4; j += 4) {
    __asm__ volatile("vmovupd (%0), %%ymm0\n"
                     "vpermilpd $0, %%ymm0, %%ymm8\n"
                     "vpermilpd $15, %%ymm0, %%ymm9\n"
                     "vxorpd %%ymm10, %%ymm10, %%ymm10\n"
                     "vsubpd %%ymm9, %%ymm10, %%ymm11\n"
                     "vaddsubpd %%ymm11, %%ymm8, %%ymm0\n"
                     "vperm2f128 $0, %%ymm0, %%ymm0, %%ymm8\n"
                     "vxorpd %%ymm9, %%ymm9, %%ymm9\n"
                     "vsubpd %%ymm0, %%ymm9, %%ymm10\n"
                     "vperm2f128 $49, %%ymm10, %%ymm0, %%ymm11\n"
                     "vaddpd %%ymm11, %%ymm8, %%ymm0\n"
                     "vmovupd %%ymm0, (%0)\n" ::"r"(buf + j)
                     : "%ymm0", "%ymm1", "%ymm2", "%ymm3", "%ymm4", "%ymm5",
                       "%ymm6", "%ymm7", "%ymm8", "%ymm9", "%ymm10", "%ymm11",
                       "%ymm12", "%ymm13", "%ymm14", "%ymm15", "memory");
  }
}


x86 assembly (clang, -O0):
<helper_double_2>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jge    1173 <helper_double_2+0x73>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
vmovupd (%rax),%ymm0
vpermilpd $0x0,%ymm0,%ymm8
vpermilpd $0xf,%ymm0,%ymm9
vxorpd %ymm10,%ymm10,%ymm10
vsubpd %ymm9,%ymm10,%ymm11
vaddsubpd %ymm11,%ymm8,%ymm0
vperm2f128 $0x0,%ymm0,%ymm0,%ymm8
vxorpd %ymm9,%ymm9,%ymm9
vsubpd %ymm0,%ymm9,%ymm10
vperm2f128 $0x31,%ymm10,%ymm0,%ymm11
vaddpd %ymm11,%ymm8,%ymm0
vmovupd %ymm0,(%rax)
mov    -0xc(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0xc(%rbp)
jmp    110f <helper_double_2+0xf>
pop    %rbp
ret

x86 assembly (clang, -O2):
<helper_double_2>:
vmovupd (%rdi),%ymm0
vpermilpd $0x0,%ymm0,%ymm8
vpermilpd $0xf,%ymm0,%ymm9
vxorpd %ymm10,%ymm10,%ymm10
vsubpd %ymm9,%ymm10,%ymm11
vaddsubpd %ymm11,%ymm8,%ymm0
vperm2f128 $0x0,%ymm0,%ymm0,%ymm8
vxorpd %ymm9,%ymm9,%ymm9
vsubpd %ymm0,%ymm9,%ymm10
vperm2f128 $0x31,%ymm10,%ymm0,%ymm11
vaddpd %ymm11,%ymm8,%ymm0
vmovupd %ymm0,(%rdi)
ret

LLVM IR (-O0):
define void @helper_double_2(double* %0) {
%2 = alloca double*
%3 = alloca i32
store double* %0, double** %2
store i32 0, i32* %3
br label %4
4: ; preds = %12, %1
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 4
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = load double*, double** %2
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds double, double* %8, i64 %10
br label %12
12: ; preds = %7
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 4
store i32 %14, i32* %3
br label %4
15: ; preds = %4
ret void
}

LLVM IR (-O2):
define void @helper_double_2(double* %0) {
tail call void asm sideeffect "vmovupd ($0), %ymm0\0Avpermilpd $$0, %ymm0, %ymm8\0Avpermilpd $$15, %ymm0, %ymm9\0Avxorpd %ymm10, %ymm10, %ymm10\0Avsubpd %ymm9, %ymm10, %ymm11\0Avaddsubpd %ymm11, %ymm8, %ymm0\0Avperm2f128 $$0, %ymm0, %ymm0, %ymm8\0Avxorpd %ymm9, %ymm9, %ymm9\0Avsubpd %ymm0, %ymm9, %ymm10\0Avperm2f128 $$49, %ymm10, %ymm0, %ymm11\0Avaddpd %ymm11, %ymm8, %ymm0\0Avmovupd %ymm0, ($0)\0A", "r,~{ymm0},~{ymm1},~{ymm2},~{ymm3},~{ymm4},~{ymm5},~{ymm6},~{ymm7},~{ymm8},~{ymm9},~{ymm10},~{ymm11},~{ymm12},~{ymm13},~{ymm14},~{ymm15},~{memory},~{dirflag},~{fpsr},~{flags}"(double* %0)
ret void
}