#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*/ dgemv_(char *, long *, long *, double *, double *, long *,
                          double *, long *, double *, double *, long *);
int /*<<< orphan*/ dscal_(long *, double *, double *, long *);
int sqrt(double);
void dmat_chol(double **a, long n) {
  long i;
  long mm;
  long nn;
  long incy = 1;
  double alpha = -1.;
  double beta = 1.;
  double da;
  for (i = 0; i < n; ++i) {
    mm = n - i;
    if (i > 0) {
      nn = i;
      dgemv_("t", &nn, &mm, &alpha, &a[i][0], &n, &a[i][0], &incy, &beta,
             &a[i][i], &n);
    }
    da = 1. / sqrt(a[i][i]);
    dscal_(&mm, &da, &a[i][i], &n);
  }
}


x86 assembly (clang, -O0):
<dmat_chol>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movq   $0x1,-0x40(%rbp)
movsd  0xeb5(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xea0(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    1270 <dmat_chol+0x140>
mov    -0x20(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
jle    1208 <dmat_chol+0xd8>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%r8
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%r14
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%r10
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
add    %rax,%r10
lea    0xe40(%rip),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x48(%rbp),%rcx
lea    -0x20(%rbp),%rax
lea    -0x40(%rbp),%rbx
lea    -0x50(%rbp),%r11
mov    %rax,%r9
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
call   1040 <dgemv_@plt>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1050 <sqrt@plt>
cvtsi2sd %eax,%xmm1
movsd  0xdd2(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    -0x30(%rbp),%rdi
lea    -0x58(%rbp),%rsi
lea    -0x20(%rbp),%rcx
call   1030 <dscal_@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    116d <dmat_chol+0x3d>
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<dmat_chol>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,0x10(%rsp)
movq   $0x1,0x28(%rsp)
movabs $0xbff0000000000000,%rax
mov    %rax,0x20(%rsp)
movabs $0x3ff0000000000000,%rax
mov    %rax,0x18(%rsp)
test   %rsi,%rsi
jle    127f <dmat_chol+0x14f>
mov    %rdi,%rbx
mov    %rsi,0x8(%rsp)
mov    (%rdi),%rax
movsd  (%rax),%xmm0
call   1050 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xe6a(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
mov    (%rbx),%rdx
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rcx
call   1030 <dscal_@plt>
mov    0x10(%rsp),%rax
cmp    $0x2,%rax
jl     127f <dmat_chol+0x14f>
mov    $0x1,%ebp
lea    0x8(%rsp),%r13
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
sub    %rbp,%rax
mov    %rax,0x8(%rsp)
mov    %rbp,0x30(%rsp)
lea    0x0(,%rbp,8),%r12
mov    (%rbx,%rbp,8),%r8
lea    (%r8,%rbp,8),%rax
sub    $0x8,%rsp
lea    0xe00(%rip),%rdi
lea    0x38(%rsp),%rsi
mov    %r13,%rdx
lea    0x28(%rsp),%rcx
mov    %r14,%r9
push   %r14
push   %rax
lea    0x30(%rsp),%rax
push   %rax
lea    0x48(%rsp),%rax
push   %rax
push   %r8
call   1040 <dgemv_@plt>
add    $0x30,%rsp
mov    (%rbx,%rbp,8),%rax
movsd  (%rax,%rbp,8),%xmm0
call   1050 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xdb1(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
add    (%rbx,%rbp,8),%r12
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
call   1030 <dscal_@plt>
add    $0x1,%rbp
mov    0x10(%rsp),%rax
cmp    %rbp,%rax
jg     11e0 <dmat_chol+0xb0>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"t\00"
define void @dmat_chol(double** %0, i64 %1) {
%3 = alloca double**
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double** %0, double*** %3
store i64 %1, i64* %4
store i64 1, i64* %8
store double -1.000000e+00, double* %9
store double 1.000000e+00, double* %10
store i64 0, i64* %5
br label %12
12: ; preds = %59, %2
%13 = load i64, i64* %5
%14 = load i64, i64* %4
%15 = icmp slt i64 %13, %14
br i1 %15, label %16, label %62
16: ; preds = %12
%17 = load i64, i64* %4
%18 = load i64, i64* %5
%19 = sub nsw i64 %17, %18
store i64 %19, i64* %6
%20 = load i64, i64* %5
%21 = icmp sgt i64 %20, 0
br i1 %21, label %22, label %41
22: ; preds = %16
%23 = load i64, i64* %5
store i64 %23, i64* %7
%24 = load double**, double*** %3
%25 = load i64, i64* %5
%26 = getelementptr inbounds double*, double** %24, i64 %25
%27 = load double*, double** %26
%28 = getelementptr inbounds double, double* %27, i64 0
%29 = load double**, double*** %3
%30 = load i64, i64* %5
%31 = getelementptr inbounds double*, double** %29, i64 %30
%32 = load double*, double** %31
%33 = getelementptr inbounds double, double* %32, i64 0
%34 = load double**, double*** %3
%35 = load i64, i64* %5
%36 = getelementptr inbounds double*, double** %34, i64 %35
%37 = load double*, double** %36
%38 = load i64, i64* %5
%39 = getelementptr inbounds double, double* %37, i64 %38
%40 = call i32 @dgemv_(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i64* %7, i64* %6, double* %9, double* %28, i64* %4, double* %33, i64* %8, double* %10, double* %39, i64* %4)
br label %41
41: ; preds = %22, %16
%42 = load double**, double*** %3
%43 = load i64, i64* %5
%44 = getelementptr inbounds double*, double** %42, i64 %43
%45 = load double*, double** %44
%46 = load i64, i64* %5
%47 = getelementptr inbounds double, double* %45, i64 %46
%48 = load double, double* %47
%49 = call i32 @sqrt(double %48)
%50 = sitofp i32 %49 to double
%51 = fdiv double 1.000000e+00, %50
store double %51, double* %11
%52 = load double**, double*** %3
%53 = load i64, i64* %5
%54 = getelementptr inbounds double*, double** %52, i64 %53
%55 = load double*, double** %54
%56 = load i64, i64* %5
%57 = getelementptr inbounds double, double* %55, i64 %56
%58 = call i32 @dscal_(i64* %6, double* %11, double* %57, i64* %4)
br label %59
59: ; preds = %41
%60 = load i64, i64* %5
%61 = add nsw i64 %60, 1
store i64 %61, i64* %5
br label %12
62: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"t\00"
define void @dmat_chol(double** nocapture %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca double
%8 = alloca double
%9 = alloca double
store i64 %1, i64* %3
%10 = bitcast i64* %4 to i8*
%11 = bitcast i64* %5 to i8*
%12 = bitcast i64* %6 to i8*
store i64 1, i64* %6
%13 = bitcast double* %7 to i8*
store double -1.000000e+00, double* %7
%14 = bitcast double* %8 to i8*
store double 1.000000e+00, double* %8
%15 = bitcast double* %9 to i8*
%16 = icmp sgt i64 %1, 0
br i1 %16, label %17, label %48
17: ; preds = %2
store i64 %1, i64* %4
%18 = load double*, double** %0
%19 = load double, double* %18
%20 = call i32 @sqrt(double %19)
%21 = sitofp i32 %20 to double
%22 = fdiv double 1.000000e+00, %21
store double %22, double* %9
%23 = load double*, double** %0
%24 = call i32 @dscal_(i64* %4, double* %9, double* %23, i64* %3)
%25 = load i64, i64* %3
%26 = icmp sgt i64 %25, 1
br i1 %26, label %27, label %48
27: ; preds = %17, %27
%28 = phi i64 [ %46, %27 ], [ %25, %17 ]
%29 = phi i64 [ %45, %27 ], [ 1, %17 ]
%30 = sub nsw i64 %28, %29
store i64 %30, i64* %4
store i64 %29, i64* %5
%31 = getelementptr inbounds double*, double** %0, i64 %29
%32 = load double*, double** %31
%33 = getelementptr inbounds double, double* %32, i64 %29
%34 = call i32 @dgemv_(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i64* %5, i64* %4, double* %7, double* %32, i64* %3, double* %32, i64* %6, double* %8, double* %33, i64* %3)
%35 = getelementptr inbounds double*, double** %0, i64 %29
%36 = load double*, double** %35
%37 = getelementptr inbounds double, double* %36, i64 %29
%38 = load double, double* %37
%39 = call i32 @sqrt(double %38)
%40 = sitofp i32 %39 to double
%41 = fdiv double 1.000000e+00, %40
store double %41, double* %9
%42 = load double*, double** %35
%43 = getelementptr inbounds double, double* %42, i64 %29
%44 = call i32 @dscal_(i64* %4, double* %9, double* %43, i64* %3)
%45 = add nuw nsw i64 %29, 1
%46 = load i64, i64* %3
%47 = icmp sgt i64 %46, %45
br i1 %47, label %27, label %48
48: ; preds = %27, %17, %2
ret void
}