; LLVM IR from moarseniy/CudaFEMproject :: FEMproject/matrix_pack/src/cpu_matrix.ll (ZN10CPU_Matrix6l2normEv)

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

%class.Matrix = type <{ ptr, i32, [4 x i8], i64, i64, i64, ptr, i8, [7 x i8] }>

@.str = external hidden unnamed_addr constant [100 x i8], align 1
@__FUNCTION__._ZN10CPU_Matrix6l2normEv = external hidden unnamed_addr constant [7 x i8], align 1

declare void @_Z10_my_assertbPKciS0_(i1 noundef zeroext, ptr noundef, i32 noundef, ptr noundef) #0

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN10CPU_Matrix6l2normEv(ptr noundef nonnull align 8 dereferenceable(49) %0) unnamed_addr #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca float, align 4
  %4 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  %6 = getelementptr inbounds %class.Matrix, ptr %5, i32 0, i32 5
  %7 = load i64, ptr %6, align 8, !tbaa !9
  %8 = icmp ugt i64 %7, 0
  call void @_Z10_my_assertbPKciS0_(i1 noundef zeroext %8, ptr noundef @.str, i32 noundef 281, ptr noundef @__FUNCTION__._ZN10CPU_Matrix6l2normEv)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store float 0.000000e+00, ptr %3, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store i64 0, ptr %4, align 8, !tbaa !16
  br label %9

9:                                                ; preds = %28, %1
  %10 = load i64, ptr %4, align 8, !tbaa !16
  %11 = getelementptr inbounds %class.Matrix, ptr %5, i32 0, i32 5
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = icmp ult i64 %10, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %31

15:                                               ; preds = %9
  %16 = getelementptr inbounds %class.Matrix, ptr %5, i32 0, i32 6
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  %18 = load i64, ptr %4, align 8, !tbaa !16
  %19 = getelementptr inbounds float, ptr %17, i64 %18
  %20 = load float, ptr %19, align 4, !tbaa !14
  %21 = getelementptr inbounds %class.Matrix, ptr %5, i32 0, i32 6
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  %23 = load i64, ptr %4, align 8, !tbaa !16
  %24 = getelementptr inbounds float, ptr %22, i64 %23
  %25 = load float, ptr %24, align 4, !tbaa !14
  %26 = load float, ptr %3, align 4, !tbaa !14
  %27 = call float @llvm.fmuladd.f32(float %20, float %25, float %26)
  store float %27, ptr %3, align 4, !tbaa !14
  br label %28

28:                                               ; preds = %15
  %29 = load i64, ptr %4, align 8, !tbaa !16
  %30 = add i64 %29, 1
  store i64 %30, ptr %4, align 8, !tbaa !16
  br label %9, !llvm.loop !18

31:                                               ; preds = %14
  %32 = load float, ptr %3, align 4, !tbaa !14
  %33 = call noundef float @_ZSt4sqrtf(float noundef %32)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret float %33
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4sqrtf(float noundef) #4

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { mustprogress 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 = { inlinehint mustprogress 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 #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++ TBAA"}
!9 = !{!10, !12, i64 32}
!10 = !{!"_ZTS6Matrix", !11, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !6, i64 40, !13, i64 48}
!11 = !{!"_ZTS11DEVICE_NAME", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{!12, !12, i64 0}
!17 = !{!10, !6, i64 40}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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 = external hidden unnamed_addr constant [100 x i8], align 1
@__FUNCTION__._ZN10CPU_Matrix6l2normEv = external hidden unnamed_addr constant [7 x i8], align 1

declare void @_Z10_my_assertbPKciS0_(i1 noundef zeroext, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN10CPU_Matrix6l2normEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(49) %0) unnamed_addr #2 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = icmp ne i64 %3, 0
  tail call void @_Z10_my_assertbPKciS0_(i1 noundef zeroext %4, ptr noundef nonnull @.str, i32 noundef 281, ptr noundef nonnull @__FUNCTION__._ZN10CPU_Matrix6l2normEv)
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load ptr, ptr %6, align 8, !tbaa !13
  %xtraiter = and i64 %5, 3
  %8 = icmp ult i64 %5, 4
  br i1 %8, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %5, -4
  br label %14

._crit_edge.loopexit.unr-lcssa:                   ; preds = %14, %.lr.ph
  %.lcssa.ph = phi float [ poison, %.lr.ph ], [ %29, %14 ]
  %.08.unr = phi i64 [ 0, %.lr.ph ], [ %30, %14 ]
  %.067.unr = phi float [ 0.000000e+00, %.lr.ph ], [ %29, %14 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %.08.epil = phi i64 [ %12, %.epil.preheader ], [ %.08.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.067.epil = phi float [ %11, %.epil.preheader ], [ %.067.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %9 = getelementptr inbounds float, ptr %7, i64 %.08.epil
  %10 = load float, ptr %9, align 4, !tbaa !14
  %11 = tail call float @llvm.fmuladd.f32(float %10, float %10, float %.067.epil)
  %12 = add nuw i64 %.08.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.epil.preheader, !llvm.loop !16

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %1
  %.06.lcssa = phi float [ 0.000000e+00, %1 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %11, %.epil.preheader ]
  %13 = tail call noundef float @_ZSt4sqrtf(float noundef %.06.lcssa)
  ret float %13

14:                                               ; preds = %14, %.lr.ph.new
  %.08 = phi i64 [ 0, %.lr.ph.new ], [ %30, %14 ]
  %.067 = phi float [ 0.000000e+00, %.lr.ph.new ], [ %29, %14 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %14 ]
  %15 = getelementptr inbounds float, ptr %7, i64 %.08
  %16 = load float, ptr %15, align 4, !tbaa !14
  %17 = tail call float @llvm.fmuladd.f32(float %16, float %16, float %.067)
  %18 = or disjoint i64 %.08, 1
  %19 = getelementptr inbounds float, ptr %7, i64 %18
  %20 = load float, ptr %19, align 4, !tbaa !14
  %21 = tail call float @llvm.fmuladd.f32(float %20, float %20, float %17)
  %22 = or disjoint i64 %.08, 2
  %23 = getelementptr inbounds float, ptr %7, i64 %22
  %24 = load float, ptr %23, align 4, !tbaa !14
  %25 = tail call float @llvm.fmuladd.f32(float %24, float %24, float %21)
  %26 = or disjoint i64 %.08, 3
  %27 = getelementptr inbounds float, ptr %7, i64 %26
  %28 = load float, ptr %27, align 4, !tbaa !14
  %29 = tail call float @llvm.fmuladd.f32(float %28, float %28, float %25)
  %30 = add nuw i64 %.08, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %14, !llvm.loop !18
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4sqrtf(float noundef) local_unnamed_addr #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 = { mustprogress 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 = { inlinehint mustprogress 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" }

!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, !10, i64 32}
!6 = !{!"_ZTS6Matrix", !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !11, i64 40, !12, i64 48}
!7 = !{!"_ZTS11DEVICE_NAME", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{!6, !11, i64 40}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.unroll.disable"}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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