; 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.10 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [33 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @matrix_pivot(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #3 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca double, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load i32, ptr %10, align 4, !tbaa !9
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = mul i32 %18, %19
  %21 = load i32, ptr %11, align 4, !tbaa !9
  %22 = add i32 %20, %21
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds double, ptr %17, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !11
  store double %25, ptr %12, align 8, !tbaa !11
  %26 = load double, ptr %12, align 8, !tbaa !11
  %27 = fcmp oeq double %26, 0.000000e+00
  br i1 %27, label %28, label %30

28:                                               ; preds = %5
  %29 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef @.str.10, i32 noundef 129, ptr noundef @.str.13)
  store i32 %29, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %94

30:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %90, %30
  %32 = load i32, ptr %14, align 4, !tbaa !9
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = icmp ult i32 %32, %33
  br i1 %34, label %35, label %93

35:                                               ; preds = %31
  %36 = load i32, ptr %14, align 4, !tbaa !9
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = icmp eq i32 %36, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %35
  br label %90

40:                                               ; preds = %35
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load i32, ptr %14, align 4, !tbaa !9
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = mul i32 %42, %43
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = add i32 %44, %45
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds double, ptr %41, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = load double, ptr %12, align 8, !tbaa !11
  %51 = fdiv double %49, %50
  store double %51, ptr %16, align 8, !tbaa !11
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %86, %40
  %53 = load i32, ptr %15, align 4, !tbaa !9
  %54 = load i32, ptr %9, align 4, !tbaa !9
  %55 = icmp ult i32 %53, %54
  br i1 %55, label %56, label %89

56:                                               ; preds = %52
  %57 = load double, ptr %16, align 8, !tbaa !11
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load i32, ptr %10, align 4, !tbaa !9
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = mul i32 %59, %60
  %62 = load i32, ptr %15, align 4, !tbaa !9
  %63 = add i32 %61, %62
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds double, ptr %58, i64 %64
  %66 = load double, ptr %65, align 8, !tbaa !11
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = load i32, ptr %14, align 4, !tbaa !9
  %69 = load i32, ptr %9, align 4, !tbaa !9
  %70 = mul i32 %68, %69
  %71 = load i32, ptr %15, align 4, !tbaa !9
  %72 = add i32 %70, %71
  %73 = zext i32 %72 to i64
  %74 = getelementptr inbounds double, ptr %67, i64 %73
  %75 = load double, ptr %74, align 8, !tbaa !11
  %76 = fneg double %75
  %77 = call double @llvm.fmuladd.f64(double %57, double %66, double %76)
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = load i32, ptr %14, align 4, !tbaa !9
  %80 = load i32, ptr %9, align 4, !tbaa !9
  %81 = mul i32 %79, %80
  %82 = load i32, ptr %15, align 4, !tbaa !9
  %83 = add i32 %81, %82
  %84 = zext i32 %83 to i64
  %85 = getelementptr inbounds double, ptr %78, i64 %84
  store double %77, ptr %85, align 8, !tbaa !11
  br label %86

86:                                               ; preds = %56
  %87 = load i32, ptr %15, align 4, !tbaa !9
  %88 = add i32 %87, 1
  store i32 %88, ptr %15, align 4, !tbaa !9
  br label %52, !llvm.loop !13

89:                                               ; preds = %52
  br label %90

90:                                               ; preds = %89, %39
  %91 = load i32, ptr %14, align 4, !tbaa !9
  %92 = add i32 %91, 1
  store i32 %92, ptr %14, align 4, !tbaa !9
  br label %31, !llvm.loop !15

93:                                               ; preds = %31
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %94

94:                                               ; preds = %93, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %95 = load i32, ptr %6, align 4
  ret i32 %95
}

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 speculatable willreturn memory(none) }
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"}
!15 = distinct !{!15, !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"

@.str.10 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [33 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @matrix_pivot(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = mul i32 %3, %2
  %7 = add i32 %6, %4
  %8 = zext i32 %7 to i64
  %9 = getelementptr inbounds double, ptr %0, i64 %8
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = fcmp oeq double %10, 0.000000e+00
  br i1 %11, label %91, label %.preheader

.preheader:                                       ; preds = %5
  %.not = icmp eq i32 %1, 0
  %.not38 = icmp eq i32 %2, 0
  %or.cond = or i1 %.not, %.not38
  br i1 %or.cond, label %.loopexit34, label %.lr.ph37.split.us.preheader

.lr.ph37.split.us.preheader:                      ; preds = %.preheader
  %12 = zext i32 %3 to i64
  %wide.trip.count44 = zext i32 %1 to i64
  %wide.trip.count = zext i32 %2 to i64
  %13 = add nsw i64 %wide.trip.count, -1
  %14 = shl nuw nsw i64 %wide.trip.count, 3
  %scevgep46 = getelementptr i8, ptr %0, i64 %14
  %15 = zext i32 %6 to i64
  %16 = shl nuw nsw i64 %15, 3
  %scevgep48 = getelementptr i8, ptr %0, i64 %16
  %17 = getelementptr i8, ptr %0, i64 %14
  %scevgep49 = getelementptr i8, ptr %17, i64 %16
  %min.iters.check = icmp ult i32 %2, 10
  %18 = trunc i64 %13 to i32
  %19 = trunc i64 %13 to i32
  %20 = xor i32 %6, -1
  %21 = icmp ult i32 %20, %19
  %22 = icmp ugt i64 %13, 4294967295
  %23 = or i1 %21, %22
  %n.vec = and i64 %wide.trip.count, 4294967292
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  %xtraiter = and i64 %wide.trip.count, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  %24 = add nsw i64 %wide.trip.count, -1
  br label %.lr.ph37.split.us

.lr.ph37.split.us:                                ; preds = %.lr.ph37.split.us.preheader, %..loopexit_crit_edge.us
  %indvars.iv41 = phi i64 [ 0, %.lr.ph37.split.us.preheader ], [ %indvars.iv.next42, %..loopexit_crit_edge.us ]
  %25 = trunc i64 %indvars.iv41 to i32
  %26 = mul i32 %25, %2
  %27 = zext i32 %26 to i64
  %28 = shl nuw nsw i64 %27, 3
  %scevgep = getelementptr i8, ptr %0, i64 %28
  %scevgep47 = getelementptr i8, ptr %scevgep46, i64 %28
  %29 = trunc i64 %indvars.iv41 to i32
  %30 = mul i32 %29, %2
  %31 = icmp eq i64 %indvars.iv41, %12
  br i1 %31, label %..loopexit_crit_edge.us, label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph37.split.us
  %32 = trunc nuw i64 %indvars.iv41 to i32
  %33 = mul i32 %32, %2
  %34 = add i32 %33, %4
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds double, ptr %0, i64 %35
  %37 = load double, ptr %36, align 8, !tbaa !5
  %38 = fdiv double %37, %10
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %.lr.ph.us
  %39 = xor i32 %30, -1
  %40 = icmp ult i32 %39, %18
  %41 = or i1 %40, %23
  br i1 %41, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %vector.scevcheck
  %bound0 = icmp ult ptr %scevgep, %scevgep49
  %bound1 = icmp ult ptr %scevgep48, %scevgep47
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %broadcast.splatinsert = insertelement <2 x double> poison, double %38, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %42 = trunc i64 %index to i32
  %43 = add i32 %6, %42
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds double, ptr %0, i64 %44
  %46 = getelementptr inbounds i8, ptr %45, i64 16
  %wide.load = load <2 x double>, ptr %45, align 8, !tbaa !5, !alias.scope !9
  %wide.load50 = load <2 x double>, ptr %46, align 8, !tbaa !5, !alias.scope !9
  %47 = add i32 %33, %42
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds double, ptr %0, i64 %48
  %50 = getelementptr inbounds i8, ptr %49, i64 16
  %wide.load51 = load <2 x double>, ptr %49, align 8, !tbaa !5, !alias.scope !12, !noalias !9
  %wide.load52 = load <2 x double>, ptr %50, align 8, !tbaa !5, !alias.scope !12, !noalias !9
  %51 = fneg <2 x double> %wide.load51
  %52 = fneg <2 x double> %wide.load52
  %53 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat, <2 x double> %wide.load, <2 x double> %51)
  %54 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat, <2 x double> %wide.load50, <2 x double> %52)
  store <2 x double> %53, ptr %49, align 8, !tbaa !5, !alias.scope !12, !noalias !9
  store <2 x double> %54, ptr %50, align 8, !tbaa !5, !alias.scope !12, !noalias !9
  %index.next = add nuw i64 %index, 4
  %55 = icmp eq i64 %index.next, %n.vec
  br i1 %55, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %..loopexit_crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %vector.scevcheck, %.lr.ph.us
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %vector.scevcheck ], [ 0, %.lr.ph.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %56 = trunc nuw i64 %indvars.iv.ph to i32
  %57 = add i32 %6, %56
  %58 = zext i32 %57 to i64
  %59 = getelementptr inbounds double, ptr %0, i64 %58
  %60 = load double, ptr %59, align 8, !tbaa !5
  %61 = add i32 %33, %56
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds double, ptr %0, i64 %62
  %64 = load double, ptr %63, align 8, !tbaa !5
  %65 = fneg double %64
  %66 = tail call double @llvm.fmuladd.f64(double %38, double %60, double %65)
  store double %66, ptr %63, align 8, !tbaa !5
  %indvars.iv.next.prol = or disjoint i64 %indvars.iv.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %67 = icmp eq i64 %indvars.iv.ph, %24
  br i1 %67, label %..loopexit_crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %68 = trunc nuw i64 %indvars.iv to i32
  %69 = add i32 %6, %68
  %70 = zext i32 %69 to i64
  %71 = getelementptr inbounds double, ptr %0, i64 %70
  %72 = load double, ptr %71, align 8, !tbaa !5
  %73 = add i32 %33, %68
  %74 = zext i32 %73 to i64
  %75 = getelementptr inbounds double, ptr %0, i64 %74
  %76 = load double, ptr %75, align 8, !tbaa !5
  %77 = fneg double %76
  %78 = tail call double @llvm.fmuladd.f64(double %38, double %72, double %77)
  store double %78, ptr %75, align 8, !tbaa !5
  %79 = trunc i64 %indvars.iv to i32
  %80 = add i32 %79, 1
  %81 = add i32 %6, %80
  %82 = zext i32 %81 to i64
  %83 = getelementptr inbounds double, ptr %0, i64 %82
  %84 = load double, ptr %83, align 8, !tbaa !5
  %85 = add i32 %33, %80
  %86 = zext i32 %85 to i64
  %87 = getelementptr inbounds double, ptr %0, i64 %86
  %88 = load double, ptr %87, align 8, !tbaa !5
  %89 = fneg double %88
  %90 = tail call double @llvm.fmuladd.f64(double %38, double %84, double %89)
  store double %90, ptr %87, align 8, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %wide.trip.count
  br i1 %exitcond.not.1, label %..loopexit_crit_edge.us, label %scalar.ph, !llvm.loop !18

..loopexit_crit_edge.us:                          ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %.lr.ph37.split.us
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
  %exitcond45.not = icmp eq i64 %indvars.iv.next42, %wide.trip.count44
  br i1 %exitcond45.not, label %.loopexit34, label %.lr.ph37.split.us, !llvm.loop !19

91:                                               ; preds = %5
  %92 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef nonnull @.str.10, i32 noundef 129, ptr noundef nonnull @.str.13) #4
  br label %.loopexit34

.loopexit34:                                      ; preds = %..loopexit_crit_edge.us, %.preheader, %91
  %.0 = phi i32 [ %92, %91 ], [ 0, %.preheader ], [ 0, %..loopexit_crit_edge.us ]
  ret i32 %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #3

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 speculatable willreturn memory(none) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !15, !16}
!19 = distinct !{!19, !15}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass