void idx_swap(double _Complex *f, unsigned long k, unsigned long r) {
  double _Complex tmp = f[k];
  f[k] = f[r];
  f[r] = tmp;
}


x86 assembly (clang, -O0):
<idx_swap>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movsd  (%rax),%xmm1
movsd  0x8(%rax),%xmm0
movsd  %xmm1,-0x28(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movsd  (%rax),%xmm1
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movsd  %xmm1,(%rax)
movsd  %xmm0,0x8(%rax)
movsd  -0x28(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movsd  %xmm1,(%rax)
movsd  %xmm0,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<idx_swap>:
shl    $0x4,%rsi
movups (%rdi,%rsi,1),%xmm0
shl    $0x4,%rdx
movups (%rdi,%rdx,1),%xmm1
movups %xmm1,(%rdi,%rsi,1)
movups %xmm0,(%rdi,%rdx,1)
ret

LLVM IR (-O0):
define void @idx_swap({ double, double }* %0, i64 %1, i64 %2) {
%4 = alloca { double, double }*
%5 = alloca i64
%6 = alloca i64
%7 = alloca { double, double }
store { double, double }* %0, { double, double }** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%8 = load { double, double }*, { double, double }** %4
%9 = load i64, i64* %5
%10 = getelementptr inbounds { double, double }, { double, double }* %8, i64 %9
%11 = getelementptr inbounds { double, double }, { double, double }* %10, i32 0, i32 0
%12 = load double, double* %11
%13 = getelementptr inbounds { double, double }, { double, double }* %10, i32 0, i32 1
%14 = load double, double* %13
%15 = getelementptr inbounds { double, double }, { double, double }* %7, i32 0, i32 0
%16 = getelementptr inbounds { double, double }, { double, double }* %7, i32 0, i32 1
store double %12, double* %15
store double %14, double* %16
%17 = load { double, double }*, { double, double }** %4
%18 = load i64, i64* %6
%19 = getelementptr inbounds { double, double }, { double, double }* %17, i64 %18
%20 = getelementptr inbounds { double, double }, { double, double }* %19, i32 0, i32 0
%21 = load double, double* %20
%22 = getelementptr inbounds { double, double }, { double, double }* %19, i32 0, i32 1
%23 = load double, double* %22
%24 = load { double, double }*, { double, double }** %4
%25 = load i64, i64* %5
%26 = getelementptr inbounds { double, double }, { double, double }* %24, i64 %25
%27 = getelementptr inbounds { double, double }, { double, double }* %26, i32 0, i32 0
%28 = getelementptr inbounds { double, double }, { double, double }* %26, i32 0, i32 1
store double %21, double* %27
store double %23, double* %28
%29 = getelementptr inbounds { double, double }, { double, double }* %7, i32 0, i32 0
%30 = load double, double* %29
%31 = getelementptr inbounds { double, double }, { double, double }* %7, i32 0, i32 1
%32 = load double, double* %31
%33 = load { double, double }*, { double, double }** %4
%34 = load i64, i64* %6
%35 = getelementptr inbounds { double, double }, { double, double }* %33, i64 %34
%36 = getelementptr inbounds { double, double }, { double, double }* %35, i32 0, i32 0
%37 = getelementptr inbounds { double, double }, { double, double }* %35, i32 0, i32 1
store double %30, double* %36
store double %32, double* %37
ret void
}

LLVM IR (-O2):
define void @idx_swap({ double, double }* nocapture %0, i64 %1, i64 %2) {
%4 = getelementptr inbounds { double, double }, { double, double }* %0, i64 %1, i32 0
%5 = bitcast double* %4 to <2 x double>*
%6 = load <2 x double>, <2 x double>* %5
%7 = getelementptr inbounds { double, double }, { double, double }* %0, i64 %2, i32 0
%8 = bitcast double* %7 to <2 x double>*
%9 = load <2 x double>, <2 x double>* %8
%10 = bitcast double* %4 to <2 x double>*
store <2 x double> %9, <2 x double>* %10
%11 = bitcast double* %7 to <2 x double>*
store <2 x double> %6, <2 x double>* %11
ret void
}