#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ thomas(double *, double *, double *, double *, int);
int main() {
  double a[] = {0.0, 2.0, 3.0};
  double b[] = {1.0, 3.0, 6.0};
  double c[] = {4.0, 5.0, 0.0};
  double x[] = {7.0, 5.0, 3.0};
  printf("The system,\n");
  printf("[1.0  4.0  0.0][x] = [7.0]\n");
  printf("[2.0  3.0  5.0][y] = [5.0]\n");
  printf("[0.0  3.0  6.0][z] = [3.0]\n");
  printf("has the solution:\n");
  thomas(a, b, c, x, 3);
  for (size_t i = 0; i < 3; ++i) {
    printf("[%f]\n", x[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec4(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xec1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xec6(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xec3(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xec0(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xec5(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xec2(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xebf(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xec4(%rip),%rax
mov    %rax,-0x80(%rbp)
mov    0xec1(%rip),%rax
mov    %rax,-0x78(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x70(%rbp)
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x60(%rbp),%rdx
lea    -0x80(%rbp),%rcx
mov    $0x3,%r8d
call   1040 <thomas@plt>
movq   $0x0,-0x88(%rbp)
cmpq   $0x3,-0x88(%rbp)
03
jae    1262 <main+0x142>
mov    -0x88(%rbp),%rax
movsd  -0x80(%rbp,%rax,8),%xmm0
lea    0xea8(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x88(%rbp)
jmp    1222 <main+0x102>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
mov    0xed1(%rip),%rax
mov    %rax,0x70(%rsp)
movaps 0xeb5(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
mov    0xed9(%rip),%rax
mov    %rax,0x50(%rsp)
movaps 0xebd(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
mov    0xee1(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xec5(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
mov    0xee9(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0xecd(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xee0(%rip),%rdi
call   1030 <puts@plt>
lea    0xee0(%rip),%rdi
call   1030 <puts@plt>
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
lea    0xefe(%rip),%rdi
call   1030 <puts@plt>
lea    0xf0d(%rip),%rdi
call   1030 <puts@plt>
lea    0x60(%rsp),%rdi
lea    0x40(%rsp),%rsi
lea    0x20(%rsp),%rdx
mov    %rsp,%rcx
mov    $0x3,%r8d
call   1050 <thomas@plt>
movsd  (%rsp),%xmm0
lea    0xe7c(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x10(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.a = [3 x double] [double 0.000000e+00, double 2.000000e+00, double 3.000000e+00]
@__const.main.b = [3 x double] [double 1.000000e+00, double 3.000000e+00, double 6.000000e+00]
@__const.main.c = [3 x double] [double 4.000000e+00, double 5.000000e+00, double 0.000000e+00]
@__const.main.x = [3 x double] [double 7.000000e+00, double 5.000000e+00, double 3.000000e+00]
@.str = [13 x i8] c"The system,\0A\00"
@.str.1 = [28 x i8] c"[1.0 4.0 0.0][x] = [7.0]\0A\00"
@.str.2 = [28 x i8] c"[2.0 3.0 5.0][y] = [5.0]\0A\00"
@.str.3 = [28 x i8] c"[0.0 3.0 6.0][z] = [3.0]\0A\00"
@.str.4 = [19 x i8] c"has the solution:\0A\00"
@.str.5 = [6 x i8] c"[%f]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x double]
%3 = alloca [3 x double]
%4 = alloca [3 x double]
%5 = alloca [3 x double]
%6 = alloca i64
store i32 0, i32* %1
%7 = bitcast [3 x double]* %2 to i8*
%8 = bitcast [3 x double]* %3 to i8*
%9 = bitcast [3 x double]* %4 to i8*
%10 = bitcast [3 x double]* %5 to i8*
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%16 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 0
%17 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 0
%18 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%19 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%20 = call i32 @thomas(double* %16, double* %17, double* %18, double* %19, i32 3)
store i64 0, i64* %6
br label %21
21: ; preds = %29, %0
%22 = load i64, i64* %6
%23 = icmp ult i64 %22, 3
br i1 %23, label %24, label %32
24: ; preds = %21
%25 = load i64, i64* %6
%26 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 %25
%27 = load double, double* %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), double %27)
br label %29
29: ; preds = %24
%30 = load i64, i64* %6
%31 = add i64 %30, 1
store i64 %31, i64* %6
br label %21
32: ; preds = %21
ret i32 0
}

LLVM IR (-O2):
@__const.main.a = [3 x double] [double 0.000000e+00, double 2.000000e+00, double 3.000000e+00]
@__const.main.b = [3 x double] [double 1.000000e+00, double 3.000000e+00, double 6.000000e+00]
@__const.main.c = [3 x double] [double 4.000000e+00, double 5.000000e+00, double 0.000000e+00]
@__const.main.x = [3 x double] [double 7.000000e+00, double 5.000000e+00, double 3.000000e+00]
@.str.5 = [6 x i8] c"[%f]\0A\00"
@str = [12 x i8] c"The system,\00"
@str.6 = [27 x i8] c"[1.0 4.0 0.0][x] = [7.0]\00"
@str.7 = [27 x i8] c"[2.0 3.0 5.0][y] = [5.0]\00"
@str.8 = [27 x i8] c"[0.0 3.0 6.0][z] = [3.0]\00"
@str.9 = [18 x i8] c"has the solution:\00"
define i32 @main() {
%1 = alloca [3 x double]
%2 = alloca [3 x double]
%3 = alloca [3 x double]
%4 = alloca [3 x double]
%5 = bitcast [3 x double]* %1 to i8*
%6 = bitcast [3 x double]* %2 to i8*
%7 = bitcast [3 x double]* %3 to i8*
%8 = bitcast [3 x double]* %4 to i8*
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.6, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.7, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.8, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.9, i64 0, i64 0))
%14 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 0
%15 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 0
%16 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 0
%17 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%18 = call i32 @thomas(double* %14, double* %15, double* %16, double* %17, i32 3)
%19 = load double, double* %17
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), double %19)
%21 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 1
%22 = load double, double* %21
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), double %22)
%24 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 2
%25 = load double, double* %24
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), double %25)
ret i32 0
}