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

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(double *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
double pow(double, double);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ thomas_alg(double *, double *, double *, double *, int);
void test_1(int n) {
  FILE *f = fopen("input.dat", "r");
  double *md = (double *)malloc(sizeof(double) * n);
  double *ud = (double *)malloc(sizeof(double) * (n - 1));
  double *ld = (double *)malloc(sizeof(double) * (n - 1));
  double *fd = (double *)malloc(sizeof(double) * n);
  double *ans = (double *)malloc(sizeof(double) * n);
  fread(md, sizeof(double), n, f);
  fread(ud, sizeof(double), (n - 1), f);
  fread(ld, sizeof(double), (n - 1), f);
  fread(fd, sizeof(double), n, f);
  fread(ans, sizeof(double), n, f);
  thomas_alg(ld, md, ud, fd, n);
  int i;
  double err = 0;
  for (i = 0; i < n; i++)
    err += (fd[i] - ans[i]) * (fd[i] - ans[i]);
  err = pow(err / n, .5);
  printf("Error is %.5e\n", err);
  free(md);
  free(ud);
  free(ld);
  free(fd);
  free(ans);
  return;
}


x86 assembly (clang, -O0):
<test_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe86(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x8,%esi
call   1040 <fread@plt>
mov    -0x20(%rbp),%rdi
mov    -0x4(%rbp),%edx
sub    $0x1,%edx
mov    -0x10(%rbp),%rcx
mov    $0x8,%esi
call   1040 <fread@plt>
mov    -0x28(%rbp),%rdi
mov    -0x4(%rbp),%edx
sub    $0x1,%edx
mov    -0x10(%rbp),%rcx
mov    $0x8,%esi
call   1040 <fread@plt>
mov    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x8,%esi
call   1040 <fread@plt>
mov    -0x38(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x8,%esi
call   1040 <fread@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x4(%rbp),%r8d
call   1060 <thomas_alg@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12f0 <test_1+0x180>
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1290 <test_1+0x120>
movsd  -0x48(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xcfa(%rip),%xmm1
call   1090 <pow@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
lea    0xcf8(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r14d
lea    0xe80(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
lea    0x0(,%r14,8),%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,0x10(%rsp)
lea    -0x1(%r14),%eax
mov    %eax,0x4(%rsp)
lea    -0x8(,%r14,8),%ebx
ff
mov    %ebx,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
mov    %ebx,%edi
call   1070 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    %r15,%rdi
mov    $0x8,%esi
mov    %r14d,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %r13,%rdi
mov    $0x8,%esi
mov    0x4(%rsp),%r15d
mov    %r15d,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    0x8(%rsp),%rdi
mov    $0x8,%esi
mov    %r15d,%edx
mov    %rdi,%r15
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
mov    %r14d,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %rbp,%rdi
mov    $0x8,%esi
mov    %r14d,%edx
mov    %r12,%rcx
mov    0x10(%rsp),%r12
call   1040 <fread@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%r15
mov    %r13,%rdx
mov    %rbx,%rcx
mov    %r14d,%r8d
call   1060 <thomas_alg@plt>
test   %r14d,%r14d
jle    128c <test_1+0x11c>
mov    %r14d,%edx
lea    -0x1(%rdx),%rcx
mov    %edx,%eax
and    $0x3,%eax
cmp    $0x3,%rcx
jae    1295 <test_1+0x125>
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
jmp    12f8 <test_1+0x188>
xorpd  %xmm0,%xmm0
jmp    132b <test_1+0x1bb>
and    $0xfffffffc,%edx
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
xchg   %ax,%ax
movsd  (%rbx,%rcx,8),%xmm1
movsd  0x8(%rbx,%rcx,8),%xmm2
subsd  0x0(%rbp,%rcx,8),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
subsd  0x8(%rbp,%rcx,8),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
movsd  0x10(%rbx,%rcx,8),%xmm1
subsd  0x10(%rbp,%rcx,8),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
movsd  0x18(%rbx,%rcx,8),%xmm0
subsd  0x18(%rbp,%rcx,8),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
add    $0x4,%rcx
cmp    %rcx,%rdx
jne    12a0 <test_1+0x130>
test   %rax,%rax
je     132b <test_1+0x1bb>
lea    0x0(,%rcx,8),%rdx
add    %rbp,%rdx
lea    (%rbx,%rcx,8),%rcx
xor    %esi,%esi
xchg   %ax,%ax
movsd  (%rcx,%rsi,8),%xmm1
subsd  (%rdx,%rsi,8),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
add    $0x1,%rsi
cmp    %rsi,%rax
jne    1310 <test_1+0x1a0>
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
divsd  %xmm1,%xmm0
movsd  0xcc1(%rip),%xmm1
call   1090 <pow@plt>
lea    0xcc9(%rip),%rdi
call   1050 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

LLVM IR (-O2):
@.str = [10 x i8] c"input.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"Error is %.5e\0A\00"
define void @test_1(i32 %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = shl i32 %0, 3
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to double*
%6 = add nsw i32 %0, -1
%7 = shl i32 %6, 3
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to double*
%10 = tail call i64 @malloc(i32 %7)
%11 = inttoptr i64 %10 to double*
%12 = tail call i64 @malloc(i32 %3)
%13 = inttoptr i64 %12 to double*
%14 = tail call i64 @malloc(i32 %3)
%15 = inttoptr i64 %14 to double*
%16 = tail call i32 @fread(double* %5, i32 8, i32 %0, i32* %2)
%17 = tail call i32 @fread(double* %9, i32 8, i32 %6, i32* %2)
%18 = tail call i32 @fread(double* %11, i32 8, i32 %6, i32* %2)
%19 = tail call i32 @fread(double* %13, i32 8, i32 %0, i32* %2)
%20 = tail call i32 @fread(double* %15, i32 8, i32 %0, i32* %2)
%21 = tail call i32 @thomas_alg(double* %11, double* %5, double* %9, double* %13, i32 %0)
%22 = icmp sgt i32 %0, 0
br i1 %22, label %23, label %82
23: ; preds = %1
%24 = zext i32 %0 to i64
%25 = add nsw i64 %24, -1
%26 = and i64 %24, 3
%27 = icmp ult i64 %25, 3
br i1 %27, label %64, label %28
28: ; preds = %23
%29 = and i64 %24, 4294967292
br label %30
30: ; preds = %30, %28
%31 = phi i64 [ 0, %28 ], [ %61, %30 ]
%32 = phi double [ 0.000000e+00, %28 ], [ %60, %30 ]
%33 = phi i64 [ 0, %28 ], [ %62, %30 ]
%34 = getelementptr inbounds double, double* %13, i64 %31
%35 = load double, double* %34
%36 = getelementptr inbounds double, double* %15, i64 %31
%37 = load double, double* %36
%38 = fsub double %35, %37
%39 = tail call double @llvm.fmuladd.f64(double %38, double %38, double %32)
%40 = or i64 %31, 1
%41 = getelementptr inbounds double, double* %13, i64 %40
%42 = load double, double* %41
%43 = getelementptr inbounds double, double* %15, i64 %40
%44 = load double, double* %43
%45 = fsub double %42, %44
%46 = tail call double @llvm.fmuladd.f64(double %45, double %45, double %39)
%47 = or i64 %31, 2
%48 = getelementptr inbounds double, double* %13, i64 %47
%49 = load double, double* %48
%50 = getelementptr inbounds double, double* %15, i64 %47
%51 = load double, double* %50
%52 = fsub double %49, %51
%53 = tail call double @llvm.fmuladd.f64(double %52, double %52, double %46)
%54 = or i64 %31, 3
%55 = getelementptr inbounds double, double* %13, i64 %54
%56 = load double, double* %55
%57 = getelementptr inbounds double, double* %15, i64 %54
%58 = load double, double* %57
%59 = fsub double %56, %58
%60 = tail call double @llvm.fmuladd.f64(double %59, double %59, double %53)
%61 = add nuw nsw i64 %31, 4
%62 = add i64 %33, 4
%63 = icmp eq i64 %62, %29
br i1 %63, label %64, label %30
64: ; preds = %30, %23
%65 = phi double [ undef, %23 ], [ %60, %30 ]
%66 = phi i64 [ 0, %23 ], [ %61, %30 ]
%67 = phi double [ 0.000000e+00, %23 ], [ %60, %30 ]
%68 = icmp eq i64 %26, 0
br i1 %68, label %82, label %69
69: ; preds = %64, %69
%70 = phi i64 [ %79, %69 ], [ %66, %64 ]
%71 = phi double [ %78, %69 ], [ %67, %64 ]
%72 = phi i64 [ %80, %69 ], [ 0, %64 ]
%73 = getelementptr inbounds double, double* %13, i64 %70
%74 = load double, double* %73
%75 = getelementptr inbounds double, double* %15, i64 %70
%76 = load double, double* %75
%77 = fsub double %74, %76
%78 = tail call double @llvm.fmuladd.f64(double %77, double %77, double %71)
%79 = add nuw nsw i64 %70, 1
%80 = add i64 %72, 1
%81 = icmp eq i64 %80, %26
br i1 %81, label %82, label %69
82: ; preds = %64, %69, %1
%83 = phi double [ 0.000000e+00, %1 ], [ %65, %64 ], [ %78, %69 ]
%84 = sitofp i32 %0 to double
%85 = fdiv double %83, %84
%86 = tail call double @pow(double %85, double 5.000000e-01)
%87 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), double %86)
%88 = tail call i32 @free(double* %5)
%89 = tail call i32 @free(double* %9)
%90 = tail call i32 @free(double* %11)
%91 = tail call i32 @free(double* %13)
%92 = tail call i32 @free(double* %15)
ret void
}