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

; 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

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

8:                                                ; preds = %32, %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = icmp ult i32 %9, %10
  br i1 %11, label %12, label %35

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

13:                                               ; preds = %28, %12
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = icmp ult i32 %14, %15
  br i1 %16, label %17, label %31

17:                                               ; preds = %13
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = icmp eq i32 %18, %19
  %21 = zext i1 %20 to i64
  %22 = select i1 %20, double 1.000000e+00, double 0.000000e+00
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = add i32 %24, 1
  store i32 %25, ptr %7, align 4, !tbaa !9
  %26 = zext i32 %24 to i64
  %27 = getelementptr inbounds double, ptr %23, i64 %26
  store double %22, ptr %27, align 8, !tbaa !11
  br label %28

28:                                               ; preds = %17
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = add i32 %29, 1
  store i32 %30, ptr %6, align 4, !tbaa !9
  br label %13, !llvm.loop !13

31:                                               ; preds = %13
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = add i32 %33, 1
  store i32 %34, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !15

35:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 0
}

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 }

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

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: write) uwtable
define dso_local noundef i32 @matrix_eye(ptr nocapture noundef writeonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %._crit_edge, label %.preheader.preheader

.preheader.preheader:                             ; preds = %2
  %min.iters.check = icmp ult i32 %1, 4
  %3 = sub i32 0, %1
  %n.vec = and i32 %1, -4
  %cmp.n = icmp eq i32 %n.vec, %1
  %xtraiter = and i32 %1, 1
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  %4 = add i32 %1, -1
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.loopexit
  %.015 = phi i32 [ %.lcssa, %.loopexit ], [ 0, %.preheader.preheader ]
  %.01014 = phi i32 [ %33, %.loopexit ], [ 0, %.preheader.preheader ]
  %5 = icmp ugt i32 %.015, %3
  %or.cond = select i1 %min.iters.check, i1 true, i1 %5
  br i1 %or.cond, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.preheader
  %ind.end = add i32 %.015, %n.vec
  %broadcast.splatinsert = insertelement <2 x i32> poison, i32 %.01014, i64 0
  %broadcast.splat = shufflevector <2 x i32> %broadcast.splatinsert, <2 x i32> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <2 x i32> [ <i32 0, i32 1>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <2 x i32> %vec.ind, <i32 2, i32 2>
  %offset.idx = add i32 %.015, %index
  %6 = icmp eq <2 x i32> %broadcast.splat, %vec.ind
  %7 = icmp eq <2 x i32> %broadcast.splat, %step.add
  %8 = select <2 x i1> %6, <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double> zeroinitializer
  %9 = select <2 x i1> %7, <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double> zeroinitializer
  %10 = zext i32 %offset.idx to i64
  %11 = getelementptr inbounds double, ptr %0, i64 %10
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  store <2 x double> %8, ptr %11, align 8, !tbaa !5
  store <2 x double> %9, ptr %12, align 8, !tbaa !5
  %index.next = add nuw i32 %index, 4
  %vec.ind.next = add <2 x i32> %vec.ind, <i32 4, i32 4>
  %13 = icmp eq i32 %index.next, %n.vec
  br i1 %13, label %middle.block, label %vector.body, !llvm.loop !9

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

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader
  %.113.ph = phi i32 [ %.015, %.preheader ], [ %ind.end, %middle.block ]
  %.0912.ph = phi i32 [ 0, %.preheader ], [ %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
  %14 = icmp eq i32 %.01014, %.0912.ph
  %15 = select i1 %14, double 1.000000e+00, double 0.000000e+00
  %16 = add i32 %.113.ph, 1
  %17 = zext i32 %.113.ph to i64
  %18 = getelementptr inbounds double, ptr %0, i64 %17
  store double %15, ptr %18, align 8, !tbaa !5
  %19 = or disjoint i32 %.0912.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.lcssa20.unr = phi i32 [ poison, %scalar.ph.preheader ], [ %16, %scalar.ph.prol ]
  %.113.unr = phi i32 [ %.113.ph, %scalar.ph.preheader ], [ %16, %scalar.ph.prol ]
  %.0912.unr = phi i32 [ %.0912.ph, %scalar.ph.preheader ], [ %19, %scalar.ph.prol ]
  %20 = icmp eq i32 %.0912.ph, %4
  br i1 %20, label %.loopexit, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.113 = phi i32 [ %29, %scalar.ph ], [ %.113.unr, %scalar.ph.prol.loopexit ]
  %.0912 = phi i32 [ %32, %scalar.ph ], [ %.0912.unr, %scalar.ph.prol.loopexit ]
  %21 = icmp eq i32 %.01014, %.0912
  %22 = select i1 %21, double 1.000000e+00, double 0.000000e+00
  %23 = add i32 %.113, 1
  %24 = zext i32 %.113 to i64
  %25 = getelementptr inbounds double, ptr %0, i64 %24
  store double %22, ptr %25, align 8, !tbaa !5
  %26 = add nuw i32 %.0912, 1
  %27 = icmp eq i32 %.01014, %26
  %28 = select i1 %27, double 1.000000e+00, double 0.000000e+00
  %29 = add i32 %.113, 2
  %30 = zext i32 %23 to i64
  %31 = getelementptr inbounds double, ptr %0, i64 %30
  store double %28, ptr %31, align 8, !tbaa !5
  %32 = add nuw i32 %.0912, 2
  %exitcond.not.1 = icmp eq i32 %32, %1
  br i1 %exitcond.not.1, label %.loopexit, label %scalar.ph, !llvm.loop !13

.loopexit:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %.lcssa = phi i32 [ %ind.end, %middle.block ], [ %.lcssa20.unr, %scalar.ph.prol.loopexit ], [ %29, %scalar.ph ]
  %33 = add nuw i32 %.01014, 1
  %exitcond16.not = icmp eq i32 %33, %1
  br i1 %exitcond16.not, label %._crit_edge, label %.preheader, !llvm.loop !14

._crit_edge:                                      ; preds = %.loopexit, %2
  ret i32 0
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: write) 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" }

!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, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !11}
!14 = distinct !{!14, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass