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

; 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: nounwind uwtable
define dso_local void @matrixf_inv_bench(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  %12 = load i32, ptr %8, align 4, !tbaa !9
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = mul i32 %12, %13
  %15 = zext i32 %14 to i64
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = udiv i64 %17, %15
  store i64 %18, ptr %16, align 8, !tbaa !11
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = icmp ult i64 %20, 1
  br i1 %21, label %22, label %24

22:                                               ; preds = %4
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 1, ptr %23, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %22, %4
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = mul i32 %25, %26
  %28 = zext i32 %27 to i64
  %29 = call ptr @llvm.stacksave.p0()
  store ptr %29, ptr %9, align 8
  %30 = alloca float, i64 %28, align 16
  store i64 %28, ptr %10, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %42, %24
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = mul i32 %33, %34
  %36 = icmp ult i32 %32, %35
  br i1 %36, label %37, label %45

37:                                               ; preds = %31
  %38 = call float (...) @randnf()
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds float, ptr %30, i64 %40
  store float %38, ptr %41, align 4, !tbaa !13
  br label %42

42:                                               ; preds = %37
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = add i32 %43, 1
  store i32 %44, ptr %11, align 4, !tbaa !9
  br label %31, !llvm.loop !15

45:                                               ; preds = %31
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = call i32 @getrusage(i32 noundef 0, ptr noundef %46) #5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %67, %45
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = zext i32 %49 to i64
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load i64, ptr %51, align 8, !tbaa !11
  %53 = icmp ult i64 %50, %52
  br i1 %53, label %54, label %70

54:                                               ; preds = %48
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = call i32 @matrixf_inv(ptr noundef %30, i32 noundef %55, i32 noundef %56)
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = call i32 @matrixf_inv(ptr noundef %30, i32 noundef %58, i32 noundef %59)
  %61 = load i32, ptr %8, align 4, !tbaa !9
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = call i32 @matrixf_inv(ptr noundef %30, i32 noundef %61, i32 noundef %62)
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = load i32, ptr %8, align 4, !tbaa !9
  %66 = call i32 @matrixf_inv(ptr noundef %30, i32 noundef %64, i32 noundef %65)
  br label %67

67:                                               ; preds = %54
  %68 = load i32, ptr %11, align 4, !tbaa !9
  %69 = add i32 %68, 1
  store i32 %69, ptr %11, align 4, !tbaa !9
  br label %48, !llvm.loop !17

70:                                               ; preds = %48
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = call i32 @getrusage(i32 noundef 0, ptr noundef %71) #5
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = load i64, ptr %73, align 8, !tbaa !11
  %75 = mul i64 %74, 4
  store i64 %75, ptr %73, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  %76 = load ptr, ptr %9, align 8
  call void @llvm.stackrestore.p0(ptr %76)
  ret void
}

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

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

declare float @randnf(...) #3

; Function Attrs: nounwind
declare i32 @getrusage(i32 noundef, ptr noundef) #4

declare i32 @matrixf_inv(ptr noundef, i32 noundef, i32 noundef) #3

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 "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 }

!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 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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: nounwind uwtable
define dso_local void @matrixf_inv_bench(ptr noundef %0, ptr noundef %1, ptr nocapture noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = mul i32 %3, %3
  %6 = zext i32 %5 to i64
  %7 = load i64, ptr %2, align 8, !tbaa !5
  %8 = udiv i64 %7, %6
  %9 = icmp ult i64 %7, %6
  %spec.select = select i1 %9, i64 1, i64 %8
  store i64 %spec.select, ptr %2, align 8, !tbaa !5
  %10 = alloca float, i64 %6, align 16
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %4 ]
  %11 = tail call float (...) @randnf() #3
  %12 = getelementptr inbounds float, ptr %10, i64 %indvars.iv
  store float %11, ptr %12, align 4, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %6
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %4
  %13 = tail call i32 @getrusage(i32 noundef 0, ptr noundef %0) #3
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %.not31 = icmp eq i64 %14, 0
  br i1 %.not31, label %._crit_edge30, label %.lr.ph29

.lr.ph29:                                         ; preds = %._crit_edge, %.lr.ph29
  %.127 = phi i32 [ %19, %.lr.ph29 ], [ 0, %._crit_edge ]
  %15 = call i32 @matrixf_inv(ptr noundef nonnull %10, i32 noundef %3, i32 noundef %3) #3
  %16 = call i32 @matrixf_inv(ptr noundef nonnull %10, i32 noundef %3, i32 noundef %3) #3
  %17 = call i32 @matrixf_inv(ptr noundef nonnull %10, i32 noundef %3, i32 noundef %3) #3
  %18 = call i32 @matrixf_inv(ptr noundef nonnull %10, i32 noundef %3, i32 noundef %3) #3
  %19 = add i32 %.127, 1
  %20 = zext i32 %19 to i64
  %21 = load i64, ptr %2, align 8, !tbaa !5
  %22 = icmp ugt i64 %21, %20
  br i1 %22, label %.lr.ph29, label %._crit_edge30, !llvm.loop !13

._crit_edge30:                                    ; preds = %.lr.ph29, %._crit_edge
  %23 = call i32 @getrusage(i32 noundef 0, ptr noundef %1) #3
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = shl i64 %24, 2
  store i64 %25, ptr %2, align 8, !tbaa !5
  ret void
}

declare float @randnf(...) local_unnamed_addr #1

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

declare i32 @matrixf_inv(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 = { 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 #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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass