; LLVM IR from jgaeddert/liquid-dsp :: src/matrix/src (matrixc)

; 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"

@.str.20 = external hidden unnamed_addr constant [89 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [36 x i8], align 1

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

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

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

declare { double, double } @__muldc3(double, double, double, double)

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @matrixc_ludecomp_doolittle(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local { double, double } @matrixc_det2x2(ptr noundef, i32 noundef, i32 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local { double, double } @matrixc_det(ptr noundef %0, i32 noundef %1, i32 noundef %2) #3 {
  %4 = alloca { double, double }, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca { double, double }, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = icmp ne i32 %16, %17
  br i1 %18, label %19, label %24

19:                                               ; preds = %3
  %20 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 5, ptr noundef @.str.20, i32 noundef 192, ptr noundef @.str.24)
  %21 = sitofp i32 %20 to double
  %22 = getelementptr inbounds { double, double }, ptr %4, i32 0, i32 0
  %23 = getelementptr inbounds { double, double }, ptr %4, i32 0, i32 1
  store double %21, ptr %22, align 8
  store double 0.000000e+00, ptr %23, align 8
  br label %108

24:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %25 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %25, ptr %8, align 4, !tbaa !9
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = icmp eq i32 %26, 2
  br i1 %27, label %28, label %35

28:                                               ; preds = %24
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = call { double, double } @matrixc_det2x2(ptr noundef %29, i32 noundef 2, i32 noundef 2)
  %31 = extractvalue { double, double } %30, 0
  %32 = extractvalue { double, double } %30, 1
  %33 = getelementptr inbounds { double, double }, ptr %4, i32 0, i32 0
  %34 = getelementptr inbounds { double, double }, ptr %4, i32 0, i32 1
  store double %31, ptr %33, align 8
  store double %32, ptr %34, align 8
  store i32 1, ptr %9, align 4
  br label %107

35:                                               ; preds = %24
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = mul i32 %36, %37
  %39 = zext i32 %38 to i64
  %40 = call ptr @llvm.stacksave.p0()
  store ptr %40, ptr %10, align 8
  %41 = alloca { double, double }, i64 %39, align 16
  store i64 %39, ptr %11, align 8
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = mul i32 %42, %43
  %45 = zext i32 %44 to i64
  %46 = alloca { double, double }, i64 %45, align 16
  store i64 %45, ptr %12, align 8
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = mul i32 %47, %48
  %50 = zext i32 %49 to i64
  %51 = alloca { double, double }, i64 %50, align 16
  store i64 %50, ptr %13, align 8
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = call i32 @matrixc_ludecomp_doolittle(ptr noundef %52, i32 noundef %53, i32 noundef %54, ptr noundef %41, ptr noundef %46, ptr noundef %51)
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #4
  %56 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  %57 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  store double 1.000000e+00, ptr %56, align 8
  store double 0.000000e+00, ptr %57, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %96, %35
  %59 = load i32, ptr %15, align 4, !tbaa !9
  %60 = load i32, ptr %8, align 4, !tbaa !9
  %61 = icmp ult i32 %59, %60
  br i1 %61, label %62, label %99

62:                                               ; preds = %58
  %63 = load i32, ptr %15, align 4, !tbaa !9
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = mul i32 %63, %64
  %66 = load i32, ptr %15, align 4, !tbaa !9
  %67 = add i32 %65, %66
  %68 = zext i32 %67 to i64
  %69 = getelementptr inbounds { double, double }, ptr %46, i64 %68
  %70 = getelementptr inbounds { double, double }, ptr %69, i32 0, i32 0
  %71 = load double, ptr %70, align 16
  %72 = getelementptr inbounds { double, double }, ptr %69, i32 0, i32 1
  %73 = load double, ptr %72, align 8
  %74 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  %75 = load double, ptr %74, align 8
  %76 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  %77 = load double, ptr %76, align 8
  %78 = fmul double %75, %71
  %79 = fmul double %77, %73
  %80 = fmul double %75, %73
  %81 = fmul double %77, %71
  %82 = fsub double %78, %79
  %83 = fadd double %80, %81
  %84 = fcmp uno double %82, %82
  br i1 %84, label %85, label %91, !prof !11

85:                                               ; preds = %62
  %86 = fcmp uno double %83, %83
  br i1 %86, label %87, label %91, !prof !11

87:                                               ; preds = %85
  %88 = call { double, double } @__muldc3(double noundef %75, double noundef %77, double noundef %71, double noundef %73) #4
  %89 = extractvalue { double, double } %88, 0
  %90 = extractvalue { double, double } %88, 1
  br label %91

91:                                               ; preds = %87, %85, %62
  %92 = phi double [ %82, %62 ], [ %82, %85 ], [ %89, %87 ]
  %93 = phi double [ %83, %62 ], [ %83, %85 ], [ %90, %87 ]
  %94 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  %95 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  store double %92, ptr %94, align 8
  store double %93, ptr %95, align 8
  br label %96

96:                                               ; preds = %91
  %97 = load i32, ptr %15, align 4, !tbaa !9
  %98 = add i32 %97, 1
  store i32 %98, ptr %15, align 4, !tbaa !9
  br label %58, !llvm.loop !12

99:                                               ; preds = %58
  %100 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  %101 = load double, ptr %100, align 8
  %102 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  %103 = load double, ptr %102, align 8
  %104 = getelementptr inbounds { double, double }, ptr %4, i32 0, i32 0
  %105 = getelementptr inbounds { double, double }, ptr %4, i32 0, i32 1
  store double %101, ptr %104, align 8
  store double %103, ptr %105, align 8
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #4
  %106 = load ptr, ptr %10, align 8
  call void @llvm.stackrestore.p0(ptr %106)
  br label %107

107:                                              ; preds = %99, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %108

108:                                              ; preds = %107, %19
  %109 = load { double, double }, ptr %4, align 8
  ret { double, double } %109
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #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 #2 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { 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 #4 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!"branch_weights", i32 1, i32 1048575}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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"

@.str.20 = external hidden unnamed_addr constant [89 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [36 x i8], align 1

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

declare { double, double } @__muldc3(double, double, double, double) local_unnamed_addr

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @matrixc_ludecomp_doolittle(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local { double, double } @matrixc_det2x2(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local { double, double } @matrixc_det(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %.not = icmp eq i32 %1, %2
  br i1 %.not, label %7, label %4

4:                                                ; preds = %3
  %5 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 5, ptr noundef nonnull @.str.20, i32 noundef 192, ptr noundef nonnull @.str.24) #3
  %6 = sitofp i32 %5 to double
  br label %45

7:                                                ; preds = %3
  %8 = icmp eq i32 %1, 2
  br i1 %8, label %9, label %13

9:                                                ; preds = %7
  %10 = tail call { double, double } @matrixc_det2x2(ptr noundef %0, i32 noundef 2, i32 noundef 2)
  %11 = extractvalue { double, double } %10, 0
  %12 = extractvalue { double, double } %10, 1
  br label %45

13:                                               ; preds = %7
  %14 = mul i32 %1, %1
  %15 = zext i32 %14 to i64
  %16 = tail call ptr @llvm.stacksave.p0()
  %17 = alloca { double, double }, i64 %15, align 16
  %18 = alloca { double, double }, i64 %15, align 16
  %19 = alloca { double, double }, i64 %15, align 16
  %20 = call i32 @matrixc_ludecomp_doolittle(ptr noundef %0, i32 noundef %1, i32 noundef %1, ptr noundef nonnull %17, ptr noundef nonnull %18, ptr noundef nonnull %19)
  %.not29 = icmp eq i32 %1, 0
  br i1 %.not29, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %13
  %.024 = add i32 %1, 1
  %wide.trip.count = zext i32 %1 to i64
  br label %21

21:                                               ; preds = %.lr.ph, %42
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %42 ]
  %.sroa.0.026 = phi double [ 1.000000e+00, %.lr.ph ], [ %43, %42 ]
  %.sroa.6.025 = phi double [ 0.000000e+00, %.lr.ph ], [ %44, %42 ]
  %22 = trunc nuw i64 %indvars.iv to i32
  %23 = mul i32 %.024, %22
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds { double, double }, ptr %18, i64 %24
  %26 = load double, ptr %25, align 16
  %27 = getelementptr inbounds i8, ptr %25, i64 8
  %28 = load double, ptr %27, align 8
  %29 = fmul double %.sroa.0.026, %26
  %30 = fmul double %.sroa.6.025, %28
  %31 = fmul double %.sroa.0.026, %28
  %32 = fmul double %.sroa.6.025, %26
  %33 = fsub double %29, %30
  %34 = fadd double %32, %31
  %35 = fcmp uno double %33, 0.000000e+00
  br i1 %35, label %36, label %42, !prof !5

36:                                               ; preds = %21
  %37 = fcmp uno double %34, 0.000000e+00
  br i1 %37, label %38, label %42, !prof !5

38:                                               ; preds = %36
  %39 = call { double, double } @__muldc3(double noundef %.sroa.0.026, double noundef %.sroa.6.025, double noundef %26, double noundef %28) #3
  %40 = extractvalue { double, double } %39, 0
  %41 = extractvalue { double, double } %39, 1
  br label %42

42:                                               ; preds = %38, %36, %21
  %43 = phi double [ %33, %21 ], [ %33, %36 ], [ %40, %38 ]
  %44 = phi double [ %34, %21 ], [ %34, %36 ], [ %41, %38 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %21, !llvm.loop !6

._crit_edge:                                      ; preds = %42, %13
  %.sroa.6.0.lcssa = phi double [ 0.000000e+00, %13 ], [ %44, %42 ]
  %.sroa.0.0.lcssa = phi double [ 1.000000e+00, %13 ], [ %43, %42 ]
  call void @llvm.stackrestore.p0(ptr %16)
  br label %45

45:                                               ; preds = %9, %._crit_edge, %4
  %.sroa.022.1 = phi double [ %6, %4 ], [ %11, %9 ], [ %.sroa.0.0.lcssa, %._crit_edge ]
  %.sroa.4.1 = phi double [ 0.000000e+00, %4 ], [ %12, %9 ], [ %.sroa.6.0.lcssa, %._crit_edge ]
  %.fca.0.insert = insertvalue { double, double } poison, double %.sroa.022.1, 0
  %.fca.1.insert = insertvalue { double, double } %.fca.0.insert, double %.sroa.4.1, 1
  ret { double, double } %.fca.1.insert
}

attributes #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 nocallback nofree nosync nounwind willreturn }
attributes #2 = { 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 #3 = { 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 = !{!"branch_weights", i32 1, i32 1048575}
!6 = distinct !{!6, !7}
!7 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass