void helper_double_2_recursive(double *buf, int depth) {
  if (depth == 2) {
    for (int j = 0; j < 4; j += 4) {
      for (int k = 0; k < 2; k += 2) {
        __asm__ volatile("movupd (%0), %%xmm0\n"
                         "movupd (%1), %%xmm1\n"
                         "movapd %%xmm0, %%xmm8\n"
                         "haddpd %%xmm8, %%xmm8\n"
                         "movapd %%xmm0, %%xmm9\n"
                         "hsubpd %%xmm9, %%xmm9\n"
                         "blendpd $1, %%xmm8, %%xmm9\n"
                         "movapd %%xmm9, %%xmm0\n"
                         "movapd %%xmm1, %%xmm8\n"
                         "haddpd %%xmm8, %%xmm8\n"
                         "movapd %%xmm1, %%xmm9\n"
                         "hsubpd %%xmm9, %%xmm9\n"
                         "blendpd $1, %%xmm8, %%xmm9\n"
                         "movapd %%xmm9, %%xmm1\n"
                         "movapd %%xmm0, %%xmm8\n"
                         "movapd %%xmm0, %%xmm9\n"
                         "addpd %%xmm1, %%xmm8\n"
                         "subpd %%xmm1, %%xmm9\n"
                         "movupd %%xmm8, (%0)\n"
                         "movupd %%xmm9, (%1)\n" ::"r"(buf + j + k + 0),
                         "r"(buf + j + k + 2)
                         : "%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5",
                           "%xmm6", "%xmm7", "%xmm8", "%xmm9", "%xmm10",
                           "%xmm11", "%xmm12", "%xmm13", "%xmm14", "%xmm15",
                           "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    11fb <helper_double_2_recursive+0xfb>
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    11f6 <helper_double_2_recursive+0xf6>
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    11e3 <helper_double_2_recursive+0xe3>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
shl    $0x3,%rdx
add    %rdx,%rcx
movslq -0x14(%rbp),%rdx
shl    $0x3,%rdx
add    %rdx,%rcx
add    $0x10,%rcx
movupd (%rax),%xmm0
movupd (%rcx),%xmm1
movapd %xmm0,%xmm8
haddpd %xmm8,%xmm8
movapd %xmm0,%xmm9
hsubpd %xmm9,%xmm9
blendpd $0x1,%xmm8,%xmm9
movapd %xmm9,%xmm0
movapd %xmm1,%xmm8
haddpd %xmm8,%xmm8
movapd %xmm1,%xmm9
hsubpd %xmm9,%xmm9
blendpd $0x1,%xmm8,%xmm9
movapd %xmm9,%xmm1
movapd %xmm0,%xmm8
movapd %xmm0,%xmm9
addpd  %xmm1,%xmm8
subpd  %xmm1,%xmm9
movupd %xmm8,(%rax)
movupd %xmm9,(%rcx)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    112d <helper_double_2_recursive+0x2d>
jmp    11e8 <helper_double_2_recursive+0xe8>
mov    -0x10(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x10(%rbp)
jmp    111c <helper_double_2_recursive+0x1c>
jmp    11fb <helper_double_2_recursive+0xfb>
pop    %rbp
ret

x86 assembly (clang, -O2):
<helper_double_2_recursive>:
cmp    $0x2,%esi
jne    116f <helper_double_2_recursive+0x6f>
lea    0x10(%rdi),%rax
movupd (%rdi),%xmm0
movupd (%rax),%xmm1
movapd %xmm0,%xmm8
haddpd %xmm8,%xmm8
movapd %xmm0,%xmm9
hsubpd %xmm9,%xmm9
blendpd $0x1,%xmm8,%xmm9
movapd %xmm9,%xmm0
movapd %xmm1,%xmm8
haddpd %xmm8,%xmm8
movapd %xmm1,%xmm9
hsubpd %xmm9,%xmm9
blendpd $0x1,%xmm8,%xmm9
movapd %xmm9,%xmm1
movapd %xmm0,%xmm8
movapd %xmm0,%xmm9
addpd  %xmm1,%xmm8
subpd  %xmm1,%xmm9
movupd %xmm8,(%rdi)
movupd %xmm9,(%rax)
ret

LLVM IR (-O0):
define void @helper_double_2_recursive(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 2
br i1 %8, label %9, label %42
9: ; preds = %2
store i32 0, i32* %5
br label %10
10: ; preds = %38, %9
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %41
13: ; preds = %10
store i32 0, i32* %6
br label %14
14: ; preds = %34, %13
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %37
17: ; preds = %14
%18 = load double*, double** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
%25 = getelementptr inbounds double, double* %24, i64 0
%26 = load double*, double** %3
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = getelementptr inbounds double, double* %32, i64 2
br label %34
34: ; preds = %17
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 2
store i32 %36, i32* %6
br label %14
37: ; preds = %14
br label %38
38: ; preds = %37
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 4
store i32 %40, i32* %5
br label %10
41: ; preds = %10
br label %42
42: ; preds = %41, %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 %6
4: ; preds = %2
%5 = getelementptr inbounds double, double* %0, i64 2
tail call void asm sideeffect "movupd ($0), %xmm0\0Amovupd ($1), %xmm1\0Amovapd %xmm0, %xmm8\0Ahaddpd %xmm8, %xmm8\0Amovapd %xmm0, %xmm9\0Ahsubpd %xmm9, %xmm9\0Ablendpd $$1, %xmm8, %xmm9\0Amovapd %xmm9, %xmm0\0Amovapd %xmm1, %xmm8\0Ahaddpd %xmm8, %xmm8\0Amovapd %xmm1, %xmm9\0Ahsubpd %xmm9, %xmm9\0Ablendpd $$1, %xmm8, %xmm9\0Amovapd %xmm9, %xmm1\0Amovapd %xmm0, %xmm8\0Amovapd %xmm0, %xmm9\0Aaddpd %xmm1, %xmm8\0Asubpd %xmm1, %xmm9\0Amovupd %xmm8, ($0)\0Amovupd %xmm9, ($1)\0A", "r,r,~{xmm0},~{xmm1},~{xmm2},~{xmm3},~{xmm4},~{xmm5},~{xmm6},~{xmm7},~{xmm8},~{xmm9},~{xmm10},~{xmm11},~{xmm12},~{xmm13},~{xmm14},~{xmm15},~{memory},~{dirflag},~{fpsr},~{flags}"(double* %0, double* %5)
br label %6
6: ; preds = %4, %2
ret void
}