#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ theta_thomas;
typedef int /*<<< orphan*/ theta_exact;
typedef int /*<<< orphan*/ res;
typedef int /*<<< orphan*/ r;
typedef int /*<<< orphan*/ mat;
typedef int /*<<< orphan*/ d;
typedef int /*<<< orphan*/ b;
typedef int /*<<< orphan*/ aug;
typedef int /*<<< orphan*/ a;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *, double);
void calc_size_heap(int ch, double *a, double *b, double *d, double **mat,
                    double **aug, double *r, double *res, double *theta_exact,
                    double *theta_thomas, int N) {
  double space;
  switch (ch) {
  case 0:
    space = sizeof(mat) * (N * N) + sizeof(aug) * (N * (N + 1)) +
            sizeof(res) * N + sizeof(theta_exact) * N + sizeof(r) * N;
    break;
  case 1:
    space = sizeof(a) * (N - 1) + sizeof(b) * (N - 1) + sizeof(d) * N +
            sizeof(mat) * (N * N) + sizeof(r) * N + sizeof(theta_exact) * N +
            sizeof(theta_thomas) * N;
  }
  printf("Space used in %s = %.3lf KB\n", (ch == 0) ? "Gauss" : "Thomas",
         space / 1000);
}


x86 assembly (clang, -O0):
<calc_size_heap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x30(%rbp),%eax
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x3c(%rbp)
test   %eax,%eax
je     1166 <calc_size_heap+0x56>
jmp    1155 <calc_size_heap+0x45>
mov    -0x3c(%rbp),%eax
sub    $0x1,%eax
je     11c3 <calc_size_heap+0xb3>
jmp    1222 <calc_size_heap+0x112>
movslq 0x30(%rbp),%rcx
mov    %ecx,%eax
mov    %eax,%edx
imul   %edx,%edx
movslq %edx,%rdx
mov    %eax,%esi
add    $0x1,%esi
imul   %esi,%eax
cltq
shl    $0x3,%rax
lea    (%rax,%rdx,8),%rax
lea    (%rax,%rcx,8),%rax
lea    (%rax,%rcx,8),%rax
lea    (%rax,%rcx,8),%rax
movq   %rax,%xmm0
movaps 0xe62(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xe66(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1222 <calc_size_heap+0x112>
movslq 0x30(%rbp),%rcx
mov    %ecx,%edx
mov    %edx,%eax
add    $0xffffffff,%eax
movslq %eax,%rsi
mov    %rsi,%rax
shl    $0x3,%rax
lea    (%rax,%rsi,8),%rax
lea    (%rax,%rcx,8),%rax
imul   %edx,%edx
movslq %edx,%rdx
lea    (%rax,%rdx,8),%rax
lea    (%rax,%rcx,8),%rax
lea    (%rax,%rcx,8),%rax
lea    (%rax,%rcx,8),%rax
movq   %rax,%xmm0
movaps 0xdfe(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xe02(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x4(%rbp),%ecx
lea    0xe1f(%rip),%rsi
lea    0xe12(%rip),%rax
cmp    $0x0,%ecx
cmove  %rax,%rsi
movsd  -0x38(%rbp),%xmm0
movsd  0xdd9(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xdd6(%rip),%rdi
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_size_heap>:
mov    0x28(%rsp),%eax
cmp    $0x1,%edi
je     113d <calc_size_heap+0x2d>
test   %edi,%edi
jne    117c <calc_size_heap+0x6c>
mov    %eax,%ecx
imul   %ecx,%ecx
lea    0x1(%rax),%edx
imul   %eax,%edx
movslq %edx,%rdx
cltq
add    %rax,%rcx
lea    (%rcx,%rax,2),%rax
add    %rdx,%rax
shl    $0x3,%rax
jmp    115b <calc_size_heap+0x4b>
cltq
lea    (%rax,%rax,1),%rcx
mov    %eax,%edx
imul   %edx,%edx
shl    $0x4,%rax
shl    $0x4,%rcx
lea    (%rax,%rdx,8),%rax
add    %rcx,%rax
add    $0xfffffffffffffff0,%rax
movq   %rax,%xmm1
punpckldq 0xe98(%rip),%xmm1
subpd  0xea0(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
test   %edi,%edi
lea    0xec0(%rip),%rax
lea    0xebf(%rip),%rsi
cmove  %rax,%rsi
divsd  0xe88(%rip),%xmm0
lea    0xe89(%rip),%rdi
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"Space used in %s = %.3lf KB\0A\00"
@.str.1 = [6 x i8] c"Gauss\00"
@.str.2 = [7 x i8] c"Thomas\00"
define void @calc_size_heap(i32 %0, double* %1, double* %2, double* %3, double** %4, double** %5, double* %6, double* %7, double* %8, double* %9, i32 %10) {
%12 = alloca i32
%13 = alloca double*
%14 = alloca double*
%15 = alloca double*
%16 = alloca double**
%17 = alloca double**
%18 = alloca double*
%19 = alloca double*
%20 = alloca double*
%21 = alloca double*
%22 = alloca i32
%23 = alloca double
store i32 %0, i32* %12
store double* %1, double** %13
store double* %2, double** %14
store double* %3, double** %15
store double** %4, double*** %16
store double** %5, double*** %17
store double* %6, double** %18
store double* %7, double** %19
store double* %8, double** %20
store double* %9, double** %21
store i32 %10, i32* %22
%24 = load i32, i32* %12
switch i32 %24, label %84 [
i32 0, label %25
i32 1, label %51
]
25: ; preds = %11
%26 = load i32, i32* %22
%27 = load i32, i32* %22
%28 = mul nsw i32 %26, %27
%29 = sext i32 %28 to i64
%30 = mul i64 8, %29
%31 = load i32, i32* %22
%32 = load i32, i32* %22
%33 = add nsw i32 %32, 1
%34 = mul nsw i32 %31, %33
%35 = sext i32 %34 to i64
%36 = mul i64 8, %35
%37 = add i64 %30, %36
%38 = load i32, i32* %22
%39 = sext i32 %38 to i64
%40 = mul i64 8, %39
%41 = add i64 %37, %40
%42 = load i32, i32* %22
%43 = sext i32 %42 to i64
%44 = mul i64 8, %43
%45 = add i64 %41, %44
%46 = load i32, i32* %22
%47 = sext i32 %46 to i64
%48 = mul i64 8, %47
%49 = add i64 %45, %48
%50 = uitofp i64 %49 to double
store double %50, double* %23
br label %84
51: ; preds = %11
%52 = load i32, i32* %22
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = mul i64 8, %54
%56 = load i32, i32* %22
%57 = sub nsw i32 %56, 1
%58 = sext i32 %57 to i64
%59 = mul i64 8, %58
%60 = add i64 %55, %59
%61 = load i32, i32* %22
%62 = sext i32 %61 to i64
%63 = mul i64 8, %62
%64 = add i64 %60, %63
%65 = load i32, i32* %22
%66 = load i32, i32* %22
%67 = mul nsw i32 %65, %66
%68 = sext i32 %67 to i64
%69 = mul i64 8, %68
%70 = add i64 %64, %69
%71 = load i32, i32* %22
%72 = sext i32 %71 to i64
%73 = mul i64 8, %72
%74 = add i64 %70, %73
%75 = load i32, i32* %22
%76 = sext i32 %75 to i64
%77 = mul i64 8, %76
%78 = add i64 %74, %77
%79 = load i32, i32* %22
%80 = sext i32 %79 to i64
%81 = mul i64 8, %80
%82 = add i64 %78, %81
%83 = uitofp i64 %82 to double
store double %83, double* %23
br label %84
84: ; preds = %51, %11, %25
%85 = load i32, i32* %12
%86 = icmp eq i32 %85, 0
%87 = zext i1 %86 to i64
%88 = select i1 %86, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)
%89 = load double, double* %23
%90 = fdiv double %89, 1.000000e+03
%91 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %88, double %90)
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"Space used in %s = %.3lf KB\0A\00"
@.str.1 = [6 x i8] c"Gauss\00"
@.str.2 = [7 x i8] c"Thomas\00"
define void @calc_size_heap(i32 %0, double* nocapture readnone %1, double* nocapture readnone %2, double* nocapture readnone %3, double** nocapture readnone %4, double** nocapture readnone %5, double* nocapture readnone %6, double* nocapture readnone %7, double* nocapture readnone %8, double* nocapture readnone %9, i32 %10) {
switch i32 %0, label %38 [
i32 0, label %12
i32 1, label %25
]
12: ; preds = %11
%13 = mul nsw i32 %10, %10
%14 = zext i32 %13 to i64
%15 = add nsw i32 %10, 1
%16 = mul nsw i32 %15, %10
%17 = sext i32 %16 to i64
%18 = sext i32 %10 to i64
%19 = shl nsw i64 %18, 1
%20 = add nsw i64 %14, %18
%21 = add nsw i64 %20, %19
%22 = add nsw i64 %21, %17
%23 = shl nsw i64 %22, 3
%24 = uitofp i64 %23 to double
br label %38
25: ; preds = %11
%26 = add nsw i32 %10, -1
%27 = sext i32 %26 to i64
%28 = sext i32 %10 to i64
%29 = mul nsw i32 %10, %10
%30 = zext i32 %29 to i64
%31 = shl nuw nsw i64 %30, 3
%32 = shl nsw i64 %28, 4
%33 = add nsw i64 %27, %28
%34 = shl nsw i64 %33, 4
%35 = add nsw i64 %32, %31
%36 = add nsw i64 %35, %34
%37 = uitofp i64 %36 to double
br label %38
38: ; preds = %25, %11, %12
%39 = phi double [ undef, %11 ], [ %37, %25 ], [ %24, %12 ]
%40 = icmp eq i32 %0, 0
%41 = select i1 %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)
%42 = fdiv double %39, 1.000000e+03
%43 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %41, double %42)
ret void
}