void ccd_c(double *moving, int len_moving, double *fixed, long *points,
           int len_points, int moving_end, int iterations,
           double rmsd_threshold) {
  double rot_mat[9], rmsd;
  int k, i, prev_i, j;
  for (k = 0; k < iterations; k++) {
    for (i = 0; i < len_points; i++) {
      double TH[3];
      int l = points[i];
      TH[0] = moving[l * 3 + 0] - moving[(l - 1) * 3 + 0];
      TH[1] = moving[l * 3 + 1] - moving[(l - 1) * 3 + 1];
      TH[2] = moving[l * 3 + 2] - moving[(l - 1) * 3 + 2];
      get_closer_rotation_matrix_c(TH, &moving[(l - 1) * 3],
                                   &moving[(moving_end)*3], fixed, rot_mat);
      for (j = l + 1; j < len_moving; j++)
        mat_times_vec(rot_mat, &moving[j * 3], &moving[j * 3], &moving[l * 3]);
    }
    rmsd = calc_rmsd_c(&moving[(moving_end - 3) * 3], fixed, 3);
    if (rmsd < rmsd_threshold)
      return;
  }
}


x86 assembly (clang, -O0):
<ccd_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    1385 <ccd_c+0x255>
movl   $0x0,-0x90(%rbp)
mov    -0x90(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    131e <ccd_c+0x1ee>
mov    -0x20(%rbp),%rax
movslq -0x90(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %eax,-0xb4(%rbp)
mov    -0x8(%rbp),%rax
imul   $0x3,-0xb4(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0xb4(%rbp),%ecx
sub    $0x1,%ecx
imul   $0x3,%ecx,%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
mov    -0x8(%rbp),%rax
imul   $0x3,-0xb4(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0xb4(%rbp),%ecx
sub    $0x1,%ecx
imul   $0x3,%ecx,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
mov    -0x8(%rbp),%rax
imul   $0x3,-0xb4(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0xb4(%rbp),%ecx
sub    $0x1,%ecx
imul   $0x3,%ecx,%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
lea    -0xb0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xb4(%rbp),%eax
sub    $0x1,%eax
imul   $0x3,%eax,%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x8(%rbp),%rdx
imul   $0x3,-0x28(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x18(%rbp),%rcx
lea    -0x80(%rbp),%r8
mov    $0x0,%al
call   1040 <get_closer_rotation_matrix_c@plt>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
mov    -0x98(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1305 <ccd_c+0x1d5>
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%rsi
imul   $0x3,-0x98(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x8(%rbp),%rdx
imul   $0x3,-0x98(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x8(%rbp),%rcx
imul   $0x3,-0xb4(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rcx
mov    $0x0,%al
call   1030 <mat_times_vec@plt>
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    129b <ccd_c+0x16b>
jmp    130a <ccd_c+0x1da>
mov    -0x90(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x90(%rbp)
jmp    117d <ccd_c+0x4d>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%eax
sub    $0x3,%eax
imul   $0x3,%eax,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x3,%edx
mov    $0x0,%al
call   1050 <calc_rmsd_c@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x88(%rbp),%xmm1
ff
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    136c <ccd_c+0x23c>
jmp    1385 <ccd_c+0x255>
jmp    1371 <ccd_c+0x241>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    1164 <ccd_c+0x34>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ccd_c>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
movsd  %xmm0,0x30(%rsp)
mov    %r8d,(%rsp)
mov    %rcx,0x48(%rsp)
mov    %rdx,0x20(%rsp)
mov    %rsi,0x18(%rsp)
mov    %rdi,0x8(%rsp)
cmpl   $0x0,0xf0(%rsp)
jle    12f1 <ccd_c+0x1c1>
lea    (%r9,%r9,2),%eax
lea    (%r9,%r9,2),%ecx
add    $0xfffffff7,%ecx
movslq %ecx,%rcx
mov    0x8(%rsp),%rdx
lea    (%rdx,%rcx,8),%rcx
mov    %rcx,0x28(%rsp)
cltq
lea    (%rdx,%rax,8),%rax
mov    %rax,0x40(%rsp)
mov    (%rsp),%eax
mov    %rax,0x38(%rsp)
mov    0x18(%rsp),%rax
add    $0xffffffff,%eax
mov    %eax,0x14(%rsp)
lea    0x70(%rsp),%r13
movl   $0x0,0x4(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
cmpl   $0x0,(%rsp)
jle    12b0 <ccd_c+0x180>
xor    %ebp,%ebp
jmp    11df <ccd_c+0xaf>
xchg   %ax,%ax
add    $0x1,%rbp
cmp    0x38(%rsp),%rbp
je     12b0 <ccd_c+0x180>
mov    0x48(%rsp),%rax
mov    (%rax,%rbp,8),%r14d
lea    (%r14,%r14,2),%eax
movslq %eax,%rbx
lea    (%r14,%r14,2),%eax
add    $0xfffffffd,%eax
cltq
mov    0x8(%rsp),%rdx
lea    (%rdx,%rax,8),%rsi
movupd (%rdx,%rbx,8),%xmm0
lea    -0x2(%r14,%r14,2),%ecx
movslq %ecx,%rcx
movsd  (%rdx,%rax,8),%xmm1
movhpd (%rdx,%rcx,8),%xmm1
subpd  %xmm1,%xmm0
movapd %xmm0,0x50(%rsp)
movsd  0x10(%rdx,%rbx,8),%xmm0
lea    -0x1(%r14,%r14,2),%eax
cltq
subsd  (%rdx,%rax,8),%xmm0
movsd  %xmm0,0x60(%rsp)
lea    0x50(%rsp),%rdi
mov    0x40(%rsp),%rdx
mov    0x20(%rsp),%rcx
mov    %r13,%r8
xor    %eax,%eax
call   1040 <get_closer_rotation_matrix_c@plt>
lea    0x1(%r14),%eax
cmp    0x18(%rsp),%eax
jge    11d0 <ccd_c+0xa0>
mov    0x8(%rsp),%rcx
lea    (%rcx,%rbx,8),%r15
cltq
lea    (%rax,%rax,2),%rax
lea    (%rcx,%rax,8),%r12
mov    0x14(%rsp),%ebx
sub    %r14d,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1030 <mat_times_vec@plt>
add    $0x18,%r12
add    $0xffffffff,%ebx
jne    1280 <ccd_c+0x150>
jmp    11d0 <ccd_c+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x28(%rsp),%rdi
mov    0x20(%rsp),%rsi
mov    $0x3,%edx
xor    %eax,%eax
call   1050 <calc_rmsd_c@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x30(%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     12f1 <ccd_c+0x1c1>
mov    0x4(%rsp),%eax
add    $0x1,%eax
mov    %eax,0x4(%rsp)
cmp    0xf0(%rsp),%eax
jl     11c0 <ccd_c+0x90>
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @ccd_c(double* %0, i32 %1, double* %2, i64* %3, i32 %4, i32 %5, i32 %6, double %7) {
%9 = alloca double*
%10 = alloca i32
%11 = alloca double*
%12 = alloca i64*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca double
%17 = alloca [9 x double]
%18 = alloca double
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca [3 x double]
%24 = alloca i32
store double* %0, double** %9
store i32 %1, i32* %10
store double* %2, double** %11
store i64* %3, i64** %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store double %7, double* %16
store i32 0, i32* %19
br label %25
25: ; preds = %153, %8
%26 = load i32, i32* %19
%27 = load i32, i32* %15
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %156
29: ; preds = %25
store i32 0, i32* %20
br label %30
30: ; preds = %135, %29
%31 = load i32, i32* %20
%32 = load i32, i32* %13
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %138
34: ; preds = %30
%35 = load i64*, i64** %12
%36 = load i32, i32* %20
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i64, i64* %35, i64 %37
%39 = load i64, i64* %38
%40 = trunc i64 %39 to i32
store i32 %40, i32* %24
%41 = load double*, double** %9
%42 = load i32, i32* %24
%43 = mul nsw i32 %42, 3
%44 = add nsw i32 %43, 0
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %41, i64 %45
%47 = load double, double* %46
%48 = load double*, double** %9
%49 = load i32, i32* %24
%50 = sub nsw i32 %49, 1
%51 = mul nsw i32 %50, 3
%52 = add nsw i32 %51, 0
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %48, i64 %53
%55 = load double, double* %54
%56 = fsub double %47, %55
%57 = getelementptr inbounds [3 x double], [3 x double]* %23, i64 0, i64 0
store double %56, double* %57
%58 = load double*, double** %9
%59 = load i32, i32* %24
%60 = mul nsw i32 %59, 3
%61 = add nsw i32 %60, 1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %58, i64 %62
%64 = load double, double* %63
%65 = load double*, double** %9
%66 = load i32, i32* %24
%67 = sub nsw i32 %66, 1
%68 = mul nsw i32 %67, 3
%69 = add nsw i32 %68, 1
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds double, double* %65, i64 %70
%72 = load double, double* %71
%73 = fsub double %64, %72
%74 = getelementptr inbounds [3 x double], [3 x double]* %23, i64 0, i64 1
store double %73, double* %74
%75 = load double*, double** %9
%76 = load i32, i32* %24
%77 = mul nsw i32 %76, 3
%78 = add nsw i32 %77, 2
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds double, double* %75, i64 %79
%81 = load double, double* %80
%82 = load double*, double** %9
%83 = load i32, i32* %24
%84 = sub nsw i32 %83, 1
%85 = mul nsw i32 %84, 3
%86 = add nsw i32 %85, 2
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds double, double* %82, i64 %87
%89 = load double, double* %88
%90 = fsub double %81, %89
%91 = getelementptr inbounds [3 x double], [3 x double]* %23, i64 0, i64 2
store double %90, double* %91
%92 = getelementptr inbounds [3 x double], [3 x double]* %23, i64 0, i64 0
%93 = load double*, double** %9
%94 = load i32, i32* %24
%95 = sub nsw i32 %94, 1
%96 = mul nsw i32 %95, 3
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds double, double* %93, i64 %97
%99 = load double*, double** %9
%100 = load i32, i32* %14
%101 = mul nsw i32 %100, 3
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds double, double* %99, i64 %102
%104 = load double*, double** %11
%105 = getelementptr inbounds [9 x double], [9 x double]* %17, i64 0, i64 0
%106 = call i32 (double*, double*, double*, double*, double*, ...) bitcast (i32 (...)* @get_closer_rotation_matrix_c to i32 (double*, double*, double*, double*, double*, ...)*)(double* %92, double* %98, double* %103, double* %104, double* %105)
%107 = load i32, i32* %24
%108 = add nsw i32 %107, 1
store i32 %108, i32* %22
br label %109
109: ; preds = %131, %34
%110 = load i32, i32* %22
%111 = load i32, i32* %10
%112 = icmp slt i32 %110, %111
br i1 %112, label %113, label %134
113: ; preds = %109
%114 = getelementptr inbounds [9 x double], [9 x double]* %17, i64 0, i64 0
%115 = load double*, double** %9
%116 = load i32, i32* %22
%117 = mul nsw i32 %116, 3
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds double, double* %115, i64 %118
%120 = load double*, double** %9
%121 = load i32, i32* %22
%122 = mul nsw i32 %121, 3
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds double, double* %120, i64 %123
%125 = load double*, double** %9
%126 = load i32, i32* %24
%127 = mul nsw i32 %126, 3
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds double, double* %125, i64 %128
%130 = call i32 (double*, double*, double*, double*, ...) bitcast (i32 (...)* @mat_times_vec to i32 (double*, double*, double*, double*, ...)*)(double* %114, double* %119, double* %124, double* %129)
br label %131
131: ; preds = %113
%132 = load i32, i32* %22
%133 = add nsw i32 %132, 1
store i32 %133, i32* %22
br label %109
134: ; preds = %109
br label %135
135: ; preds = %134
%136 = load i32, i32* %20
%137 = add nsw i32 %136, 1
store i32 %137, i32* %20
br label %30
138: ; preds = %30
%139 = load double*, double** %9
%140 = load i32, i32* %14
%141 = sub nsw i32 %140, 3
%142 = mul nsw i32 %141, 3
%143 = sext i32 %142 to i64
%144 = getelementptr inbounds double, double* %139, i64 %143
%145 = load double*, double** %11
%146 = call i32 (double*, double*, i32, ...) bitcast (i32 (...)* @calc_rmsd_c to i32 (double*, double*, i32, ...)*)(double* %144, double* %145, i32 3)
%147 = sitofp i32 %146 to double
store double %147, double* %18
%148 = load double, double* %18
%149 = load double, double* %16
%150 = fcmp olt double %148, %149
br i1 %150, label %151, label %152
151: ; preds = %138
br label %156
152: ; preds = %138
br label %153
153: ; preds = %152
%154 = load i32, i32* %19
%155 = add nsw i32 %154, 1
store i32 %155, i32* %19
br label %25
156: ; preds = %151, %25
ret void
}

LLVM IR (-O2):
define void @ccd_c(double* %0, i32 %1, double* %2, i64* nocapture %3, i32 %4, i32 %5, i32 %6, double %7) {
%9 = alloca [9 x double]
%10 = alloca [3 x double]
%11 = bitcast [9 x double]* %9 to i8*
%12 = mul i32 %5, 3
%13 = add i32 %12, -9
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds double, double* %0, i64 %14
%16 = icmp sgt i32 %6, 0
br i1 %16, label %17, label %82
17: ; preds = %8
%18 = icmp sgt i32 %4, 0
%19 = bitcast [3 x double]* %10 to i8*
%20 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%21 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 2
%22 = sext i32 %12 to i64
%23 = getelementptr inbounds double, double* %0, i64 %22
%24 = getelementptr inbounds [9 x double], [9 x double]* %9, i64 0, i64 0
%25 = zext i32 %4 to i64
%26 = bitcast [3 x double]* %10 to <2 x double>*
br label %27
27: ; preds = %75, %17
%28 = phi i32 [ 0, %17 ], [ %79, %75 ]
br i1 %18, label %29, label %75
29: ; preds = %27, %72
%30 = phi i64 [ %73, %72 ], [ 0, %27 ]
%31 = getelementptr inbounds i64, i64* %3, i64 %30
%32 = load i64, i64* %31
%33 = trunc i64 %32 to i32
%34 = mul nsw i32 %33, 3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %0, i64 %35
%37 = add i32 %34, -3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %0, i64 %38
%40 = load double, double* %39
%41 = bitcast double* %36 to <2 x double>*
%42 = load <2 x double>, <2 x double>* %41
%43 = add i32 %34, -2
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %0, i64 %44
%46 = load double, double* %45
%47 = insertelement <2 x double> poison, double %40, i64 0
%48 = insertelement <2 x double> %47, double %46, i64 1
%49 = fsub <2 x double> %42, %48
store <2 x double> %49, <2 x double>* %26
%50 = add nsw i32 %34, 2
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %0, i64 %51
%53 = load double, double* %52
%54 = add i32 %34, -1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %0, i64 %55
%57 = load double, double* %56
%58 = fsub double %53, %57
store double %58, double* %21
%59 = call i32 (double*, double*, double*, double*, double*, ...) bitcast (i32 (...)* @get_closer_rotation_matrix_c to i32 (double*, double*, double*, double*, double*, ...)*)(double* %20, double* %39, double* %23, double* %2, double* %24)
%60 = add i32 %33, 1
%61 = icmp slt i32 %60, %1
br i1 %61, label %62, label %72
62: ; preds = %29
%63 = sext i32 %60 to i64
br label %64
64: ; preds = %62, %64
%65 = phi i64 [ %63, %62 ], [ %69, %64 ]
%66 = mul nsw i64 %65, 3
%67 = getelementptr inbounds double, double* %0, i64 %66
%68 = call i32 (double*, double*, double*, double*, ...) bitcast (i32 (...)* @mat_times_vec to i32 (double*, double*, double*, double*, ...)*)(double* %24, double* %67, double* %67, double* %36)
%69 = add nsw i64 %65, 1
%70 = trunc i64 %69 to i32
%71 = icmp eq i32 %70, %1
br i1 %71, label %72, label %64
72: ; preds = %64, %29
%73 = add nuw nsw i64 %30, 1
%74 = icmp eq i64 %73, %25
br i1 %74, label %75, label %29
75: ; preds = %72, %27
%76 = call i32 (double*, double*, i32, ...) bitcast (i32 (...)* @calc_rmsd_c to i32 (double*, double*, i32, ...)*)(double* %15, double* %2, i32 3)
%77 = sitofp i32 %76 to double
%78 = fcmp uge double %77, %7
%79 = add nuw nsw i32 %28, 1
%80 = icmp slt i32 %79, %6
%81 = select i1 %78, i1 %80, i1 false
br i1 %81, label %27, label %82
82: ; preds = %75, %8
ret void
}