#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*/ memset(double *, int /*<<< orphan*/, size_t const);
void thomas(double *const a, double *const b, double *const c, double *const x,
            const size_t size) {
  double y[size];
  memset(y, 0, size * sizeof(double));
  y[0] = c[0] / b[0];
  x[0] = x[0] / b[0];
  for (size_t i = 1; i < size; ++i) {
    double scale = 1.0 / (b[i] - a[i] * y[i - 1]);
    y[i] = c[i] * scale;
    x[i] = (x[i] - a[i] * x[i - 1]) * scale;
  }
  for (int i = size - 2; i >= 0; --i) {
    x[i] -= y[i] * x[i + 1];
  }
}


x86 assembly (clang, -O0):
<thomas>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdx
shl    $0x3,%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x58(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsd  (%rcx),%xmm0
mov    -0x10(%rbp),%rcx
divsd  (%rcx),%xmm0
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
divsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movq   $0x1,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    128c <thomas+0x17c>
mov    -0x58(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x40(%rbp),%rdx
movsd  (%rcx,%rdx,8),%xmm0
mov    -0x8(%rbp),%rcx
mov    -0x40(%rbp),%rdx
movsd  (%rcx,%rdx,8),%xmm1
mov    -0x40(%rbp),%rcx
sub    $0x1,%rcx
movsd  (%rax,%rcx,8),%xmm2
movq   %xmm1,%rcx
movabs $0x8000000000000000,%rdx
xor    %rdx,%rcx
movq   %rcx,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe05(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x40(%rbp),%rdx
movsd  (%rcx,%rdx,8),%xmm0
mulsd  -0x48(%rbp),%xmm0
mov    -0x40(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x8(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    $0x1,%rcx
movsd  (%rax,%rcx,8),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mulsd  -0x48(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    119b <thomas+0x8b>
mov    -0x28(%rbp),%rax
sub    $0x2,%rax
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jl     12ff <thomas+0x1ef>
mov    -0x58(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x4c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x20(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movq   %xmm0,%rdx
movabs $0x8000000000000000,%rsi
xor    %rsi,%rdx
movq   %rdx,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x4c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4c(%rbp)
jmp    1297 <thomas+0x187>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thomas>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r15
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,-0x38(%rbp)
mov    %rsp,%r14
mov    %r14,-0x40(%rbp)
lea    0xf(,%r8,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
neg    %rax
mov    %rax,-0x30(%rbp)
lea    0x0(,%r8,8),%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x38(%rbp),%rcx
movsd  (%rbx),%xmm1
movhpd (%r12),%xmm1
movsd  0x0(%r13),%xmm0
unpcklpd %xmm0,%xmm0
divpd  %xmm0,%xmm1
mov    -0x40(%rbp),%rax
mov    -0x30(%rbp),%rdx
movhpd %xmm1,(%rax,%rdx,1)
movlpd %xmm1,(%rbx)
cmp    $0x2,%r15
jb     1203 <thomas+0xf3>
mov    $0x1,%eax
movsd  0xe5d(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  0x0(%r13,%rax,8),%xmm2
movsd  (%rcx,%rax,8),%xmm3
movapd %xmm1,%xmm4
unpckhpd %xmm1,%xmm4
mulsd  %xmm3,%xmm4
subsd  %xmm4,%xmm2
movapd %xmm0,%xmm4
divsd  %xmm2,%xmm4
mulsd  %xmm1,%xmm3
movsd  (%rbx,%rax,8),%xmm1
subsd  %xmm3,%xmm1
unpcklpd %xmm4,%xmm4
movhpd (%r12,%rax,8),%xmm1
mulpd  %xmm4,%xmm1
movhpd %xmm1,(%r14,%rax,8)
movlpd %xmm1,(%rbx,%rax,8)
add    $0x1,%rax
cmp    %rax,%r15
jne    11b0 <thomas+0xa0>
add    $0xfffffffe,%r15d
js     127b <thomas+0x16b>
mov    %r15d,%eax
test   $0x1,%r15b
jne    1230 <thomas+0x120>
movsd  (%r14,%rax,8),%xmm0
mulsd  0x8(%rbx,%rax,8),%xmm0
movsd  (%rbx,%rax,8),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rax,8)
add    $0xffffffffffffffff,%rax
test   %r15d,%r15d
je     127b <thomas+0x16b>
cs nopw 0x0(%rax,%rax,1)
nop
movsd  (%r14,%rax,8),%xmm0
movsd  -0x8(%rbx,%rax,8),%xmm1
movsd  (%rbx,%rax,8),%xmm2
mulsd  0x8(%rbx,%rax,8),%xmm0
subsd  %xmm0,%xmm2
movsd  %xmm2,(%rbx,%rax,8)
mulsd  -0x8(%r14,%rax,8),%xmm2
subsd  %xmm2,%xmm1
movsd  %xmm1,-0x8(%rbx,%rax,8)
add    $0xfffffffffffffffe,%rax
cmp    $0xffffffffffffffff,%rax
jne    1240 <thomas+0x130>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @thomas(double* nocapture %0, double* nocapture %1, double* nocapture %2, double* nocapture %3, i64 %4) {
%6 = alloca double, i64 %4
%7 = shl i64 %4, 3
%8 = call i32 @memset(double* %6, i32 0, i64 %7)
%9 = load double, double* %2
%10 = load double, double* %1
%11 = load double, double* %3
%12 = insertelement <2 x double> poison, double %11, i64 0
%13 = insertelement <2 x double> %12, double %9, i64 1
%14 = insertelement <2 x double> poison, double %10, i64 0
%15 = shufflevector <2 x double> %14, <2 x double> poison, <2 x i32> zeroinitializer
%16 = fdiv <2 x double> %13, %15
%17 = extractelement <2 x double> %16, i64 1
store double %17, double* %6
%18 = extractelement <2 x double> %16, i64 0
store double %18, double* %3
%19 = icmp ugt i64 %4, 1
br i1 %19, label %42, label %20
20: ; preds = %42, %5
%21 = trunc i64 %4 to i32
%22 = add i32 %21, -2
%23 = icmp sgt i32 %22, -1
br i1 %23, label %24, label %69
24: ; preds = %20
%25 = zext i32 %22 to i64
%26 = and i64 %25, 1
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %24
%29 = getelementptr inbounds double, double* %6, i64 %25
%30 = load double, double* %29
%31 = add nuw nsw i64 %25, 1
%32 = getelementptr inbounds double, double* %3, i64 %31
%33 = load double, double* %32
%34 = getelementptr inbounds double, double* %3, i64 %25
%35 = load double, double* %34
%36 = fneg double %30
%37 = call double @llvm.fmuladd.f64(double %36, double %33, double %35)
store double %37, double* %34
%38 = add nsw i64 %25, -1
br label %39
39: ; preds = %28, %24
%40 = phi i64 [ %25, %24 ], [ %38, %28 ]
%41 = icmp eq i32 %22, 0
br i1 %41, label %69, label %70
42: ; preds = %5, %42
%43 = phi i64 [ %67, %42 ], [ 1, %5 ]
%44 = phi <2 x double> [ %64, %42 ], [ %16, %5 ]
%45 = getelementptr inbounds double, double* %1, i64 %43
%46 = load double, double* %45
%47 = getelementptr inbounds double, double* %0, i64 %43
%48 = load double, double* %47
%49 = fneg double %48
%50 = extractelement <2 x double> %44, i64 1
%51 = call double @llvm.fmuladd.f64(double %49, double %50, double %46)
%52 = fdiv double 1.000000e+00, %51
%53 = getelementptr inbounds double, double* %2, i64 %43
%54 = load double, double* %53
%55 = getelementptr inbounds double, double* %6, i64 %43
%56 = getelementptr inbounds double, double* %3, i64 %43
%57 = load double, double* %56
%58 = extractelement <2 x double> %44, i64 0
%59 = call double @llvm.fmuladd.f64(double %49, double %58, double %57)
%60 = insertelement <2 x double> poison, double %52, i64 0
%61 = shufflevector <2 x double> %60, <2 x double> poison, <2 x i32> zeroinitializer
%62 = insertelement <2 x double> poison, double %59, i64 0
%63 = insertelement <2 x double> %62, double %54, i64 1
%64 = fmul <2 x double> %61, %63
%65 = extractelement <2 x double> %64, i64 1
store double %65, double* %55
%66 = extractelement <2 x double> %64, i64 0
store double %66, double* %56
%67 = add nuw i64 %43, 1
%68 = icmp eq i64 %67, %4
br i1 %68, label %20, label %42
69: ; preds = %39, %70, %20
ret void
70: ; preds = %39, %70
%71 = phi i64 [ %88, %70 ], [ %40, %39 ]
%72 = getelementptr inbounds double, double* %6, i64 %71
%73 = load double, double* %72
%74 = add nuw nsw i64 %71, 1
%75 = getelementptr inbounds double, double* %3, i64 %74
%76 = load double, double* %75
%77 = getelementptr inbounds double, double* %3, i64 %71
%78 = load double, double* %77
%79 = fneg double %73
%80 = call double @llvm.fmuladd.f64(double %79, double %76, double %78)
store double %80, double* %77
%81 = add nsw i64 %71, -1
%82 = getelementptr inbounds double, double* %6, i64 %81
%83 = load double, double* %82
%84 = getelementptr inbounds double, double* %3, i64 %81
%85 = load double, double* %84
%86 = fneg double %83
%87 = call double @llvm.fmuladd.f64(double %86, double %80, double %85)
store double %87, double* %84
%88 = add nsw i64 %71, -2
%89 = icmp eq i64 %81, 0
br i1 %89, label %69, label %70
}