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


x86 assembly (clang, -O0):
<dist_to_squareform_from_vector>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11b5 <dist_to_squareform_from_vector+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,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a2 <dist_to_squareform_from_vector+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_squareform_from_vector+0x60>
jmp    11a7 <dist_to_squareform_from_vector+0xa7>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    111e <dist_to_squareform_from_vector+0x1e>
pop    %rbp
ret

x86 assembly (clang, -O2):
<dist_to_squareform_from_vector>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x2,%edx
jl     13c8 <dist_to_squareform_from_vector+0x2c8>
lea    -0x1(%rdx),%r9d
mov    %edx,%r14d
lea    0x8(%rdi),%rax
mov    %rax,-0x8(%rsp)
lea    0x8(,%r14,8),%rax
mov    %rax,-0x18(%rsp)
lea    0x10(%rdi),%rax
mov    %rax,-0x10(%rsp)
lea    -0x2(%rdx),%r15d
lea    0x78(%rdi),%r12
xor    %r11d,%r11d
mov    %rdi,%r10
mov    %r15d,-0x34(%rsp)
mov    %rdx,-0x20(%rsp)
mov    %r9,-0x28(%rsp)
mov    %rdi,-0x30(%rsp)
jmp    1188 <dist_to_squareform_from_vector+0x88>
mov    -0x20(%rsp),%rdx
mov    -0x30(%rsp),%rdi
mov    -0x28(%rsp),%r9
nopl   0x0(%rax)
mov    -0x18(%rsp),%rax
add    %rax,%r12
add    $0xffffffff,%r15d
add    %rax,%r10
cmp    %r9,%r11
je     13c8 <dist_to_squareform_from_vector+0x2c8>
mov    %r11,%rbx
add    $0x1,%r11
cmp    %r14,%r11
jae    1170 <dist_to_squareform_from_vector+0x70>
mov    -0x34(%rsp),%eax
mov    %eax,%r13d
sub    %ebx,%r13d
mov    %rbx,%rax
imul   %r14,%rax
lea    (%rdi,%rax,8),%rax
lea    (%rax,%rbx,8),%rcx
cmp    $0x3,%r13d
jb     11e4 <dist_to_squareform_from_vector+0xe4>
imul   -0x18(%rsp),%rbx
mov    -0x8(%rsp),%rax
add    %rbx,%rax
lea    (%rsi,%r13,8),%rbp
add    $0x8,%rbp
cmp    %rbp,%rax
jae    1298 <dist_to_squareform_from_vector+0x198>
add    -0x10(%rsp),%rbx
lea    (%rbx,%r13,8),%rax
cmp    %rsi,%rax
jbe    1298 <dist_to_squareform_from_vector+0x198>
mov    %r11d,%r8d
mov    %edx,%ebx
sub    %r8d,%ebx
mov    %r8d,%ebp
not    %ebp
add    %edx,%ebp
and    $0x7,%ebx
je     121b <dist_to_squareform_from_vector+0x11b>
neg    %ebx
xor    %eax,%eax
nopl   0x0(%rax)
movsd  (%rsi),%xmm0
movsd  %xmm0,0x8(%rcx)
add    $0x8,%rcx
add    $0x8,%rsi
add    $0xffffffff,%eax
cmp    %eax,%ebx
jne    1200 <dist_to_squareform_from_vector+0x100>
sub    %eax,%r8d
cmp    $0x7,%ebp
jb     1170 <dist_to_squareform_from_vector+0x70>
mov    %edx,%ebp
sub    %r8d,%ebp
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
movsd  (%rsi),%xmm0
movsd  %xmm0,0x8(%rcx,%rax,8)
movsd  0x8(%rsi),%xmm0
movsd  %xmm0,0x10(%rcx,%rax,8)
movsd  0x10(%rsi),%xmm0
movsd  %xmm0,0x18(%rcx,%rax,8)
movsd  0x18(%rsi),%xmm0
movsd  %xmm0,0x20(%rcx,%rax,8)
movsd  0x20(%rsi),%xmm0
movsd  %xmm0,0x28(%rcx,%rax,8)
movsd  0x28(%rsi),%xmm0
movsd  %xmm0,0x30(%rcx,%rax,8)
movsd  0x30(%rsi),%xmm0
movsd  %xmm0,0x38(%rcx,%rax,8)
movsd  0x38(%rsi),%xmm0
movsd  %xmm0,0x40(%rcx,%rax,8)
add    $0x40,%rsi
add    $0x8,%rax
cmp    %eax,%ebp
jne    1230 <dist_to_squareform_from_vector+0x130>
jmp    1170 <dist_to_squareform_from_vector+0x70>
mov    %r14,%rbx
mov    %r15d,%r9d
add    $0x1,%r9
and    $0xfffffffffffffffc,%r9
add    $0xfffffffffffffffc,%r9
shr    $0x2,%r9
add    $0x1,%r13
mov    %r13,%r8
movabs $0x1fffffffc,%rax
and    %rax,%r8
lea    -0x4(%r8),%rax
mov    %rax,%r14
shr    $0x2,%r14
add    $0x1,%r14
cmp    $0xc,%rax
jae    12db <dist_to_squareform_from_vector+0x1db>
xor    %ebp,%ebp
jmp    1350 <dist_to_squareform_from_vector+0x250>
lea    0x1(%r9),%rdi
and    $0xfffffffffffffffc,%rdi
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movups (%rsi,%rbp,8),%xmm0
movups 0x10(%rsi,%rbp,8),%xmm1
movups %xmm0,-0x70(%r12,%rbp,8)
movups %xmm1,-0x60(%r12,%rbp,8)
movups 0x20(%rsi,%rbp,8),%xmm0
movups 0x30(%rsi,%rbp,8),%xmm1
movups %xmm0,-0x50(%r12,%rbp,8)
movups %xmm1,-0x40(%r12,%rbp,8)
movups 0x40(%rsi,%rbp,8),%xmm0
movups 0x50(%rsi,%rbp,8),%xmm1
movups %xmm0,-0x30(%r12,%rbp,8)
movups %xmm1,-0x20(%r12,%rbp,8)
movups 0x60(%rsi,%rbp,8),%xmm0
movups 0x70(%rsi,%rbp,8),%xmm1
movups %xmm0,-0x10(%r12,%rbp,8)
movups %xmm1,(%r12,%rbp,8)
add    $0x10,%rbp
add    $0xfffffffffffffffc,%rdi
jne    12f0 <dist_to_squareform_from_vector+0x1f0>
test   $0x3,%r14b
je     139d <dist_to_squareform_from_vector+0x29d>
add    $0x1,%r9b
movzbl %r9b,%eax
and    $0x3,%eax
shl    $0x5,%rax
lea    (%r10,%rbp,8),%rdi
lea    (%rsi,%rbp,8),%rbp
add    $0x10,%rbp
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movups -0x10(%rbp,%rdx,1),%xmm0
movups 0x0(%rbp,%rdx,1),%xmm1
movups %xmm0,0x8(%rdi,%rdx,1)
movups %xmm1,0x18(%rdi,%rdx,1)
add    $0x20,%rdx
cmp    %rdx,%rax
jne    1380 <dist_to_squareform_from_vector+0x280>
lea    (%rsi,%r8,8),%rsi
cmp    %r8,%r13
mov    %rbx,%r14
je     115d <dist_to_squareform_from_vector+0x5d>
lea    (%rcx,%r8,8),%rcx
add    %r11d,%r8d
mov    -0x20(%rsp),%rdx
mov    -0x30(%rsp),%rdi
mov    -0x28(%rsp),%r9
jmp    11e7 <dist_to_squareform_from_vector+0xe7>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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