; 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: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @matrix_hermitian(ptr noundef %0, i32 noundef %1, i32 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = mul i32 %11, %12
  %14 = zext i32 %13 to i64
  %15 = call ptr @llvm.stacksave.p0()
  store ptr %15, ptr %7, align 8
  %16 = alloca double, i64 %14, align 16
  store i64 %14, ptr %8, align 8
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = mul i32 %18, %19
  %21 = zext i32 %20 to i64
  %22 = mul i64 %21, 8
  call void @llvm.memmove.p0.p0.i64(ptr align 16 %16, ptr align 8 %17, i64 %22, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %53, %3
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = icmp ult i32 %24, %25
  br i1 %26, label %27, label %56

27:                                               ; preds = %23
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %49, %27
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = icmp ult i32 %29, %30
  br i1 %31, label %32, label %52

32:                                               ; preds = %28
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = mul i32 %33, %34
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = add i32 %35, %36
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds double, ptr %16, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !11
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = mul i32 %42, %43
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = add i32 %44, %45
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds double, ptr %41, i64 %47
  store double %40, ptr %48, align 8, !tbaa !11
  br label %49

49:                                               ; preds = %32
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = add i32 %50, 1
  store i32 %51, ptr %10, align 4, !tbaa !9
  br label %28, !llvm.loop !13

52:                                               ; preds = %28
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %9, align 4, !tbaa !9
  %55 = add i32 %54, 1
  store i32 %55, ptr %9, align 4, !tbaa !9
  br label %23, !llvm.loop !15

56:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %57 = load ptr, ptr %7, align 8
  call void @llvm.stackrestore.p0(ptr %57)
  ret i32 0
}

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

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local noundef i32 @matrix_hermitian(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = mul i32 %2, %1
  %5 = zext i32 %4 to i64
  %6 = alloca double, i64 %5, align 16
  %7 = shl nuw nsw i64 %5, 3
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %6, ptr align 8 %0, i64 %7, i1 false)
  %.not = icmp eq i32 %1, 0
  %.not24 = icmp eq i32 %2, 0
  %or.cond = or i1 %.not, %.not24
  br i1 %or.cond, label %._crit_edge23, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %3
  %wide.trip.count = zext i32 %2 to i64
  %8 = add nsw i64 %wide.trip.count, -1
  %min.iters.check = icmp ult i32 %2, 20
  %9 = trunc i64 %8 to i32
  %10 = icmp ugt i64 %8, 4294967295
  %ident.check = icmp ne i32 %1, 1
  %11 = trunc i64 %8 to i32
  %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
  %12 = add nsw i64 %wide.trip.count, -1
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.01822.us = phi i32 [ %61, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %13 = mul i32 %.01822.us, %2
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %.preheader.us
  %14 = mul i32 %.01822.us, %2
  %15 = xor i32 %14, -1
  %16 = icmp ult i32 %15, %9
  %17 = or i1 %16, %10
  %18 = xor i32 %.01822.us, -1
  %19 = icmp ult i32 %18, %11
  %20 = or i1 %17, %ident.check
  %21 = or i1 %19, %20
  br i1 %21, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %vector.scevcheck, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %vector.scevcheck ]
  %22 = trunc i64 %index to i32
  %23 = add i32 %13, %22
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds double, ptr %6, i64 %24
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  %wide.load = load <2 x double>, ptr %25, align 8, !tbaa !5
  %wide.load28 = load <2 x double>, ptr %26, align 8, !tbaa !5
  %27 = add i32 %.01822.us, %22
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds double, ptr %0, i64 %28
  %30 = getelementptr inbounds i8, ptr %29, i64 16
  store <2 x double> %wide.load, ptr %29, align 8, !tbaa !5
  store <2 x double> %wide.load28, ptr %30, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %31 = icmp eq i64 %index.next, %n.vec
  br i1 %31, label %middle.block, label %vector.body, !llvm.loop !9

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

scalar.ph.preheader:                              ; preds = %middle.block, %vector.scevcheck, %.preheader.us
  %indvars.iv.ph = phi i64 [ 0, %vector.scevcheck ], [ 0, %.preheader.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
  %32 = trunc nuw i64 %indvars.iv.ph to i32
  %33 = add i32 %13, %32
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds double, ptr %6, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !5
  %37 = mul i32 %32, %1
  %38 = add i32 %37, %.01822.us
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds double, ptr %0, i64 %39
  store double %36, ptr %40, 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 ]
  %41 = icmp eq i64 %indvars.iv.ph, %12
  br i1 %41, label %._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 ]
  %42 = trunc nuw i64 %indvars.iv to i32
  %43 = add i32 %13, %42
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds double, ptr %6, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !5
  %47 = mul i32 %42, %1
  %48 = add i32 %47, %.01822.us
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds double, ptr %0, i64 %49
  store double %46, ptr %50, align 8, !tbaa !5
  %51 = trunc i64 %indvars.iv to i32
  %52 = add i32 %51, 1
  %53 = add i32 %13, %52
  %54 = zext i32 %53 to i64
  %55 = getelementptr inbounds double, ptr %6, i64 %54
  %56 = load double, ptr %55, align 8, !tbaa !5
  %57 = mul i32 %52, %1
  %58 = add i32 %57, %.01822.us
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds double, ptr %0, i64 %59
  store double %56, ptr %60, 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 %._crit_edge.us, label %scalar.ph, !llvm.loop !13

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %61 = add nuw i32 %.01822.us, 1
  %exitcond27.not = icmp eq i32 %61, %1
  br i1 %exitcond27.not, label %._crit_edge23, label %.preheader.us, !llvm.loop !14

._crit_edge23:                                    ; preds = %._crit_edge.us, %3
  ret i32 0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

!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,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass