; LLVM IR from Dutta-SD/Numerical_Methods :: Linear_Algebra (Cholesky_Factorization)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local ptr @Cholesky_Decomposition(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %8 = call noalias ptr @calloc(i64 noundef 9, i64 noundef 8) #6
  store ptr %8, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %3, align 4, !tbaa !11
  br label %9

9:                                                ; preds = %107, %1
  %10 = load i32, ptr %3, align 4, !tbaa !11
  %11 = icmp slt i32 %10, 3
  br i1 %11, label %12, label %110

12:                                               ; preds = %9
  store i32 0, ptr %4, align 4, !tbaa !11
  br label %13

13:                                               ; preds = %103, %12
  %14 = load i32, ptr %4, align 4, !tbaa !11
  %15 = load i32, ptr %3, align 4, !tbaa !11
  %16 = add nsw i32 %15, 1
  %17 = icmp slt i32 %14, %16
  br i1 %17, label %18, label %106

18:                                               ; preds = %13
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %19

19:                                               ; preds = %44, %18
  %20 = load i32, ptr %5, align 4, !tbaa !11
  %21 = load i32, ptr %4, align 4, !tbaa !11
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %23, label %47

23:                                               ; preds = %19
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !11
  %26 = mul nsw i32 %25, 3
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds double, ptr %24, i64 %27
  %29 = load i32, ptr %5, align 4, !tbaa !11
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds double, ptr %28, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !11
  %35 = mul nsw i32 %34, 3
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds double, ptr %33, i64 %36
  %38 = load i32, ptr %5, align 4, !tbaa !11
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds double, ptr %37, i64 %39
  %41 = load double, ptr %40, align 8, !tbaa !9
  %42 = load double, ptr %6, align 8, !tbaa !9
  %43 = call double @llvm.fmuladd.f64(double %32, double %41, double %42)
  store double %43, ptr %6, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %23
  %45 = load i32, ptr %5, align 4, !tbaa !11
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %5, align 4, !tbaa !11
  br label %19, !llvm.loop !13

47:                                               ; preds = %19
  %48 = load i32, ptr %3, align 4, !tbaa !11
  %49 = load i32, ptr %4, align 4, !tbaa !11
  %50 = icmp eq i32 %48, %49
  br i1 %50, label %51, label %72

51:                                               ; preds = %47
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = load i32, ptr %4, align 4, !tbaa !11
  %54 = mul nsw i32 %53, 3
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds double, ptr %52, i64 %55
  %57 = load i32, ptr %4, align 4, !tbaa !11
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds double, ptr %56, i64 %58
  %60 = load double, ptr %59, align 8, !tbaa !9
  %61 = load double, ptr %6, align 8, !tbaa !9
  %62 = fsub double %60, %61
  %63 = call double @sqrt(double noundef %62) #5
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = load i32, ptr %3, align 4, !tbaa !11
  %66 = mul nsw i32 %65, 3
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds double, ptr %64, i64 %67
  %69 = load i32, ptr %4, align 4, !tbaa !11
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds double, ptr %68, i64 %70
  store double %63, ptr %71, align 8, !tbaa !9
  br label %102

72:                                               ; preds = %47
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = load i32, ptr %3, align 4, !tbaa !11
  %75 = mul nsw i32 %74, 3
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds double, ptr %73, i64 %76
  %78 = load i32, ptr %4, align 4, !tbaa !11
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds double, ptr %77, i64 %79
  %81 = load double, ptr %80, align 8, !tbaa !9
  %82 = load double, ptr %6, align 8, !tbaa !9
  %83 = fsub double %81, %82
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  %85 = load i32, ptr %4, align 4, !tbaa !11
  %86 = mul nsw i32 %85, 3
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds double, ptr %84, i64 %87
  %89 = load i32, ptr %4, align 4, !tbaa !11
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds double, ptr %88, i64 %90
  %92 = load double, ptr %91, align 8, !tbaa !9
  %93 = fdiv double %83, %92
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = load i32, ptr %3, align 4, !tbaa !11
  %96 = mul nsw i32 %95, 3
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds double, ptr %94, i64 %97
  %99 = load i32, ptr %4, align 4, !tbaa !11
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds double, ptr %98, i64 %100
  store double %93, ptr %101, align 8, !tbaa !9
  br label %102

102:                                              ; preds = %72, %51
  br label %103

103:                                              ; preds = %102
  %104 = load i32, ptr %4, align 4, !tbaa !11
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %4, align 4, !tbaa !11
  br label %13, !llvm.loop !15

106:                                              ; preds = %13
  br label %107

107:                                              ; preds = %106
  %108 = load i32, ptr %3, align 4, !tbaa !11
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %3, align 4, !tbaa !11
  br label %9, !llvm.loop !16

110:                                              ; preds = %9
  %111 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret ptr %111
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

; Function Attrs: nounwind
declare double @sqrt(double noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind allocsize(0,1) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(0,1) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: mustprogress nofree nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: readwrite) uwtable
define dso_local noalias noundef ptr @Cholesky_Decomposition(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = tail call noalias dereferenceable_or_null(72) ptr @calloc(i64 noundef 9, i64 noundef 8) #4
  %3 = load double, ptr %0, align 8, !tbaa !5
  %4 = tail call double @sqrt(double noundef %3) #5
  store double %4, ptr %2, align 8
  %5 = getelementptr inbounds i8, ptr %2, i64 24
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = fdiv double %7, %4
  store double %8, ptr %5, align 8, !tbaa !5
  %9 = tail call double @llvm.fmuladd.f64(double %8, double %8, double 0.000000e+00)
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = fsub double %11, %9
  %13 = tail call double @sqrt(double noundef %12) #5
  %14 = getelementptr inbounds i8, ptr %2, i64 32
  store double %13, ptr %14, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %2, i64 48
  %16 = getelementptr inbounds i8, ptr %0, i64 48
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = fdiv double %17, %4
  store double %18, ptr %15, align 8, !tbaa !5
  %19 = tail call double @llvm.fmuladd.f64(double %18, double %8, double 0.000000e+00)
  %20 = getelementptr inbounds i8, ptr %0, i64 56
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = fsub double %21, %19
  %23 = fdiv double %22, %13
  %24 = getelementptr inbounds i8, ptr %2, i64 56
  store double %23, ptr %24, align 8, !tbaa !5
  %25 = tail call double @llvm.fmuladd.f64(double %18, double %18, double 0.000000e+00)
  %26 = tail call double @llvm.fmuladd.f64(double %23, double %23, double %25)
  %27 = getelementptr inbounds i8, ptr %0, i64 64
  %28 = load double, ptr %27, align 8, !tbaa !5
  %29 = fsub double %28, %26
  %30 = tail call double @sqrt(double noundef %29) #5
  %31 = getelementptr inbounds i8, ptr %2, i64 64
  store double %30, ptr %31, align 8, !tbaa !5
  ret ptr %2
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nofree nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: readwrite) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { mustprogress nofree nounwind willreturn memory(write) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind allocsize(0,1) }
attributes #5 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass