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

; 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_Matrix3maxEv = external hidden unnamed_addr constant [4 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 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_Matrix3maxEv(ptr noundef nonnull align 8 dereferenceable(49) %0) unnamed_addr #2 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 318, ptr noundef @__FUNCTION__._ZN10CPU_Matrix3maxEv)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store float -1.000000e+10, ptr %3, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 0, ptr %4, align 8, !tbaa !16
  br label %9

9:                                                ; preds = %30, %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) #3
  br label %33

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 = load float, ptr %3, align 4, !tbaa !14
  %22 = fcmp ogt float %20, %21
  br i1 %22, label %23, label %29

23:                                               ; preds = %15
  %24 = getelementptr inbounds %class.Matrix, ptr %5, i32 0, i32 6
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  %26 = load i64, ptr %4, align 8, !tbaa !16
  %27 = getelementptr inbounds float, ptr %25, i64 %26
  %28 = load float, ptr %27, align 4, !tbaa !14
  store float %28, ptr %3, align 4, !tbaa !14
  br label %29

29:                                               ; preds = %23, %15
  br label %30

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

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

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 = { 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 = { 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_Matrix3maxEv = external hidden unnamed_addr constant [4 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 uwtable
define dso_local noundef float @_ZN10CPU_Matrix3maxEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(49) %0) unnamed_addr #1 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 318, ptr noundef nonnull @__FUNCTION__._ZN10CPU_Matrix3maxEv)
  %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 %13

._crit_edge.loopexit.unr-lcssa:                   ; preds = %13, %.lr.ph
  %.1.lcssa.ph = phi float [ poison, %.lr.ph ], [ %.1.3, %13 ]
  %.09.unr = phi i64 [ 0, %.lr.ph ], [ %29, %13 ]
  %.068.unr = phi float [ -1.000000e+10, %.lr.ph ], [ %.1.3, %13 ]
  %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
  %.09.epil = phi i64 [ %12, %.epil.preheader ], [ %.09.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.068.epil = phi float [ %.1.epil, %.epil.preheader ], [ %.068.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 %.09.epil
  %10 = load float, ptr %9, align 4, !tbaa !14
  %11 = fcmp ogt float %10, %.068.epil
  %.1.epil = select i1 %11, float %10, float %.068.epil
  %12 = add nuw i64 %.09.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 [ -1.000000e+10, %1 ], [ %.1.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.1.epil, %.epil.preheader ]
  ret float %.06.lcssa

13:                                               ; preds = %13, %.lr.ph.new
  %.09 = phi i64 [ 0, %.lr.ph.new ], [ %29, %13 ]
  %.068 = phi float [ -1.000000e+10, %.lr.ph.new ], [ %.1.3, %13 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %13 ]
  %14 = getelementptr inbounds float, ptr %7, i64 %.09
  %15 = load float, ptr %14, align 4, !tbaa !14
  %16 = fcmp ogt float %15, %.068
  %.1 = select i1 %16, float %15, float %.068
  %17 = or disjoint i64 %.09, 1
  %18 = getelementptr inbounds float, ptr %7, i64 %17
  %19 = load float, ptr %18, align 4, !tbaa !14
  %20 = fcmp ogt float %19, %.1
  %.1.1 = select i1 %20, float %19, float %.1
  %21 = or disjoint i64 %.09, 2
  %22 = getelementptr inbounds float, ptr %7, i64 %21
  %23 = load float, ptr %22, align 4, !tbaa !14
  %24 = fcmp ogt float %23, %.1.1
  %.1.2 = select i1 %24, float %23, float %.1.1
  %25 = or disjoint i64 %.09, 3
  %26 = getelementptr inbounds float, ptr %7, i64 %25
  %27 = load float, ptr %26, align 4, !tbaa !14
  %28 = fcmp ogt float %27, %.1.2
  %.1.3 = select i1 %28, float %27, float %.1.2
  %29 = add nuw i64 %.09, 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 %13, !llvm.loop !18
}

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