int norm(int n,
         int relax(int n, char resolution, int max_step, double step_size,
                   double **A, double *b, double *x_next, double *delta_l2,
                   double *time),
         double **A, double *b, double *x_next) {
  int row;
  double delta_l2, **AT, *ATb, **ATA;
  AT = (double **)malloc(n * sizeof(double *));
  ATb = (double *)malloc(n * sizeof(double));
  ATA = (double **)malloc(n * sizeof(double *));
  for (row = 0; row < n; row++) {
    AT[row] = (double *)malloc(n * sizeof(double));
    ATA[row] = (double *)malloc(n * sizeof(double));
  }
  transpose(n, A, AT);
  mat_mat_mult(n, AT, A, ATA);
  mat_vec_mult(n, AT, b, ATb);
  double time;
  int step = relax(n, 16, 1 << 16, 0.125, ATA, ATb, x_next, &delta_l2, &time);
  printf("norm took %.5f seconds\n", time);
  for (row = 0; row < n; row++) {
    free(AT[row]);
    free(ATA[row]);
  }
  free(AT);
  free(ATA);
  free(ATb);
  return step;
}


x86 assembly (clang, -O0):
<norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movslq -0x4(%rbp),%rdi
shl    $0x3,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
movslq -0x4(%rbp),%rdi
shl    $0x3,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x48(%rbp)
movslq -0x4(%rbp),%rdi
shl    $0x3,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1207 <norm+0xa7>
movslq -0x4(%rbp),%rdi
shl    $0x3,%rdi
call   1080 <malloc@plt>
mov    %rax,%rdx
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movslq -0x4(%rbp),%rdi
shl    $0x3,%rdi
call   1080 <malloc@plt>
mov    %rax,%rdx
mov    -0x50(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b5 <norm+0x55>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    $0x0,%al
call   1070 <transpose@plt>
mov    -0x4(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    $0x0,%al
call   1040 <mat_mat_mult@plt>
mov    -0x4(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    $0x0,%al
call   1060 <mat_vec_mult@plt>
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%edi
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    $0x10,%esi
mov    $0x10000,%edx
movsd  0xd96(%rip),%xmm0
lea    -0x38(%rbp),%r11
lea    -0x58(%rbp),%r10
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
call   *%rax
mov    %eax,-0x5c(%rbp)
movsd  -0x58(%rbp),%xmm0
lea    0xd7c(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12d6 <norm+0x176>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    129a <norm+0x13a>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x5c(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<norm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8,0x28(%rsp)
mov    %rcx,0x20(%rsp)
mov    %rdx,0x18(%rsp)
mov    %rsi,0x8(%rsp)
mov    %edi,%ebp
movslq %edi,%r13
lea    0x0(,%r13,8),%r12
mov    %r12,%rdi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1080 <malloc@plt>
mov    %rax,0x30(%rsp)
mov    %r12,%rdi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,0x14(%rsp)
mov    %ebp,%r14d
test   %r13d,%r13d
jle    11f1 <norm+0x91>
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1080 <malloc@plt>
mov    %rax,(%r15,%r13,8)
mov    %r12,%rdi
call   1080 <malloc@plt>
mov    %rax,(%rbx,%r13,8)
add    $0x1,%r13
cmp    %r13,%r14
jne    11d0 <norm+0x70>
mov    0x14(%rsp),%r12d
mov    %r12d,%edi
mov    0x18(%rsp),%rbp
mov    %rbp,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <transpose@plt>
mov    %r12d,%edi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <mat_mat_mult@plt>
mov    %r12d,%edi
mov    %r15,%rsi
mov    0x20(%rsp),%rdx
mov    0x30(%rsp),%r13
mov    %r13,%rcx
xor    %eax,%eax
call   1060 <mat_vec_mult@plt>
lea    0x38(%rsp),%rax
lea    0x40(%rsp),%r10
movsd  0xdb6(%rip),%xmm0
mov    %r12d,%edi
mov    $0x10,%esi
mov    $0x10000,%edx
mov    %rbx,%rcx
mov    %r13,%r8
mov    0x28(%rsp),%r9
push   %rax
push   %r10
call   *0x18(%rsp)
add    $0x10,%rsp
mov    %eax,0x8(%rsp)
movsd  0x38(%rsp),%xmm0
lea    0xd8a(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
test   %r12d,%r12d
jle    12ab <norm+0x14b>
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    (%r15,%rbp,8),%rdi
call   1030 <free@plt>
mov    (%rbx,%rbp,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1290 <norm+0x130>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"norm took %.5f seconds\0A\00"
define i32 @norm(i32 %0, i32 (i32, i8, i32, double, double**, double*, double*, double*, double*)* %1, double** %2, double* %3, double* %4) {
%6 = alloca i32
%7 = alloca i32 (i32, i8, i32, double, double**, double*, double*, double*, double*)*
%8 = alloca double**
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%12 = alloca double
%13 = alloca double**
%14 = alloca double*
%15 = alloca double**
%16 = alloca double
%17 = alloca i32
store i32 %0, i32* %6
store i32 (i32, i8, i32, double, double**, double*, double*, double*, double*)* %1, i32 (i32, i8, i32, double, double**, double*, double*, double*, double*)** %7
store double** %2, double*** %8
store double* %3, double** %9
store double* %4, double** %10
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 8
%21 = call i8* @malloc(i64 %20)
%22 = bitcast i8* %21 to double**
store double** %22, double*** %13
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 8
%26 = call i8* @malloc(i64 %25)
%27 = bitcast i8* %26 to double*
store double* %27, double** %14
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 8
%31 = call i8* @malloc(i64 %30)
%32 = bitcast i8* %31 to double**
store double** %32, double*** %15
store i32 0, i32* %11
br label %33
33: ; preds = %56, %5
%34 = load i32, i32* %11
%35 = load i32, i32* %6
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %59
37: ; preds = %33
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = mul i64 %39, 8
%41 = call i8* @malloc(i64 %40)
%42 = bitcast i8* %41 to double*
%43 = load double**, double*** %13
%44 = load i32, i32* %11
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double*, double** %43, i64 %45
store double* %42, double** %46
%47 = load i32, i32* %6
%48 = sext i32 %47 to i64
%49 = mul i64 %48, 8
%50 = call i8* @malloc(i64 %49)
%51 = bitcast i8* %50 to double*
%52 = load double**, double*** %15
%53 = load i32, i32* %11
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double*, double** %52, i64 %54
store double* %51, double** %55
br label %56
56: ; preds = %37
%57 = load i32, i32* %11
%58 = add nsw i32 %57, 1
store i32 %58, i32* %11
br label %33
59: ; preds = %33
%60 = load i32, i32* %6
%61 = load double**, double*** %8
%62 = load double**, double*** %13
%63 = call i32 (i32, double**, double**, ...) bitcast (i32 (...)* @transpose to i32 (i32, double**, double**, ...)*)(i32 %60, double** %61, double** %62)
%64 = load i32, i32* %6
%65 = load double**, double*** %13
%66 = load double**, double*** %8
%67 = load double**, double*** %15
%68 = call i32 (i32, double**, double**, double**, ...) bitcast (i32 (...)* @mat_mat_mult to i32 (i32, double**, double**, double**, ...)*)(i32 %64, double** %65, double** %66, double** %67)
%69 = load i32, i32* %6
%70 = load double**, double*** %13
%71 = load double*, double** %9
%72 = load double*, double** %14
%73 = call i32 (i32, double**, double*, double*, ...) bitcast (i32 (...)* @mat_vec_mult to i32 (i32, double**, double*, double*, ...)*)(i32 %69, double** %70, double* %71, double* %72)
%74 = load i32 (i32, i8, i32, double, double**, double*, double*, double*, double*)*, i32 (i32, i8, i32, double, double**, double*, double*, double*, double*)** %7
%75 = load i32, i32* %6
%76 = load double**, double*** %15
%77 = load double*, double** %14
%78 = load double*, double** %10
%79 = call i32 %74(i32 %75, i8 signext 16, i32 65536, double 1.250000e-01, double** %76, double* %77, double* %78, double* %12, double* %16)
store i32 %79, i32* %17
%80 = load double, double* %16
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), double %80)
store i32 0, i32* %11
br label %82
82: ; preds = %99, %59
%83 = load i32, i32* %11
%84 = load i32, i32* %6
%85 = icmp slt i32 %83, %84
br i1 %85, label %86, label %102
86: ; preds = %82
%87 = load double**, double*** %13
%88 = load i32, i32* %11
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds double*, double** %87, i64 %89
%91 = load double*, double** %90
%92 = bitcast double* %91 to i8*
%93 = load double**, double*** %15
%94 = load i32, i32* %11
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds double*, double** %93, i64 %95
%97 = load double*, double** %96
%98 = bitcast double* %97 to i8*
br label %99
99: ; preds = %86
%100 = load i32, i32* %11
%101 = add nsw i32 %100, 1
store i32 %101, i32* %11
br label %82
102: ; preds = %82
%103 = load double**, double*** %13
%104 = bitcast double** %103 to i8*
%105 = load double**, double*** %15
%106 = bitcast double** %105 to i8*
%107 = load double*, double** %14
%108 = bitcast double* %107 to i8*
%109 = load i32, i32* %17
ret i32 %109
}

LLVM IR (-O2):
@.str = [24 x i8] c"norm took %.5f seconds\0A\00"
define i32 @norm(i32 %0, i32 (i32, i8, i32, double, double**, double*, double*, double*, double*)* nocapture %1, double** %2, double* %3, double* %4) {
%6 = alloca double
%7 = alloca double
%8 = bitcast double* %6 to i8*
%9 = sext i32 %0 to i64
%10 = shl nsw i64 %9, 3
%11 = tail call i8* @malloc(i64 %10)
%12 = bitcast i8* %11 to double**
%13 = tail call i8* @malloc(i64 %10)
%14 = bitcast i8* %13 to double*
%15 = tail call i8* @malloc(i64 %10)
%16 = bitcast i8* %15 to double**
%17 = icmp sgt i32 %0, 0
br i1 %17, label %18, label %30
18: ; preds = %5
%19 = zext i32 %0 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 0, %18 ], [ %28, %20 ]
%22 = tail call i8* @malloc(i64 %10)
%23 = getelementptr inbounds double*, double** %12, i64 %21
%24 = bitcast double** %23 to i8**
store i8* %22, i8** %24
%25 = tail call i8* @malloc(i64 %10)
%26 = getelementptr inbounds double*, double** %16, i64 %21
%27 = bitcast double** %26 to i8**
store i8* %25, i8** %27
%28 = add nuw nsw i64 %21, 1
%29 = icmp eq i64 %28, %19
br i1 %29, label %30, label %20
30: ; preds = %20, %5
%31 = tail call i32 (i32, double**, double**, ...) bitcast (i32 (...)* @transpose to i32 (i32, double**, double**, ...)*)(i32 %0, double** %2, double** %12)
%32 = tail call i32 (i32, double**, double**, double**, ...) bitcast (i32 (...)* @mat_mat_mult to i32 (i32, double**, double**, double**, ...)*)(i32 %0, double** %12, double** %2, double** %16)
%33 = tail call i32 (i32, double**, double*, double*, ...) bitcast (i32 (...)* @mat_vec_mult to i32 (i32, double**, double*, double*, ...)*)(i32 %0, double** %12, double* %3, double* %14)
%34 = bitcast double* %7 to i8*
%35 = call i32 %1(i32 %0, i8 signext 16, i32 65536, double 1.250000e-01, double** %16, double* %14, double* %4, double* %6, double* %7)
%36 = load double, double* %7
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), double %36)
br i1 %17, label %38, label %50
38: ; preds = %30
%39 = zext i32 %0 to i64
br label %40
40: ; preds = %38, %40
%41 = phi i64 [ 0, %38 ], [ %48, %40 ]
%42 = getelementptr inbounds double*, double** %12, i64 %41
%43 = bitcast double** %42 to i8**
%44 = load i8*, i8** %43
%45 = getelementptr inbounds double*, double** %16, i64 %41
%46 = bitcast double** %45 to i8**
%47 = load i8*, i8** %46
%48 = add nuw nsw i64 %41, 1
%49 = icmp eq i64 %48, %39
br i1 %49, label %50, label %40
50: ; preds = %40, %30
ret i32 %35
}