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

; 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 @matrixcf_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 = %35, %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 %38

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

13:                                               ; preds = %31, %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 %34

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 = fptrunc double %22 to float
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = add i32 %25, 1
  store i32 %26, ptr %7, align 4, !tbaa !9
  %27 = zext i32 %25 to i64
  %28 = getelementptr inbounds { float, float }, ptr %24, i64 %27
  %29 = getelementptr inbounds { float, float }, ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds { float, float }, ptr %28, i32 0, i32 1
  store float %23, ptr %29, align 4
  store float 0.000000e+00, ptr %30, align 4
  br label %31

31:                                               ; preds = %17
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = add i32 %32, 1
  store i32 %33, ptr %6, align 4, !tbaa !9
  br label %13, !llvm.loop !11

34:                                               ; preds = %13
  br label %35

35:                                               ; preds = %34
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = add i32 %36, 1
  store i32 %37, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !13

38:                                               ; 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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 @matrixcf_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
  %3 = add i32 %1, -1
  %scevgep17 = getelementptr i8, ptr %0, i64 4
  %min.iters.check = icmp ult i32 %1, 18
  %4 = zext i32 %3 to i64
  %mul = shl nuw nsw i64 %4, 3
  %5 = zext i32 %3 to i64
  %mul19 = shl nuw nsw i64 %5, 3
  %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
  %6 = add i32 %1, -1
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.loopexit
  %.015 = phi i32 [ %.lcssa, %.loopexit ], [ 0, %.preheader.preheader ]
  %.01014 = phi i32 [ %49, %.loopexit ], [ 0, %.preheader.preheader ]
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %.preheader
  %7 = xor i32 %.015, -1
  %8 = icmp ugt i32 %3, %7
  %9 = zext i32 %.015 to i64
  %10 = shl nuw nsw i64 %9, 3
  %scevgep = getelementptr i8, ptr %0, i64 %10
  %11 = getelementptr i8, ptr %scevgep, i64 %mul
  %12 = icmp ult ptr %11, %scevgep
  %scevgep18 = getelementptr i8, ptr %scevgep17, i64 %10
  %13 = getelementptr i8, ptr %scevgep18, i64 %mul19
  %14 = icmp ult ptr %13, %scevgep18
  %15 = or i1 %8, %12
  %16 = or i1 %15, %14
  br i1 %16, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.scevcheck
  %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
  %17 = add i32 %offset.idx, 2
  %18 = icmp eq <2 x i32> %broadcast.splat, %vec.ind
  %19 = icmp eq <2 x i32> %broadcast.splat, %step.add
  %20 = select <2 x i1> %18, <2 x float> <float 1.000000e+00, float 1.000000e+00>, <2 x float> zeroinitializer
  %21 = select <2 x i1> %19, <2 x float> <float 1.000000e+00, float 1.000000e+00>, <2 x float> zeroinitializer
  %22 = zext i32 %offset.idx to i64
  %23 = zext i32 %17 to i64
  %24 = getelementptr inbounds { float, float }, ptr %0, i64 %22
  %25 = getelementptr inbounds { float, float }, ptr %0, i64 %23
  %interleaved.vec = shufflevector <2 x float> %20, <2 x float> zeroinitializer, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
  store <4 x float> %interleaved.vec, ptr %24, align 4
  %interleaved.vec24 = shufflevector <2 x float> %21, <2 x float> zeroinitializer, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
  store <4 x float> %interleaved.vec24, ptr %25, align 4
  %index.next = add nuw i32 %index, 4
  %vec.ind.next = add <2 x i32> %vec.ind, <i32 4, i32 4>
  %26 = icmp eq i32 %index.next, %n.vec
  br i1 %26, label %middle.block, label %vector.body, !llvm.loop !5

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

scalar.ph.preheader:                              ; preds = %middle.block, %vector.scevcheck, %.preheader
  %.113.ph = phi i32 [ %.015, %vector.scevcheck ], [ %.015, %.preheader ], [ %ind.end, %middle.block ]
  %.0912.ph = phi i32 [ 0, %vector.scevcheck ], [ 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
  %27 = icmp eq i32 %.01014, %.0912.ph
  %28 = select i1 %27, float 1.000000e+00, float 0.000000e+00
  %29 = add i32 %.113.ph, 1
  %30 = zext i32 %.113.ph to i64
  %31 = getelementptr inbounds { float, float }, ptr %0, i64 %30
  %32 = getelementptr inbounds i8, ptr %31, i64 4
  store float %28, ptr %31, align 4
  store float 0.000000e+00, ptr %32, align 4
  %33 = or disjoint i32 %.0912.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.lcssa25.unr = phi i32 [ poison, %scalar.ph.preheader ], [ %29, %scalar.ph.prol ]
  %.113.unr = phi i32 [ %.113.ph, %scalar.ph.preheader ], [ %29, %scalar.ph.prol ]
  %.0912.unr = phi i32 [ %.0912.ph, %scalar.ph.preheader ], [ %33, %scalar.ph.prol ]
  %34 = icmp eq i32 %.0912.ph, %6
  br i1 %34, label %.loopexit, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.113 = phi i32 [ %44, %scalar.ph ], [ %.113.unr, %scalar.ph.prol.loopexit ]
  %.0912 = phi i32 [ %48, %scalar.ph ], [ %.0912.unr, %scalar.ph.prol.loopexit ]
  %35 = icmp eq i32 %.01014, %.0912
  %36 = select i1 %35, float 1.000000e+00, float 0.000000e+00
  %37 = add i32 %.113, 1
  %38 = zext i32 %.113 to i64
  %39 = getelementptr inbounds { float, float }, ptr %0, i64 %38
  %40 = getelementptr inbounds i8, ptr %39, i64 4
  store float %36, ptr %39, align 4
  store float 0.000000e+00, ptr %40, align 4
  %41 = add nuw i32 %.0912, 1
  %42 = icmp eq i32 %.01014, %41
  %43 = select i1 %42, float 1.000000e+00, float 0.000000e+00
  %44 = add i32 %.113, 2
  %45 = zext i32 %37 to i64
  %46 = getelementptr inbounds { float, float }, ptr %0, i64 %45
  %47 = getelementptr inbounds i8, ptr %46, i64 4
  store float %43, ptr %46, align 4
  store float 0.000000e+00, ptr %47, align 4
  %48 = add nuw i32 %.0912, 2
  %exitcond.not.1 = icmp eq i32 %48, %1
  br i1 %exitcond.not.1, label %.loopexit, label %scalar.ph, !llvm.loop !9

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

._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 = distinct !{!5, !6, !7, !8}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!"llvm.loop.isvectorized", i32 1}
!8 = !{!"llvm.loop.unroll.runtime.disable"}
!9 = distinct !{!9, !6, !7}
!10 = distinct !{!10, !6}


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