void calc_thermal_matrix_gauss(design) struct Design *design;
{
  struct Component *comp;
  double *flux, **R;
  void set_up_tfield(), set_up_flux(), set_up_coef_matrix();
  void gauss_seidel(), find_comp_temp(), find_contained_nodes();
  int i, j, node_dim[3], tot_nodes, hbw, width;
  printf("GS   ");
  set_up_tfield(design, node_dim);
  hbw = node_dim[1] * node_dim[2];
  width = 2 * hbw + 1;
  tot_nodes = node_dim[0] * hbw;
  find_contained_nodes(design, hbw, node_dim[2]);
  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, R, tot_nodes, hbw, node_dim[2]);
  gauss_seidel(design, R, flux, tot_nodes, hbw, node_dim[2]);
  find_comp_temp(design);
  for (i = 0; i < tot_nodes; i++)
    free(R[i]);
  free(R);
  free(flux);
}


x86 assembly (clang, -O0):
<calc_thermal_matrix_gauss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x34(%rbp),%rsi
mov    $0x0,%al
call   1090 <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)
mov    -0x8(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    $0x0,%al
call   1060 <find_contained_nodes@plt>
movslq -0x38(%rbp),%rdi
shl    $0x3,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    122c <calc_thermal_matrix_gauss+0x9c>
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    1202 <calc_thermal_matrix_gauss+0x72>
movslq -0x38(%rbp),%rdi
shl    $0x3,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    12b8 <calc_thermal_matrix_gauss+0x128>
movslq -0x40(%rbp),%rdi
shl    $0x3,%rdi
call   1070 <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    12a5 <calc_thermal_matrix_gauss+0x115>
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    1273 <calc_thermal_matrix_gauss+0xe3>
jmp    12aa <calc_thermal_matrix_gauss+0x11a>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1244 <calc_thermal_matrix_gauss+0xb4>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x38(%rbp),%edx
mov    $0x0,%al
call   1080 <set_up_flux@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x38(%rbp),%ecx
mov    -0x3c(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    $0x0,%al
call   10a0 <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    -0x2c(%rbp),%r9d
mov    $0x0,%al
call   1050 <gauss_seidel@plt>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   10b0 <find_comp_temp@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1343 <calc_thermal_matrix_gauss+0x1b3>
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    1318 <calc_thermal_matrix_gauss+0x188>
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_gauss>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%r14
lea    0xe48(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   10a0 <set_up_tfield@plt>
mov    0x14(%rsp),%edx
mov    0x10(%rsp),%r13d
imul   %edx,%r13d
mov    0xc(%rsp),%ebp
imul   %r13d,%ebp
mov    %r14,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1070 <find_contained_nodes@plt>
movslq %ebp,%rbx
lea    0x0(,%rbx,8),%rdi
mov    %rdi,0x18(%rsp)
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %ebp,%r15d
test   %ebx,%ebx
jle    12ae <calc_thermal_matrix_gauss+0x10e>
mov    %ebp,0x8(%rsp)
mov    %r14,0x30(%rsp)
lea    0x0(%r13,%r13,1),%r14d
mov    %r12,%rdi
mov    %r13,0x20(%rsp)
lea    0x1(%r13,%r13,1),%r12d
lea    0x0(,%r15,8),%rdx
xor    %r13d,%r13d
mov    %rdi,0x28(%rsp)
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x18(%rsp),%rdi
call   1080 <malloc@plt>
mov    %rax,%rbx
movslq %r12d,%rbp
shl    $0x3,%rbp
mov    %r14d,%r14d
shl    $0x3,%r14
or     $0x8,%r14
jmp    1279 <calc_thermal_matrix_gauss+0xd9>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    %r13,%r15
je     1299 <calc_thermal_matrix_gauss+0xf9>
mov    %rbp,%rdi
call   1080 <malloc@plt>
mov    %rax,(%rbx,%r13,8)
test   %r12d,%r12d
jle    1270 <calc_thermal_matrix_gauss+0xd0>
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
jmp    1270 <calc_thermal_matrix_gauss+0xd0>
mov    0x30(%rsp),%r14
mov    0x28(%rsp),%r12
mov    0x8(%rsp),%ebp
mov    0x20(%rsp),%r13
jmp    12bb <calc_thermal_matrix_gauss+0x11b>
mov    0x18(%rsp),%rdi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1090 <set_up_flux@plt>
mov    0x14(%rsp),%r9d
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
mov    %r13d,%r8d
xor    %eax,%eax
call   10b0 <set_up_coef_matrix@plt>
mov    0x14(%rsp),%r9d
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %ebp,%ecx
mov    %r13d,%r8d
xor    %eax,%eax
call   1060 <gauss_seidel@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   10c0 <find_comp_temp@plt>
test   %ebp,%ebp
jle    1322 <calc_thermal_matrix_gauss+0x182>
xor    %ebp,%ebp
xchg   %ax,%ax
mov    (%rbx,%rbp,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1310 <calc_thermal_matrix_gauss+0x170>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%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
@.str = [6 x i8] c"GS \00"
define void @calc_thermal_matrix_gauss(%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 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = load %struct.Design*, %struct.Design** %2
%14 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 0
%15 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 2
%18 = load i32, i32* %17
%19 = mul nsw i32 %16, %18
store i32 %19, i32* %10
%20 = load i32, i32* %10
%21 = mul nsw i32 2, %20
%22 = add nsw i32 %21, 1
store i32 %22, i32* %11
%23 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 0
%24 = load i32, i32* %23
%25 = load i32, i32* %10
%26 = mul nsw i32 %24, %25
store i32 %26, i32* %9
%27 = load %struct.Design*, %struct.Design** %2
%28 = load i32, i32* %10
%29 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 2
%30 = load i32, i32* %29
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = mul i64 8, %32
%34 = call i8* @malloc(i64 %33)
%35 = bitcast i8* %34 to double*
store double* %35, double** %4
store i32 0, i32* %6
br label %36
36: ; preds = %45, %1
%37 = load i32, i32* %6
%38 = load i32, i32* %9
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %48
40: ; preds = %36
%41 = load double*, double** %4
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %41, i64 %43
store double 0.000000e+00, double* %44
br label %45
45: ; preds = %40
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %36
48: ; preds = %36
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = mul i64 8, %50
%52 = call i8* @malloc(i64 %51)
%53 = bitcast i8* %52 to double**
store double** %53, double*** %5
store i32 0, i32* %6
br label %54
54: ; preds = %85, %48
%55 = load i32, i32* %6
%56 = load i32, i32* %9
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %88
58: ; preds = %54
%59 = load i32, i32* %11
%60 = sext i32 %59 to i64
%61 = mul i64 8, %60
%62 = call i8* @malloc(i64 %61)
%63 = bitcast i8* %62 to double*
%64 = load double**, double*** %5
%65 = load i32, i32* %6
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double*, double** %64, i64 %66
store double* %63, double** %67
store i32 0, i32* %7
br label %68
68: ; preds = %81, %58
%69 = load i32, i32* %7
%70 = load i32, i32* %11
%71 = icmp slt i32 %69, %70
br i1 %71, label %72, label %84
72: ; preds = %68
%73 = load double**, double*** %5
%74 = load i32, i32* %6
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds double*, double** %73, i64 %75
%77 = load double*, double** %76
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds double, double* %77, i64 %79
store double 0.000000e+00, double* %80
br label %81
81: ; preds = %72
%82 = load i32, i32* %7
%83 = add nsw i32 %82, 1
store i32 %83, i32* %7
br label %68
84: ; preds = %68
br label %85
85: ; preds = %84
%86 = load i32, i32* %6
%87 = add nsw i32 %86, 1
store i32 %87, i32* %6
br label %54
88: ; preds = %54
%89 = load %struct.Design*, %struct.Design** %2
%90 = load double*, double** %4
%91 = load i32, i32* %9
%92 = load %struct.Design*, %struct.Design** %2
%93 = load double*, double** %4
%94 = load double**, double*** %5
%95 = load i32, i32* %9
%96 = load i32, i32* %10
%97 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 2
%98 = load i32, i32* %97
%99 = load %struct.Design*, %struct.Design** %2
%100 = load double**, double*** %5
%101 = load double*, double** %4
%102 = load i32, i32* %9
%103 = load i32, i32* %10
%104 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 2
%105 = load i32, i32* %104
%106 = load %struct.Design*, %struct.Design** %2
store i32 0, i32* %6
br label %107
107: ; preds = %118, %88
%108 = load i32, i32* %6
%109 = load i32, i32* %9
%110 = icmp slt i32 %108, %109
br i1 %110, label %111, label %121
111: ; preds = %107
%112 = load double**, double*** %5
%113 = load i32, i32* %6
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds double*, double** %112, i64 %114
%116 = load double*, double** %115
%117 = bitcast double* %116 to i8*
br label %118
118: ; preds = %111
%119 = load i32, i32* %6
%120 = add nsw i32 %119, 1
store i32 %120, i32* %6
br label %107
121: ; preds = %107
%122 = load double**, double*** %5
%123 = bitcast double** %122 to i8*
%124 = load double*, double** %4
%125 = bitcast double* %124 to i8*
ret void
}

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