void calc_thermal_matrix(design) struct Design *design;
{
  struct Component *comp;
  double *flux, **R;
  void set_up_tfield(), set_up_flux(), set_up_coef_matrix();
  void matrix_solver(), find_comp_temp(), matrix_solver3();
  int i, j, node_dim[3], tot_nodes, hbw, width;
  set_up_tfield(design, node_dim);
  hbw = node_dim[1] * node_dim[2];
  width = 2 * hbw + 1;
  tot_nodes = node_dim[0] * hbw;
  flux = (double *)malloc(sizeof(double) * tot_nodes);
  for (i = 0; i < tot_nodes; i++)
    flux[i] = 0.0;
  R = (double **)malloc(sizeof(double *) * tot_nodes);
  for (i = 0; i < tot_nodes; i++) {
    R[i] = (double *)malloc(sizeof(double) * width);
    for (j = 0; j < width; ++j)
      R[i][j] = 0.0;
  }
  set_up_flux(design, flux, tot_nodes);
  set_up_coef_matrix(design, flux, tot_nodes, hbw, node_dim[2], R);
  matrix_solver(design, R, flux, tot_nodes, hbw);
  find_comp_temp(design, tot_nodes);
  for (i = 0; i < tot_nodes; i++)
    free(R[i]);
  free(R);
  free(flux);
}


