void dist_to_vector_from_squareform(const double *M, double *v, int n) {
  double *it;
  const double *cit;
  int i, j;
  it = v;
  for (i = 0; i < n - 1; i++) {
    cit = M + (i * n) + i + 1;
    for (j = i + 1; j < n; j++, it++, cit++) {
      *it = *cit;
    }
  }
}


x86 assembly (clang, -O0):
<dist_to_vector_from_squareform>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11b5 <dist_to_vector_from_squareform+0xb5>
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
imul   -0x14(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x2c(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a2 <dist_to_vector_from_squareform+0xa2>
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    1160 <dist_to_vector_from_squareform+0x60>
jmp    11a7 <dist_to_vector_from_squareform+0xa7>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    111e <dist_to_vector_from_squareform+0x1e>
pop    %rbp
ret

x86 assembly (clang, -O2):
<dist_to_vector_from_squareform>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x2,%edx
jl     13c4 <dist_to_vector_from_squareform+0x2c4>
lea    -0x1(%rdx),%r14d
mov    %edx,%r9d
lea    -0x2(%rdx),%r15d
lea    0x8(%rdi),%rax
mov    %rax,-0x10(%rsp)
lea    0x8(,%r9,8),%r12
lea    0x10(%rdi),%rax
mov    %rax,-0x8(%rsp)
lea    0x78(%rdi),%rbx
xor    %r10d,%r10d
mov    %rdi,%r11
mov    %r15d,-0x34(%rsp)
mov    %r9,-0x28(%rsp)
mov    %rdx,-0x18(%rsp)
mov    %rdi,-0x20(%rsp)
mov    %r14,-0x30(%rsp)
jmp    1183 <dist_to_vector_from_squareform+0x83>
mov    -0x30(%rsp),%r14
mov    -0x28(%rsp),%r9
nopw   0x0(%rax,%rax,1)
add    %r12,%rbx
add    $0xffffffff,%r15d
add    %r12,%r11
cmp    %r14,%r10
je     13c4 <dist_to_vector_from_squareform+0x2c4>
mov    %r10,%rax
add    $0x1,%r10
cmp    %r9,%r10
jae    1170 <dist_to_vector_from_squareform+0x70>
mov    -0x34(%rsp),%ecx
mov    %ecx,%r13d
sub    %eax,%r13d
mov    %rax,%rcx
imul   %r9,%rcx
lea    (%rdi,%rcx,8),%rcx
lea    (%rcx,%rax,8),%rcx
cmp    $0x3,%r13d
jb     11de <dist_to_vector_from_squareform+0xde>
imul   %r12,%rax
mov    -0x8(%rsp),%rbp
add    %rax,%rbp
lea    0x0(%rbp,%r13,8),%rbp
cmp    %rsi,%rbp
jbe    12a8 <dist_to_vector_from_squareform+0x1a8>
add    -0x10(%rsp),%rax
lea    (%rsi,%r13,8),%rbp
add    $0x8,%rbp
cmp    %rbp,%rax
jae    12a8 <dist_to_vector_from_squareform+0x1a8>
mov    %r10d,%r8d
mov    %edx,%eax
sub    %r8d,%eax
mov    %r8d,%r9d
not    %r9d
add    %edx,%r9d
and    $0x7,%eax
je     121b <dist_to_vector_from_squareform+0x11b>
neg    %eax
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsd  0x8(%rcx),%xmm0
add    $0x8,%rcx
movsd  %xmm0,(%rsi)
add    $0x8,%rsi
add    $0xffffffff,%ebp
cmp    %ebp,%eax
jne    1200 <dist_to_vector_from_squareform+0x100>
sub    %ebp,%r8d
cmp    $0x7,%r9d
mov    -0x28(%rsp),%r9
jb     1170 <dist_to_vector_from_squareform+0x70>
mov    %edx,%eax
sub    %r8d,%eax
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  0x8(%rcx,%rbp,8),%xmm0
movsd  %xmm0,(%rsi)
movsd  0x10(%rcx,%rbp,8),%xmm0
movsd  %xmm0,0x8(%rsi)
movsd  0x18(%rcx,%rbp,8),%xmm0
movsd  %xmm0,0x10(%rsi)
movsd  0x20(%rcx,%rbp,8),%xmm0
movsd  %xmm0,0x18(%rsi)
movsd  0x28(%rcx,%rbp,8),%xmm0
movsd  %xmm0,0x20(%rsi)
movsd  0x30(%rcx,%rbp,8),%xmm0
movsd  %xmm0,0x28(%rsi)
movsd  0x38(%rcx,%rbp,8),%xmm0
movsd  %xmm0,0x30(%rsi)
movsd  0x40(%rcx,%rbp,8),%xmm0
movsd  %xmm0,0x38(%rsi)
add    $0x40,%rsi
add    $0x8,%rbp
cmp    %ebp,%eax
jne    1240 <dist_to_vector_from_squareform+0x140>
jmp    1170 <dist_to_vector_from_squareform+0x70>
mov    %r15d,%r14d
add    $0x1,%r14
and    $0xfffffffffffffffc,%r14
add    $0xfffffffffffffffc,%r14
shr    $0x2,%r14
add    $0x1,%r13
mov    %r13,%r8
movabs $0x1fffffffc,%rax
and    %rax,%r8
lea    -0x4(%r8),%rax
mov    %rax,%r9
shr    $0x2,%r9
add    $0x1,%r9
cmp    $0xc,%rax
jae    12e8 <dist_to_vector_from_squareform+0x1e8>
xor    %eax,%eax
jmp    1358 <dist_to_vector_from_squareform+0x258>
lea    0x1(%r14),%rdi
and    $0xfffffffffffffffc,%rdi
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movups -0x70(%rbx,%rax,8),%xmm0
movups -0x60(%rbx,%rax,8),%xmm1
movups %xmm0,(%rsi,%rax,8)
movups %xmm1,0x10(%rsi,%rax,8)
movups -0x50(%rbx,%rax,8),%xmm0
movups -0x40(%rbx,%rax,8),%xmm1
movups %xmm0,0x20(%rsi,%rax,8)
movups %xmm1,0x30(%rsi,%rax,8)
movups -0x30(%rbx,%rax,8),%xmm0
movups -0x20(%rbx,%rax,8),%xmm1
movups %xmm0,0x40(%rsi,%rax,8)
movups %xmm1,0x50(%rsi,%rax,8)
movups -0x10(%rbx,%rax,8),%xmm0
movups (%rbx,%rax,8),%xmm1
movups %xmm0,0x60(%rsi,%rax,8)
movups %xmm1,0x70(%rsi,%rax,8)
add    $0x10,%rax
add    $0xfffffffffffffffc,%rdi
jne    1300 <dist_to_vector_from_squareform+0x200>
test   $0x3,%r9b
je     139c <dist_to_vector_from_squareform+0x29c>
add    $0x1,%r14b
movzbl %r14b,%edi
and    $0x3,%edi
shl    $0x5,%rdi
lea    (%r11,%rax,8),%rbp
lea    (%rsi,%rax,8),%rax
add    $0x10,%rax
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
movups 0x8(%rbp,%rdx,1),%xmm0
movups 0x18(%rbp,%rdx,1),%xmm1
movups %xmm0,-0x10(%rax,%rdx,1)
movups %xmm1,(%rax,%rdx,1)
add    $0x20,%rdx
cmp    %rdx,%rdi
jne    1380 <dist_to_vector_from_squareform+0x280>
lea    (%rsi,%r8,8),%rsi
cmp    %r8,%r13
mov    -0x18(%rsp),%rdx
mov    -0x20(%rsp),%rdi
je     115d <dist_to_vector_from_squareform+0x5d>
lea    (%rcx,%r8,8),%rcx
add    %r10d,%r8d
mov    -0x30(%rsp),%r14
jmp    11e1 <dist_to_vector_from_squareform+0xe1>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @dist_to_vector_from_squareform(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
%11 = load double*, double** %5
store double* %11, double** %7
store i32 0, i32* %9
br label %12
12: ; preds = %46, %3
%13 = load i32, i32* %9
%14 = load i32, i32* %6
%15 = sub nsw i32 %14, 1
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %49
17: ; preds = %12
%18 = load double*, double** %4
%19 = load i32, i32* %9
%20 = load i32, i32* %6
%21 = mul nsw i32 %19, %20
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %18, i64 %22
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = getelementptr inbounds double, double* %26, i64 1
store double* %27, double** %8
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
store i32 %29, i32* %10
br label %30
30: ; preds = %38, %17
%31 = load i32, i32* %10
%32 = load i32, i32* %6
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %45
34: ; preds = %30
%35 = load double*, double** %8
%36 = load double, double* %35
%37 = load double*, double** %7
store double %36, double* %37
br label %38
38: ; preds = %34
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 1
store i32 %40, i32* %10
%41 = load double*, double** %7
%42 = getelementptr inbounds double, double* %41, i32 1
store double* %42, double** %7
%43 = load double*, double** %8
%44 = getelementptr inbounds double, double* %43, i32 1
store double* %44, double** %8
br label %30
45: ; preds = %30
br label %46
46: ; preds = %45
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
br label %12
49: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @dist_to_vector_from_squareform(double* nocapture %0, double* nocapture writeonly %1, i32 %2) {
%4 = icmp sgt i32 %2, 1
br i1 %4, label %5, label %201
5: ; preds = %3
%6 = add nsw i32 %2, -1
%7 = zext i32 %2 to i64
%8 = zext i32 %6 to i64
%9 = add i32 %2, -2
%10 = getelementptr double, double* %0, i64 1
%11 = bitcast double* %10 to i8*
%12 = shl nuw nsw i64 %7, 3
%13 = add nuw nsw i64 %12, 8
%14 = getelementptr double, double* %0, i64 2
%15 = bitcast double* %14 to i8*
%16 = add i32 %2, -2
br label %20
17: ; preds = %165, %171, %143, %20
%18 = phi double* [ %22, %20 ], [ %64, %143 ], [ %166, %165 ], [ %199, %171 ]
%19 = icmp eq i64 %44, %8
br i1 %19, label %201, label %20
20: ; preds = %5, %17
%21 = phi i64 [ 0, %5 ], [ %44, %17 ]
%22 = phi double* [ %1, %5 ], [ %18, %17 ]
%23 = trunc i64 %21 to i32
%24 = sub i32 %16, %23
%25 = zext i32 %24 to i64
%26 = add nuw nsw i64 %25, 1
%27 = and i64 %26, 8589934588
%28 = add nsw i64 %27, -4
%29 = lshr exact i64 %28, 2
%30 = add nuw nsw i64 %29, 1
%31 = trunc i64 %21 to i32
%32 = sub i32 %16, %31
%33 = zext i32 %32 to i64
%34 = add nuw nsw i64 %33, 1
%35 = bitcast double* %22 to i8*
%36 = trunc i64 %21 to i32
%37 = sub i32 %9, %36
%38 = zext i32 %37 to i64
%39 = mul i64 %13, %21
%40 = getelementptr i8, i8* %11, i64 %39
%41 = getelementptr i8, i8* %15, i64 %39
%42 = shl nuw nsw i64 %38, 3
%43 = getelementptr i8, i8* %41, i64 %42
%44 = add nuw nsw i64 %21, 1
%45 = icmp ult i64 %44, %7
br i1 %45, label %46, label %17
46: ; preds = %20
%47 = mul nsw i64 %21, %7
%48 = getelementptr inbounds double, double* %0, i64 %47
%49 = getelementptr inbounds double, double* %48, i64 %21
%50 = trunc i64 %44 to i32
%51 = icmp ult i32 %32, 3
br i1 %51, label %145, label %52
52: ; preds = %46
%53 = getelementptr double, double* %22, i64 1
%54 = getelementptr double, double* %53, i64 %38
%55 = bitcast double* %54 to i8*
%56 = icmp ugt i8* %43, %35
%57 = icmp ult i8* %40, %55
%58 = and i1 %56, %57
br i1 %58, label %145, label %59
59: ; preds = %52
%60 = and i64 %34, 8589934588
%61 = getelementptr double, double* %49, i64 %60
%62 = trunc i64 %60 to i32
%63 = add i32 %50, %62
%64 = getelementptr double, double* %22, i64 %60
%65 = and i64 %30, 3
%66 = icmp ult i64 %28, 12
br i1 %66, label %122, label %67
67: ; preds = %59
%68 = and i64 %30, 9223372036854775804
%69 = getelementptr double, double* %49, i64 1
%70 = getelementptr double, double* %49, i64 1
%71 = getelementptr double, double* %49, i64 1
%72 = getelementptr double, double* %49, i64 1
br label %73
73: ; preds = %73, %67
%74 = phi i64 [ 0, %67 ], [ %119, %73 ]
%75 = phi i64 [ 0, %67 ], [ %120, %73 ]
%76 = getelementptr double, double* %22, i64 %74
%77 = getelementptr inbounds double, double* %69, i64 %74
%78 = bitcast double* %77 to <2 x double>*
%79 = load <2 x double>, <2 x double>* %78
%80 = getelementptr inbounds double, double* %77, i64 2
%81 = bitcast double* %80 to <2 x double>*
%82 = load <2 x double>, <2 x double>* %81
%83 = bitcast double* %76 to <2 x double>*
store <2 x double> %79, <2 x double>* %83
%84 = getelementptr double, double* %76, i64 2
%85 = bitcast double* %84 to <2 x double>*
store <2 x double> %82, <2 x double>* %85
%86 = or i64 %74, 4
%87 = getelementptr double, double* %22, i64 %86
%88 = getelementptr inbounds double, double* %70, i64 %86
%89 = bitcast double* %88 to <2 x double>*
%90 = load <2 x double>, <2 x double>* %89
%91 = getelementptr inbounds double, double* %88, i64 2
%92 = bitcast double* %91 to <2 x double>*
%93 = load <2 x double>, <2 x double>* %92
%94 = bitcast double* %87 to <2 x double>*
store <2 x double> %90, <2 x double>* %94
%95 = getelementptr double, double* %87, i64 2
%96 = bitcast double* %95 to <2 x double>*
store <2 x double> %93, <2 x double>* %96
%97 = or i64 %74, 8
%98 = getelementptr double, double* %22, i64 %97
%99 = getelementptr inbounds double, double* %71, i64 %97
%100 = bitcast double* %99 to <2 x double>*
%101 = load <2 x double>, <2 x double>* %100
%102 = getelementptr inbounds double, double* %99, i64 2
%103 = bitcast double* %102 to <2 x double>*
%104 = load <2 x double>, <2 x double>* %103
%105 = bitcast double* %98 to <2 x double>*
store <2 x double> %101, <2 x double>* %105
%106 = getelementptr double, double* %98, i64 2
%107 = bitcast double* %106 to <2 x double>*
store <2 x double> %104, <2 x double>* %107
%108 = or i64 %74, 12
%109 = getelementptr double, double* %22, i64 %108
%110 = getelementptr inbounds double, double* %72, i64 %108
%111 = bitcast double* %110 to <2 x double>*
%112 = load <2 x double>, <2 x double>* %111
%113 = getelementptr inbounds double, double* %110, i64 2
%114 = bitcast double* %113 to <2 x double>*
%115 = load <2 x double>, <2 x double>* %114
%116 = bitcast double* %109 to <2 x double>*
store <2 x double> %112, <2 x double>* %116
%117 = getelementptr double, double* %109, i64 2
%118 = bitcast double* %117 to <2 x double>*
store <2 x double> %115, <2 x double>* %118
%119 = add nuw i64 %74, 16
%120 = add nuw i64 %75, 4
%121 = icmp eq i64 %120, %68
br i1 %121, label %122, label %73
122: ; preds = %73, %59
%123 = phi i64 [ 0, %59 ], [ %119, %73 ]
%124 = icmp eq i64 %65, 0
br i1 %124, label %143, label %125
125: ; preds = %122
%126 = getelementptr double, double* %49, i64 1
br label %127
127: ; preds = %127, %125
%128 = phi i64 [ %123, %125 ], [ %140, %127 ]
%129 = phi i64 [ 0, %125 ], [ %141, %127 ]
%130 = getelementptr double, double* %22, i64 %128
%131 = getelementptr inbounds double, double* %126, i64 %128
%132 = bitcast double* %131 to <2 x double>*
%133 = load <2 x double>, <2 x double>* %132
%134 = getelementptr inbounds double, double* %131, i64 2
%135 = bitcast double* %134 to <2 x double>*
%136 = load <2 x double>, <2 x double>* %135
%137 = bitcast double* %130 to <2 x double>*
store <2 x double> %133, <2 x double>* %137
%138 = getelementptr double, double* %130, i64 2
%139 = bitcast double* %138 to <2 x double>*
store <2 x double> %136, <2 x double>* %139
%140 = add nuw i64 %128, 4
%141 = add i64 %129, 1
%142 = icmp eq i64 %141, %65
br i1 %142, label %143, label %127
143: ; preds = %127, %122
%144 = icmp eq i64 %34, %60
br i1 %144, label %17, label %145
145: ; preds = %52, %46, %143
%146 = phi double* [ %49, %52 ], [ %49, %46 ], [ %61, %143 ]
%147 = phi i32 [ %50, %52 ], [ %50, %46 ], [ %63, %143 ]
%148 = phi double* [ %22, %52 ], [ %22, %46 ], [ %64, %143 ]
%149 = sub i32 %2, %147
%150 = xor i32 %147, -1
%151 = add i32 %150, %2
%152 = and i32 %149, 7
%153 = icmp eq i32 %152, 0
br i1 %153, label %165, label %154
154: ; preds = %145, %154
%155 = phi double* [ %159, %154 ], [ %146, %145 ]
%156 = phi i32 [ %161, %154 ], [ %147, %145 ]
%157 = phi double* [ %162, %154 ], [ %148, %145 ]
%158 = phi i32 [ %163, %154 ], [ 0, %145 ]
%159 = getelementptr inbounds double, double* %155, i64 1
%160 = load double, double* %159
store double %160, double* %157
%161 = add nuw nsw i32 %156, 1
%162 = getelementptr inbounds double, double* %157, i64 1
%163 = add i32 %158, 1
%164 = icmp eq i32 %163, %152
br i1 %164, label %165, label %154
165: ; preds = %154, %145
%166 = phi double* [ undef, %145 ], [ %162, %154 ]
%167 = phi double* [ %146, %145 ], [ %159, %154 ]
%168 = phi i32 [ %147, %145 ], [ %161, %154 ]
%169 = phi double* [ %148, %145 ], [ %162, %154 ]
%170 = icmp ult i32 %151, 7
br i1 %170, label %17, label %171
171: ; preds = %165, %171
%172 = phi double* [ %196, %171 ], [ %167, %165 ]
%173 = phi i32 [ %198, %171 ], [ %168, %165 ]
%174 = phi double* [ %199, %171 ], [ %169, %165 ]
%175 = getelementptr inbounds double, double* %172, i64 1
%176 = load double, double* %175
store double %176, double* %174
%177 = getelementptr inbounds double, double* %174, i64 1
%178 = getelementptr inbounds double, double* %172, i64 2
%179 = load double, double* %178
store double %179, double* %177
%180 = getelementptr inbounds double, double* %174, i64 2
%181 = getelementptr inbounds double, double* %172, i64 3
%182 = load double, double* %181
store double %182, double* %180
%183 = getelementptr inbounds double, double* %174, i64 3
%184 = getelementptr inbounds double, double* %172, i64 4
%185 = load double, double* %184
store double %185, double* %183
%186 = getelementptr inbounds double, double* %174, i64 4
%187 = getelementptr inbounds double, double* %172, i64 5
%188 = load double, double* %187
store double %188, double* %186
%189 = getelementptr inbounds double, double* %174, i64 5
%190 = getelementptr inbounds double, double* %172, i64 6
%191 = load double, double* %190
store double %191, double* %189
%192 = getelementptr inbounds double, double* %174, i64 6
%193 = getelementptr inbounds double, double* %172, i64 7
%194 = load double, double* %193
store double %194, double* %192
%195 = getelementptr inbounds double, double* %174, i64 7
%196 = getelementptr inbounds double, double* %172, i64 8
%197 = load double, double* %196
store double %197, double* %195
%198 = add nuw nsw i32 %173, 8
%199 = getelementptr inbounds double, double* %174, i64 8
%200 = icmp eq i32 %198, %2
br i1 %200, label %17, label %171
201: ; preds = %17, %3
ret void
}