#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 */
double __check(double *, double *, int);
double *canonical_from_hierarchical(char *, int, int, int, int, int, int,
                                    double *);
int /*<<< orphan*/ dpotrf_(char *, int *, double *, int *, int *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int chol_check(int check, int m, int mr, int ts, double **Ah, double *Rcheck) {
  if (check > 0) {
    double *R = canonical_from_hierarchical("R", m, mr, m, mr, ts, ts, Ah[0]);
    printf("calling dpotrf for residual checking...");
    fflush(0);
    int IINFO;
    dpotrf_("Lower", &m, Rcheck, &m, &IINFO);
    printf("...done (IINFO: %d)\n", IINFO);
    if (IINFO < 0) {
      perror("Error in dpotrf\n");
    }
    double norm_diff = __check(Rcheck, R, m);
    printf("norm of difference: %22.16g\n", norm_diff);
    free(Rcheck);
    int ret = (norm_diff > 0.0001) ? 1 : 0;
    return ret;
  }
  return 0;
}


x86 assembly (clang, -O0):
<chol_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    127c <chol_check+0x10c>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
mov    -0x14(%rbp),%r9d
mov    -0x14(%rbp),%r10d
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
lea    0xe4f(%rip),%rdi
mov    %r10d,(%rsp)
mov    %rax,0x8(%rsp)
call   1070 <canonical_from_hierarchical@plt>
mov    %rax,-0x30(%rbp)
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1080 <fflush@plt>
mov    -0x28(%rbp),%rdx
lea    0xe47(%rip),%rdi
lea    -0xc(%rbp),%rcx
lea    -0x34(%rbp),%r8
mov    %rcx,%rsi
call   1040 <dpotrf_@plt>
mov    -0x34(%rbp),%esi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x0,-0x34(%rbp)
jge    1222 <chol_check+0xb2>
lea    0xe30(%rip),%rdi
call   1090 <perror@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <__check@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
lea    0xe1b(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x40(%rbp),%xmm0
movsd  0xda0(%rip),%xmm1
xor    %eax,%eax
mov    $0x1,%ecx
ucomisd %xmm1,%xmm0
cmova  %ecx,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1283 <chol_check+0x113>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chol_check>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,0xc(%rsp)
test   %edi,%edi
jle    1232 <chol_check+0xc2>
mov    %r9,%rbx
mov    %r8,%rax
mov    %ecx,%r9d
lea    0xe75(%rip),%rdi
mov    %esi,%ecx
mov    %edx,%r8d
push   (%rax)
push   %r9
call   1070 <canonical_from_hierarchical@plt>
add    $0x10,%rsp
mov    %rax,%r14
lea    0xe5b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1080 <fflush@plt>
lea    0xe6e(%rip),%rdi
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %rcx,%rsi
mov    %rbx,%rdx
call   1040 <dpotrf_@plt>
mov    0x8(%rsp),%esi
lea    0xe54(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x0,0x8(%rsp)
js     123c <chol_check+0xcc>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <__check@plt>
movsd  %xmm0,0x10(%rsp)
lea    0xe50(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
movsd  0x10(%rsp),%xmm0
ucomisd 0xdd3(%rip),%xmm0
seta   %al
jmp    1234 <chol_check+0xc4>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe0a(%rip),%rdi
call   1090 <perror@plt>
jmp    11f2 <chol_check+0x82>

LLVM IR (-O0):
@.str = [2 x i8] c"R\00"
@.str.1 = [40 x i8] c"calling dpotrf for residual checking...\00"
@.str.2 = [6 x i8] c"Lower\00"
@.str.3 = [21 x i8] c"...done (IINFO: %d)\0A\00"
@.str.4 = [17 x i8] c"Error in dpotrf\0A\00"
@.str.5 = [29 x i8] c"norm of difference: %22.16g\0A\00"
define i32 @chol_check(i32 %0, i32 %1, i32 %2, i32 %3, double** %4, double* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca double**
%13 = alloca double*
%14 = alloca double*
%15 = alloca i32
%16 = alloca double
%17 = alloca i32
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store double** %4, double*** %12
store double* %5, double** %13
%18 = load i32, i32* %8
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %55
20: ; preds = %6
%21 = load i32, i32* %9
%22 = load i32, i32* %10
%23 = load i32, i32* %9
%24 = load i32, i32* %10
%25 = load i32, i32* %11
%26 = load i32, i32* %11
%27 = load double**, double*** %12
%28 = getelementptr inbounds double*, double** %27, i64 0
%29 = load double*, double** %28
%30 = call double* @canonical_from_hierarchical(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22, i32 %23, i32 %24, i32 %25, i32 %26, double* %29)
store double* %30, double** %14
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @fflush(i32 0)
%33 = load double*, double** %13
%34 = call i32 @dpotrf_(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %9, double* %33, i32* %9, i32* %15)
%35 = load i32, i32* %15
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %15
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %20
%40 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %41
41: ; preds = %39, %20
%42 = load double*, double** %13
%43 = load double*, double** %14
%44 = load i32, i32* %9
%45 = call double @__check(double* %42, double* %43, i32 %44)
store double %45, double* %16
%46 = load double, double* %16
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), double %46)
%48 = load double*, double** %13
%49 = call i32 @free(double* %48)
%50 = load double, double* %16
%51 = fcmp ogt double %50, 1.000000e-04
%52 = zext i1 %51 to i64
%53 = select i1 %51, i32 1, i32 0
store i32 %53, i32* %17
%54 = load i32, i32* %17
store i32 %54, i32* %7
br label %56
55: ; preds = %6
store i32 0, i32* %7
br label %56
56: ; preds = %55, %41
%57 = load i32, i32* %7
ret i32 %57
}

LLVM IR (-O2):
@.str = [2 x i8] c"R\00"
@.str.1 = [40 x i8] c"calling dpotrf for residual checking...\00"
@.str.2 = [6 x i8] c"Lower\00"
@.str.3 = [21 x i8] c"...done (IINFO: %d)\0A\00"
@.str.4 = [17 x i8] c"Error in dpotrf\0A\00"
@.str.5 = [29 x i8] c"norm of difference: %22.16g\0A\00"
define i32 @chol_check(i32 %0, i32 %1, i32 %2, i32 %3, double** nocapture %4, double* %5) {
%7 = alloca i32
%8 = alloca i32
store i32 %1, i32* %7
%9 = icmp sgt i32 %0, 0
br i1 %9, label %10, label %30
10: ; preds = %6
%11 = load double*, double** %4
%12 = tail call double* @canonical_from_hierarchical(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2, i32 %1, i32 %2, i32 %3, i32 %3, double* %11)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @fflush(i32 0)
%15 = bitcast i32* %8 to i8*
%16 = call i32 @dpotrf_(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %7, double* %5, i32* %7, i32* %8)
%17 = load i32, i32* %8
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %10
%22 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %23
23: ; preds = %21, %10
%24 = load i32, i32* %7
%25 = call double @__check(double* %5, double* %12, i32 %24)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), double %25)
%27 = call i32 @free(double* %5)
%28 = fcmp ogt double %25, 1.000000e-04
%29 = zext i1 %28 to i32
br label %30
30: ; preds = %6, %23
%31 = phi i32 [ %29, %23 ], [ 0, %6 ]
ret i32 %31
}