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

; 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.19 = external hidden unnamed_addr constant [89 x i8], align 1
@.str.23 = 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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local double @matrix_det(ptr noundef %0, i32 noundef %1, i32 noundef %2) #3 {
  %4 = alloca 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, 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 %22

19:                                               ; preds = %3
  %20 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 5, ptr noundef @.str.19, i32 noundef 192, ptr noundef @.str.23)
  %21 = sitofp i32 %20 to double
  store double %21, ptr %4, align 8
  br label %72

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

26:                                               ; preds = %22
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = call double @matrix_det2x2(ptr noundef %27, i32 noundef 2, i32 noundef 2)
  store double %28, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %71

29:                                               ; preds = %22
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = mul i32 %30, %31
  %33 = zext i32 %32 to i64
  %34 = call ptr @llvm.stacksave.p0()
  store ptr %34, ptr %10, align 8
  %35 = alloca double, i64 %33, align 16
  store i64 %33, ptr %11, align 8
  %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 = alloca double, i64 %39, align 16
  store i64 %39, ptr %12, align 8
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = mul i32 %41, %42
  %44 = zext i32 %43 to i64
  %45 = alloca double, i64 %44, align 16
  store i64 %44, ptr %13, align 8
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = call i32 @matrix_ludecomp_doolittle(ptr noundef %46, i32 noundef %47, i32 noundef %48, ptr noundef %35, ptr noundef %40, ptr noundef %45)
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store double 1.000000e+00, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %65, %29
  %51 = load i32, ptr %15, align 4, !tbaa !9
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = icmp ult i32 %51, %52
  br i1 %53, label %54, label %68

54:                                               ; preds = %50
  %55 = load i32, ptr %15, align 4, !tbaa !9
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = mul i32 %55, %56
  %58 = load i32, ptr %15, align 4, !tbaa !9
  %59 = add i32 %57, %58
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds double, ptr %40, i64 %60
  %62 = load double, ptr %61, align 8, !tbaa !11
  %63 = load double, ptr %14, align 8, !tbaa !11
  %64 = fmul double %63, %62
  store double %64, ptr %14, align 8, !tbaa !11
  br label %65

65:                                               ; preds = %54
  %66 = load i32, ptr %15, align 4, !tbaa !9
  %67 = add i32 %66, 1
  store i32 %67, ptr %15, align 4, !tbaa !9
  br label %50, !llvm.loop !13

68:                                               ; preds = %50
  %69 = load double, ptr %14, align 8, !tbaa !11
  store double %69, ptr %4, 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 8, ptr %14) #4
  %70 = load ptr, ptr %10, align 8
  call void @llvm.stackrestore.p0(ptr %70)
  br label %71

71:                                               ; preds = %68, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %72

72:                                               ; preds = %71, %19
  %73 = load double, ptr %4, align 8
  ret double %73
}

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 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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.19 = external hidden unnamed_addr constant [89 x i8], align 1
@.str.23 = 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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @matrix_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 @matrix_det2x2(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local double @matrix_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.19, i32 noundef 192, ptr noundef nonnull @.str.23) #3
  %6 = sitofp i32 %5 to double
  br label %54

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

9:                                                ; preds = %7
  %10 = tail call double @matrix_det2x2(ptr noundef %0, i32 noundef 2, i32 noundef 2)
  br label %54

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

.lr.ph:                                           ; preds = %11
  %.026 = add i32 %1, 1
  %wide.trip.count = zext i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %19 = icmp ult i32 %1, 4
  br i1 %19, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 4294967292
  br label %20

20:                                               ; preds = %20, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %20 ]
  %.02327 = phi double [ 1.000000e+00, %.lr.ph.new ], [ %47, %20 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %20 ]
  %21 = trunc nuw i64 %indvars.iv to i32
  %22 = mul i32 %.026, %21
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds double, ptr %16, i64 %23
  %25 = load double, ptr %24, align 16, !tbaa !5
  %26 = fmul double %.02327, %25
  %27 = trunc i64 %indvars.iv to i32
  %28 = or disjoint i32 %27, 1
  %29 = mul i32 %.026, %28
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds double, ptr %16, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !5
  %33 = fmul double %26, %32
  %34 = trunc i64 %indvars.iv to i32
  %35 = or disjoint i32 %34, 2
  %36 = mul i32 %.026, %35
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds double, ptr %16, i64 %37
  %39 = load double, ptr %38, align 16, !tbaa !5
  %40 = fmul double %33, %39
  %41 = trunc i64 %indvars.iv to i32
  %42 = or disjoint i32 %41, 3
  %43 = mul i32 %.026, %42
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds double, ptr %16, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !5
  %47 = fmul double %40, %46
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %20, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %20, %.lr.ph
  %.lcssa.ph = phi double [ poison, %.lr.ph ], [ %47, %20 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %20 ]
  %.02327.unr = phi double [ 1.000000e+00, %.lr.ph ], [ %47, %20 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.02327.epil = phi double [ %53, %.epil.preheader ], [ %.02327.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %48 = trunc nuw i64 %indvars.iv.epil to i32
  %49 = mul i32 %.026, %48
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds double, ptr %16, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !5
  %53 = fmul double %.02327.epil, %52
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.epil.preheader, !llvm.loop !11

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %11
  %.023.lcssa = phi double [ 1.000000e+00, %11 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %53, %.epil.preheader ]
  call void @llvm.stackrestore.p0(ptr %14)
  br label %54

54:                                               ; preds = %9, %._crit_edge, %4
  %.1 = phi double [ %6, %4 ], [ %10, %9 ], [ %.023.lcssa, %._crit_edge ]
  ret double %.1
}

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 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}


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