void constant_rotating_frame_gradient_2d(double t, double *pars, double *qp,
                                         int n_dim, double *dH) {
  double Cx, Cy;
  Cx = -pars[0] * qp[1];
  Cy = pars[0] * qp[0];
  dH[0] = dH[0] + qp[0 + n_dim] - Cx;
  dH[1] = dH[1] + qp[1 + n_dim] - Cy;
  Cx = -pars[0] * qp[1 + n_dim];
  Cy = pars[0] * qp[0 + n_dim];
  dH[2] = dH[3] + Cx;
  dH[3] = dH[4] + Cy;
}


x86 assembly (clang, -O0):
<constant_rotating_frame_gradient_2d>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
subsd  -0x30(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
subsd  -0x38(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movsd  0x18(%rax),%xmm0
addsd  -0x30(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x28(%rbp),%rax
movsd  0x20(%rax),%xmm0
addsd  -0x38(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,0x18(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<constant_rotating_frame_gradient_2d>:
movsd  (%rdi),%xmm0
movsd  (%rsi),%xmm1
mulsd  %xmm0,%xmm1
movslq %edx,%rax
movsd  (%rcx),%xmm2
movsd  0x8(%rcx),%xmm3
addsd  (%rsi,%rax,8),%xmm2
mulsd  0x8(%rsi),%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,(%rcx)
addsd  0x8(%rsi,%rax,8),%xmm3
subsd  %xmm1,%xmm3
movsd  %xmm3,0x8(%rcx)
movupd (%rsi,%rax,8),%xmm0
movsd  (%rdi),%xmm1
unpcklpd %xmm1,%xmm1
shufpd $0x1,%xmm0,%xmm0
mulpd  %xmm1,%xmm0
movupd 0x18(%rcx),%xmm1
movapd %xmm1,%xmm2
subpd  %xmm0,%xmm2
addpd  %xmm1,%xmm0
movsd  %xmm2,%xmm0
movupd %xmm0,0x10(%rcx)
ret

LLVM IR (-O0):
define void @constant_rotating_frame_gradient_2d(double %0, double* %1, double* %2, i32 %3, double* %4) {
%6 = alloca double
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca double*
%11 = alloca double
%12 = alloca double
store double %0, double* %6
store double* %1, double** %7
store double* %2, double** %8
store i32 %3, i32* %9
store double* %4, double** %10
%13 = load double*, double** %7
%14 = getelementptr inbounds double, double* %13, i64 0
%15 = load double, double* %14
%16 = fneg double %15
%17 = load double*, double** %8
%18 = getelementptr inbounds double, double* %17, i64 1
%19 = load double, double* %18
%20 = fmul double %16, %19
store double %20, double* %11
%21 = load double*, double** %7
%22 = getelementptr inbounds double, double* %21, i64 0
%23 = load double, double* %22
%24 = load double*, double** %8
%25 = getelementptr inbounds double, double* %24, i64 0
%26 = load double, double* %25
%27 = fmul double %23, %26
store double %27, double* %12
%28 = load double*, double** %10
%29 = getelementptr inbounds double, double* %28, i64 0
%30 = load double, double* %29
%31 = load double*, double** %8
%32 = load i32, i32* %9
%33 = add nsw i32 0, %32
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %31, i64 %34
%36 = load double, double* %35
%37 = fadd double %30, %36
%38 = load double, double* %11
%39 = fsub double %37, %38
%40 = load double*, double** %10
%41 = getelementptr inbounds double, double* %40, i64 0
store double %39, double* %41
%42 = load double*, double** %10
%43 = getelementptr inbounds double, double* %42, i64 1
%44 = load double, double* %43
%45 = load double*, double** %8
%46 = load i32, i32* %9
%47 = add nsw i32 1, %46
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %45, i64 %48
%50 = load double, double* %49
%51 = fadd double %44, %50
%52 = load double, double* %12
%53 = fsub double %51, %52
%54 = load double*, double** %10
%55 = getelementptr inbounds double, double* %54, i64 1
store double %53, double* %55
%56 = load double*, double** %7
%57 = getelementptr inbounds double, double* %56, i64 0
%58 = load double, double* %57
%59 = fneg double %58
%60 = load double*, double** %8
%61 = load i32, i32* %9
%62 = add nsw i32 1, %61
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %60, i64 %63
%65 = load double, double* %64
%66 = fmul double %59, %65
store double %66, double* %11
%67 = load double*, double** %7
%68 = getelementptr inbounds double, double* %67, i64 0
%69 = load double, double* %68
%70 = load double*, double** %8
%71 = load i32, i32* %9
%72 = add nsw i32 0, %71
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds double, double* %70, i64 %73
%75 = load double, double* %74
%76 = fmul double %69, %75
store double %76, double* %12
%77 = load double*, double** %10
%78 = getelementptr inbounds double, double* %77, i64 3
%79 = load double, double* %78
%80 = load double, double* %11
%81 = fadd double %79, %80
%82 = load double*, double** %10
%83 = getelementptr inbounds double, double* %82, i64 2
store double %81, double* %83
%84 = load double*, double** %10
%85 = getelementptr inbounds double, double* %84, i64 4
%86 = load double, double* %85
%87 = load double, double* %12
%88 = fadd double %86, %87
%89 = load double*, double** %10
%90 = getelementptr inbounds double, double* %89, i64 3
store double %88, double* %90
ret void
}

LLVM IR (-O2):
define void @constant_rotating_frame_gradient_2d(double %0, double* nocapture %1, double* nocapture %2, i32 %3, double* nocapture %4) {
%6 = load double, double* %1
%7 = getelementptr inbounds double, double* %2, i64 1
%8 = load double, double* %7
%9 = load double, double* %2
%10 = fmul double %6, %9
%11 = load double, double* %4
%12 = sext i32 %3 to i64
%13 = getelementptr inbounds double, double* %2, i64 %12
%14 = load double, double* %13
%15 = fadd double %11, %14
%16 = fmul double %6, %8
%17 = fadd double %16, %15
store double %17, double* %4
%18 = getelementptr inbounds double, double* %4, i64 1
%19 = load double, double* %18
%20 = add nsw i32 %3, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %2, i64 %21
%23 = load double, double* %22
%24 = fadd double %19, %23
%25 = fsub double %24, %10
store double %25, double* %18
%26 = load double, double* %1
%27 = bitcast double* %13 to <2 x double>*
%28 = load <2 x double>, <2 x double>* %27
%29 = getelementptr inbounds double, double* %4, i64 3
%30 = insertelement <2 x double> poison, double %26, i64 0
%31 = shufflevector <2 x double> %30, <2 x double> poison, <2 x i32> zeroinitializer
%32 = fmul <2 x double> %31, %28
%33 = shufflevector <2 x double> %32, <2 x double> poison, <2 x i32> <i32 1, i32 0>
%34 = getelementptr inbounds double, double* %4, i64 2
%35 = bitcast double* %29 to <2 x double>*
%36 = load <2 x double>, <2 x double>* %35
%37 = fsub <2 x double> %36, %33
%38 = fadd <2 x double> %36, %33
%39 = shufflevector <2 x double> %37, <2 x double> %38, <2 x i32> <i32 0, i32 3>
%40 = bitcast double* %34 to <2 x double>*
store <2 x double> %39, <2 x double>* %40
ret void
}