; 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: 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

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

26:                                               ; preds = %71, %5
  %27 = load i64, ptr %12, align 8, !tbaa !9
  %28 = load i64, ptr %7, align 8, !tbaa !9
  %29 = icmp ult i64 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 2, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %74

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store i64 0, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %32 = load i64, ptr %14, align 8, !tbaa !9
  store i64 %32, ptr %15, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %64, %31
  %34 = load i64, ptr %15, align 8, !tbaa !9
  %35 = load i64, ptr %8, align 8, !tbaa !9
  %36 = icmp ult i64 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 5, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  br label %67

38:                                               ; preds = %33
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = load i64, ptr %15, align 8, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %39, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !11
  %43 = zext i8 %42 to i32
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = load i64, ptr %15, align 8, !tbaa !9
  %46 = getelementptr inbounds i8, ptr %44, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !11
  %48 = zext i8 %47 to i32
  %49 = icmp sgt i32 %43, %48
  br i1 %49, label %50, label %63

50:                                               ; preds = %38
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = load i64, ptr %15, align 8, !tbaa !9
  %53 = getelementptr inbounds i8, ptr %51, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = load i64, ptr %15, align 8, !tbaa !9
  %57 = getelementptr inbounds i8, ptr %55, i64 %56
  store i8 %54, ptr %57, align 1, !tbaa !11
  %58 = load i64, ptr %12, align 8, !tbaa !9
  %59 = trunc i64 %58 to i32
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = load i64, ptr %15, align 8, !tbaa !9
  %62 = getelementptr inbounds i32, ptr %60, i64 %61
  store i32 %59, ptr %62, align 4, !tbaa !12
  br label %63

63:                                               ; preds = %50, %38
  br label %64

64:                                               ; preds = %63
  %65 = load i64, ptr %15, align 8, !tbaa !9
  %66 = add i64 %65, 1
  store i64 %66, ptr %15, align 8, !tbaa !9
  br label %33, !llvm.loop !14

67:                                               ; preds = %37
  %68 = load i64, ptr %8, align 8, !tbaa !9
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  %70 = getelementptr inbounds i8, ptr %69, i64 %68
  store ptr %70, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %71

71:                                               ; preds = %67
  %72 = load i64, ptr %12, align 8, !tbaa !9
  %73 = add i64 %72, 1
  store i64 %73, ptr %12, align 8, !tbaa !9
  br label %26, !llvm.loop !16

74:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  ret void
}

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


; 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: mustprogress 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) #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @matrix_column_max_and_idx_u8_cacheline_asimd(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2, ptr nocapture noundef %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #2 {
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %3, ptr align 1 %0, i64 %2, i1 false)
  %6 = shl i64 %2, 2
  tail call void @llvm.memset.p0.i64(ptr align 4 %4, i8 0, i64 %6, i1 false)
  %7 = icmp ult i64 %1, 2
  %.not = icmp eq i64 %2, 0
  %or.cond = or i1 %7, %.not
  br i1 %or.cond, label %._crit_edge33, label %.preheader.us.preheader

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

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.02632.us.pn = phi ptr [ %.02632.us, %._crit_edge.us ], [ %0, %.preheader.us.preheader ]
  %.02731.us = phi i64 [ %35, %._crit_edge.us ], [ 1, %.preheader.us.preheader ]
  %.02632.us = getelementptr inbounds i8, ptr %.02632.us.pn, i64 %2
  %9 = trunc i64 %.02731.us to i32
  br i1 %8, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %26
  %.029.us = phi i64 [ %27, %26 ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %26 ], [ 0, %.preheader.us ]
  %10 = getelementptr inbounds i8, ptr %.02632.us, i64 %.029.us
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %3, i64 %.029.us
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = icmp ugt i8 %11, %13
  br i1 %14, label %15, label %17

15:                                               ; preds = %.preheader.us.new
  store i8 %11, ptr %12, align 1, !tbaa !5
  %16 = getelementptr inbounds i32, ptr %4, i64 %.029.us
  store i32 %9, ptr %16, align 4, !tbaa !8
  br label %17

17:                                               ; preds = %15, %.preheader.us.new
  %18 = or disjoint i64 %.029.us, 1
  %19 = getelementptr inbounds i8, ptr %.02632.us, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %3, i64 %18
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = icmp ugt i8 %20, %22
  br i1 %23, label %24, label %26

24:                                               ; preds = %17
  store i8 %20, ptr %21, align 1, !tbaa !5
  %25 = getelementptr inbounds i32, ptr %4, i64 %18
  store i32 %9, ptr %25, align 4, !tbaa !8
  br label %26

26:                                               ; preds = %24, %17
  %27 = add nuw i64 %.029.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 !10

._crit_edge.us.unr-lcssa:                         ; preds = %26, %.preheader.us
  %.029.us.unr = phi i64 [ 0, %.preheader.us ], [ %27, %26 ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa
  %28 = getelementptr inbounds i8, ptr %.02632.us, i64 %.029.us.unr
  %29 = load i8, ptr %28, align 1, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %3, i64 %.029.us.unr
  %31 = load i8, ptr %30, align 1, !tbaa !5
  %32 = icmp ugt i8 %29, %31
  br i1 %32, label %33, label %._crit_edge.us

33:                                               ; preds = %.epil.preheader
  store i8 %29, ptr %30, align 1, !tbaa !5
  %34 = getelementptr inbounds i32, ptr %4, i64 %.029.us.unr
  store i32 %9, ptr %34, align 4, !tbaa !8
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %.epil.preheader, %33, %._crit_edge.us.unr-lcssa
  %35 = add nuw i64 %.02731.us, 1
  %exitcond35.not = icmp eq i64 %35, %1
  br i1 %exitcond35.not, label %._crit_edge33, label %.preheader.us, !llvm.loop !12

._crit_edge33:                                    ; preds = %._crit_edge.us, %5
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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