; LLVM IR from zchrissirhcz/pixel :: legacy/matcalc (matrix_column_max)

; 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: nounwind uwtable
define dso_local void @matrix_column_max_u8_naive(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %54, %4
  %14 = load i64, ptr %9, align 8, !tbaa !9
  %15 = load i64, ptr %7, align 8, !tbaa !9
  %16 = icmp ult i64 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %57

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %50, %18
  %20 = load i64, ptr %11, align 8, !tbaa !9
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %53

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %25 = load i64, ptr %11, align 8, !tbaa !9
  %26 = load i64, ptr %7, align 8, !tbaa !9
  %27 = mul i64 %25, %26
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = add i64 %27, %28
  store i64 %29, ptr %12, align 8, !tbaa !9
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i64, ptr %12, align 8, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %30, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = zext i8 %33 to i32
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load i64, ptr %9, align 8, !tbaa !9
  %37 = getelementptr inbounds i8, ptr %35, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !11
  %39 = zext i8 %38 to i32
  %40 = icmp sgt i32 %34, %39
  br i1 %40, label %41, label %49

41:                                               ; preds = %24
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i64, ptr %12, align 8, !tbaa !9
  %44 = getelementptr inbounds i8, ptr %42, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !11
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load i64, ptr %9, align 8, !tbaa !9
  %48 = getelementptr inbounds i8, ptr %46, i64 %47
  store i8 %45, ptr %48, align 1, !tbaa !11
  br label %49

49:                                               ; preds = %41, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %50

50:                                               ; preds = %49
  %51 = load i64, ptr %11, align 8, !tbaa !9
  %52 = add i64 %51, 1
  store i64 %52, ptr %11, align 8, !tbaa !9
  br label %19, !llvm.loop !12

53:                                               ; preds = %23
  br label %54

54:                                               ; preds = %53
  %55 = load i64, ptr %9, align 8, !tbaa !9
  %56 = add i64 %55, 1
  store i64 %56, ptr %9, align 8, !tbaa !9
  br label %13, !llvm.loop !14

57:                                               ; preds = %17
  ret void
}

; 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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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 void @matrix_column_max_u8_naive(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %.not = icmp eq i64 %2, 0
  %.not21 = icmp eq i64 %1, 0
  %or.cond = or i1 %.not, %.not21
  br i1 %or.cond, label %._crit_edge20, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %4
  %xtraiter = and i64 %1, 1
  %5 = icmp eq i64 %1, 1
  %unroll_iter = and i64 %1, -2
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.019.us = phi i64 [ %26, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %invariant.gep.us = getelementptr i8, ptr %0, i64 %.019.us
  %6 = getelementptr inbounds i8, ptr %3, i64 %.019.us
  %.promoted.us = load i8, ptr %6, align 1, !tbaa !5
  br i1 %5, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %19
  %7 = phi i8 [ %20, %19 ], [ %.promoted.us, %.preheader.us ]
  %.01618.us = phi i64 [ %21, %19 ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %19 ], [ 0, %.preheader.us ]
  %8 = mul i64 %.01618.us, %2
  %gep.us = getelementptr i8, ptr %invariant.gep.us, i64 %8
  %9 = load i8, ptr %gep.us, align 1, !tbaa !5
  %10 = icmp ugt i8 %9, %7
  br i1 %10, label %11, label %12

11:                                               ; preds = %.preheader.us.new
  store i8 %9, ptr %6, align 1, !tbaa !5
  br label %12

12:                                               ; preds = %11, %.preheader.us.new
  %13 = phi i8 [ %9, %11 ], [ %7, %.preheader.us.new ]
  %14 = or disjoint i64 %.01618.us, 1
  %15 = mul i64 %14, %2
  %gep.us.1 = getelementptr i8, ptr %invariant.gep.us, i64 %15
  %16 = load i8, ptr %gep.us.1, align 1, !tbaa !5
  %17 = icmp ugt i8 %16, %13
  br i1 %17, label %18, label %19

18:                                               ; preds = %12
  store i8 %16, ptr %6, align 1, !tbaa !5
  br label %19

19:                                               ; preds = %18, %12
  %20 = phi i8 [ %16, %18 ], [ %13, %12 ]
  %21 = add nuw i64 %.01618.us, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !8

._crit_edge.us.unr-lcssa:                         ; preds = %19, %.preheader.us
  %.unr = phi i8 [ %.promoted.us, %.preheader.us ], [ %20, %19 ]
  %.01618.us.unr = phi i64 [ 0, %.preheader.us ], [ %21, %19 ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa
  %22 = mul i64 %.01618.us.unr, %2
  %gep.us.epil = getelementptr i8, ptr %invariant.gep.us, i64 %22
  %23 = load i8, ptr %gep.us.epil, align 1, !tbaa !5
  %24 = icmp ugt i8 %23, %.unr
  br i1 %24, label %25, label %._crit_edge.us

25:                                               ; preds = %.epil.preheader
  store i8 %23, ptr %6, align 1, !tbaa !5
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %.epil.preheader, %25, %._crit_edge.us.unr-lcssa
  %26 = add nuw i64 %.019.us, 1
  %exitcond23.not = icmp eq i64 %26, %2
  br i1 %exitcond23.not, label %._crit_edge20, label %.preheader.us, !llvm.loop !10

._crit_edge20:                                    ; preds = %._crit_edge.us, %4
  ret void
}

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


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