; LLVM IR from tyoma/agge :: src/agge/blenders_intel.ll (ZNK4agge4simd19blender_solid_colorclEPNS_7pixel32Eiij)

; 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.agge::simd::blender_solid_color" = type <{ <2 x i64>, <2 x i64>, %"struct.agge::pixel32", [12 x i8] }>
%"struct.agge::pixel32" = type { [4 x i8] }

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZNK4agge4simd19blender_solid_colorclEPNS_7pixel32Eiij(ptr noundef nonnull align 16 dereferenceable(36) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %11 = load ptr, ptr %6, align 8
  br label %12

12:                                               ; preds = %18, %5
  %13 = load i32, ptr %10, align 4, !tbaa !9
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %23

15:                                               ; preds = %12
  %16 = getelementptr inbounds %"class.agge::simd::blender_solid_color", ptr %11, i32 0, i32 2
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %17, ptr align 16 %16, i64 4, i1 false), !tbaa.struct !11
  br label %18

18:                                               ; preds = %15
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = add i32 %19, -1
  store i32 %20, ptr %10, align 4, !tbaa !9
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.agge::pixel32", ptr %21, i32 1
  store ptr %22, ptr %7, align 8, !tbaa !5
  br label %12, !llvm.loop !13

23:                                               ; preds = %12
  ret void
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 4, !12}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZNK4agge4simd19blender_solid_colorclEPNS_7pixel32Eiij(ptr nocapture noundef nonnull readonly align 16 dereferenceable(36) %0, ptr nocapture noundef writeonly %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 align 2 {
  %.not5 = icmp eq i32 %4, 0
  br i1 %.not5, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = zext i32 %4 to i64
  %min.iters.check = icmp ult i32 %4, 16
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph
  %8 = add i32 %4, -1
  %9 = zext i32 %8 to i64
  %10 = shl nuw nsw i64 %9, 2
  %11 = getelementptr i8, ptr %1, i64 %10
  %scevgep = getelementptr i8, ptr %11, i64 4
  %scevgep8 = getelementptr inbounds i8, ptr %0, i64 36
  %bound0 = icmp ugt ptr %scevgep8, %1
  %bound1 = icmp ult ptr %6, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %7, 4294967288
  %.cast = trunc nuw i64 %n.vec to i32
  %ind.end = sub i32 %4, %.cast
  %12 = shl nuw nsw i64 %n.vec, 2
  %ind.end9 = getelementptr i8, ptr %1, i64 %12
  %13 = load i32, ptr %6, align 16, !tbaa !5, !alias.scope !8
  %broadcast.splatinsert12 = insertelement <4 x i32> poison, i32 %13, i64 0
  %broadcast.splat13 = shufflevector <4 x i32> %broadcast.splatinsert12, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = shl i64 %index, 2
  %next.gep = getelementptr i8, ptr %1, i64 %offset.idx
  %14 = getelementptr i8, ptr %next.gep, i64 16
  store <4 x i32> %broadcast.splat13, ptr %next.gep, align 1, !tbaa !5, !alias.scope !11, !noalias !8
  store <4 x i32> %broadcast.splat13, ptr %14, align 1, !tbaa !5, !alias.scope !11, !noalias !8
  %index.next = add nuw i64 %index, 8
  %15 = icmp eq i64 %index.next, %n.vec
  br i1 %15, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %7
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %.07.ph = phi i32 [ %4, %vector.memcheck ], [ %4, %.lr.ph ], [ %ind.end, %middle.block ]
  %.046.ph = phi ptr [ %1, %vector.memcheck ], [ %1, %.lr.ph ], [ %ind.end9, %middle.block ]
  %16 = add i32 %.07.ph, -1
  %xtraiter = and i32 %.07.ph, 7
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %.07.prol = phi i32 [ %18, %scalar.ph.prol ], [ %.07.ph, %scalar.ph.preheader ]
  %.046.prol = phi ptr [ %19, %scalar.ph.prol ], [ %.046.ph, %scalar.ph.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %17 = load i32, ptr %6, align 16, !tbaa !5
  store i32 %17, ptr %.046.prol, align 1, !tbaa !5
  %18 = add i32 %.07.prol, -1
  %19 = getelementptr inbounds i8, ptr %.046.prol, i64 4
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !17

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.07.unr = phi i32 [ %.07.ph, %scalar.ph.preheader ], [ %18, %scalar.ph.prol ]
  %.046.unr = phi ptr [ %.046.ph, %scalar.ph.preheader ], [ %19, %scalar.ph.prol ]
  %20 = icmp ult i32 %16, 7
  br i1 %20, label %._crit_edge, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.07 = phi i32 [ %36, %scalar.ph ], [ %.07.unr, %scalar.ph.prol.loopexit ]
  %.046 = phi ptr [ %37, %scalar.ph ], [ %.046.unr, %scalar.ph.prol.loopexit ]
  %21 = load i32, ptr %6, align 16, !tbaa !5
  store i32 %21, ptr %.046, align 1, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %.046, i64 4
  %23 = load i32, ptr %6, align 16, !tbaa !5
  store i32 %23, ptr %22, align 1, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %.046, i64 8
  %25 = load i32, ptr %6, align 16, !tbaa !5
  store i32 %25, ptr %24, align 1, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %.046, i64 12
  %27 = load i32, ptr %6, align 16, !tbaa !5
  store i32 %27, ptr %26, align 1, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %.046, i64 16
  %29 = load i32, ptr %6, align 16, !tbaa !5
  store i32 %29, ptr %28, align 1, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %.046, i64 20
  %31 = load i32, ptr %6, align 16, !tbaa !5
  store i32 %31, ptr %30, align 1, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %.046, i64 24
  %33 = load i32, ptr %6, align 16, !tbaa !5
  store i32 %33, ptr %32, align 1, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %.046, i64 28
  %35 = load i32, ptr %6, align 16, !tbaa !5
  store i32 %35, ptr %34, align 1, !tbaa !5
  %36 = add i32 %.07, -8
  %37 = getelementptr inbounds i8, ptr %.046, i64 32
  %.not.7 = icmp eq i32 %36, 0
  br i1 %.not.7, label %._crit_edge, label %scalar.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(write, 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++ TBAA"}
!8 = !{!9}
!9 = distinct !{!9, !10}
!10 = distinct !{!10, !"LVerDomain"}
!11 = !{!12}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !14, !15, !16}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = distinct !{!19, !14, !15}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass