void helper_double_2_recursive(double *buf, int depth) {
  if (depth == 2) {
    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");
    }
    return;
  }
}


x86 assembly (clang, -O0):
<helper_double_2_recursive>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jne    1185 <helper_double_2_recursive+0x85>
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    1180 <helper_double_2_recursive+0x80>
mov    -0x8(%rbp),%rax
movslq -0x10(%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    -0x10(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x10(%rbp)
jmp    111c <helper_double_2_recursive+0x1c>
jmp    1185 <helper_double_2_recursive+0x85>
pop    %rbp
ret

x86 assembly (clang, -O2):
<helper_double_2_recursive>:
cmp    $0x2,%esi
jne    1142 <helper_double_2_recursive+0x42>
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_recursive(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 2
br i1 %7, label %8, label %21
8: ; preds = %2
store i32 0, i32* %5
br label %9
9: ; preds = %17, %8
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 4
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load double*, double** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds double, double* %13, i64 %15
br label %17
17: ; preds = %12
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 4
store i32 %19, i32* %5
br label %9
20: ; preds = %9
br label %21
21: ; preds = %20, %2
ret void
}

LLVM IR (-O2):
define void @helper_double_2_recursive(double* %0, i32 %1) {
%3 = icmp eq i32 %1, 2
br i1 %3, label %4, label %5
4: ; preds = %2
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)
br label %5
5: ; preds = %4, %2
ret void
}