x86 assembly (clang, -O0):
<calc_thermal_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x34(%rbp),%rsi
mov    $0x0,%al
call   1070 <set_up_tfield@plt>
mov    -0x30(%rbp),%eax
imul   -0x2c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x34(%rbp),%eax
imul   -0x3c(%rbp),%eax
mov    %eax,-0x38(%rbp)
movslq -0x38(%rbp),%rdi
shl    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    11ed <calc_thermal_matrix+0x7d>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c3 <calc_thermal_matrix+0x53>
movslq -0x38(%rbp),%rdi
shl    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1279 <calc_thermal_matrix+0x109>
movslq -0x40(%rbp),%rdi
shl    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    1266 <calc_thermal_matrix+0xf6>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1234 <calc_thermal_matrix+0xc4>
jmp    126b <calc_thermal_matrix+0xfb>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1205 <calc_thermal_matrix+0x95>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x38(%rbp),%edx
mov    $0x0,%al
call   1060 <set_up_flux@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x38(%rbp),%edx
mov    -0x3c(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x20(%rbp),%r9
mov    $0x0,%al
call   1080 <set_up_coef_matrix@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%ecx
mov    -0x3c(%rbp),%r8d
mov    $0x0,%al
call   1040 <matrix_solver@plt>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    $0x0,%al
call   1090 <find_comp_temp@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1302 <calc_thermal_matrix+0x192>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12d7 <calc_thermal_matrix+0x167>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_thermal_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%r12
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1080 <set_up_tfield@plt>
movslq 0x10(%rsp),%rax
movslq 0x14(%rsp),%r13
imul   %rax,%r13
movslq 0xc(%rsp),%rbp
imul   %r13,%rbp
mov    %rbp,%rbx
shl    $0x3,%rbx
mov    %rbx,%rdi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %ebp,%r15d
test   %ebp,%ebp
jle    126f <calc_thermal_matrix+0xef>
mov    %rbp,0x20(%rsp)
mov    %r12,0x28(%rsp)
mov    %r14,%rdi
lea    0x0(%r13,%r13,1),%r14d
mov    %r13,0x18(%rsp)
lea    0x1(%r13,%r13,1),%r12d
lea    0x0(,%r15,8),%rdx
xor    %r13d,%r13d
mov    %rdi,0x30(%rsp)
xor    %esi,%esi
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
movslq %r12d,%rbp
shl    $0x3,%rbp
mov    %r14d,%r14d
shl    $0x3,%r14
or     $0x8,%r14
jmp    1239 <calc_thermal_matrix+0xb9>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r13
cmp    %r13,%r15
je     1259 <calc_thermal_matrix+0xd9>
mov    %rbp,%rdi
call   1060 <malloc@plt>
mov    %rax,(%rbx,%r13,8)
test   %r12d,%r12d
jle    1230 <calc_thermal_matrix+0xb0>
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1040 <memset@plt>
jmp    1230 <calc_thermal_matrix+0xb0>
mov    0x30(%rsp),%r14
mov    0x28(%rsp),%r12
mov    0x20(%rsp),%rbp
mov    0x18(%rsp),%r13
jmp    127a <calc_thermal_matrix+0xfa>
mov    %rbx,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <set_up_flux@plt>
mov    0x14(%rsp),%r8d
mov    %r12,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %r13d,%ecx
mov    %rbx,%r9
xor    %eax,%eax
call   1090 <set_up_coef_matrix@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %ebp,%ecx
mov    %r13d,%r8d
xor    %eax,%eax
call   1050 <matrix_solver@plt>
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   10a0 <find_comp_temp@plt>
test   %ebp,%ebp
jle    12e2 <calc_thermal_matrix+0x162>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    (%rbx,%rbp,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    12d0 <calc_thermal_matrix+0x150>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.Design = type opaque
%struct.Component = type opaque
define void @calc_thermal_matrix(%struct.Design* %0) {
%2 = alloca [3 x i32]
%3 = bitcast [3 x i32]* %2 to i8*
%4 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%5 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 1
%6 = load i32, i32* %5
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 2
%8 = load i32, i32* %7
%9 = mul nsw i32 %8, %6
%10 = shl i32 %9, 1
%11 = or i32 %10, 1
%12 = load i32, i32* %4
%13 = mul nsw i32 %12, %9
%14 = sext i32 %13 to i64
%15 = shl nsw i64 %14, 3
%16 = call i8* @malloc(i64 %15)
%17 = bitcast i8* %16 to double*
%18 = icmp sgt i32 %13, 0
br i1 %18, label %22, label %19
19: ; preds = %1
%20 = call i8* @malloc(i64 %15)
%21 = bitcast i8* %20 to double**
br label %43
22: ; preds = %1
%23 = zext i32 %13 to i64
%24 = shl nuw nsw i64 %23, 3
%25 = call i8* @malloc(i64 %15)
%26 = bitcast i8* %25 to double**
%27 = sext i32 %11 to i64
%28 = shl nsw i64 %27, 3
%29 = icmp sgt i32 %11, 0
%30 = zext i32 %10 to i64
%31 = shl nuw nsw i64 %30, 3
%32 = or i64 %31, 8
%33 = zext i32 %13 to i64
br label %34
34: ; preds = %22, %40
%35 = phi i64 [ 0, %22 ], [ %41, %40 ]
%36 = call i8* @malloc(i64 %28)
%37 = getelementptr inbounds double*, double** %26, i64 %35
%38 = bitcast double** %37 to i8**
store i8* %36, i8** %38
br i1 %29, label %39, label %40
39: ; preds = %34
br label %40
40: ; preds = %39, %34
%41 = add nuw nsw i64 %35, 1
%42 = icmp eq i64 %41, %33
br i1 %42, label %43, label %34
43: ; preds = %40, %19
%44 = phi double** [ %21, %19 ], [ %26, %40 ]
%45 = phi i8* [ %20, %19 ], [ %25, %40 ]
%46 = load i32, i32* %7
br i1 %18, label %47, label %56
47: ; preds = %43
%48 = zext i32 %13 to i64
br label %49
49: ; preds = %47, %49
%50 = phi i64 [ 0, %47 ], [ %54, %49 ]
%51 = getelementptr inbounds double*, double** %44, i64 %50
%52 = bitcast double** %51 to i8**
%53 = load i8*, i8** %52
%54 = add nuw nsw i64 %50, 1
%55 = icmp eq i64 %54, %48
br i1 %55, label %56, label %49
56: ; preds = %49, %43
ret void
}