; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseFill.ll (ZN4Simd4Base8FillBgraEPhmmmhhhh)

; 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: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4Simd7AlignLoEmm(i64 noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base8FillBgraEPhmmmhhhh(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i8 noundef zeroext %4, i8 noundef zeroext %5, i8 noundef zeroext %6, i8 noundef zeroext %7) #2 {
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i8, align 1
  %14 = alloca i8, align 1
  %15 = alloca i8, align 1
  %16 = alloca i8, align 1
  %17 = alloca i32, align 4
  %18 = alloca i64, align 8
  %19 = alloca i64, align 8
  %20 = alloca i64, align 8
  %21 = alloca i32, align 4
  %22 = alloca i64, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i64 %1, ptr %10, align 8, !tbaa !9
  store i64 %2, ptr %11, align 8, !tbaa !9
  store i64 %3, ptr %12, align 8, !tbaa !9
  store i8 %4, ptr %13, align 1, !tbaa !11
  store i8 %5, ptr %14, align 1, !tbaa !11
  store i8 %6, ptr %15, align 1, !tbaa !11
  store i8 %7, ptr %16, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %23 = load i8, ptr %13, align 1, !tbaa !11
  %24 = zext i8 %23 to i32
  %25 = load i8, ptr %14, align 1, !tbaa !11
  %26 = zext i8 %25 to i32
  %27 = shl i32 %26, 8
  %28 = or i32 %24, %27
  %29 = load i8, ptr %15, align 1, !tbaa !11
  %30 = zext i8 %29 to i32
  %31 = shl i32 %30, 16
  %32 = or i32 %28, %31
  %33 = load i8, ptr %16, align 1, !tbaa !11
  %34 = zext i8 %33 to i32
  %35 = shl i32 %34, 24
  %36 = or i32 %32, %35
  store i32 %36, ptr %17, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %37 = load i32, ptr %17, align 4, !tbaa !12
  %38 = zext i32 %37 to i64
  %39 = load i32, ptr %17, align 4, !tbaa !12
  %40 = zext i32 %39 to i64
  %41 = shl i64 %40, 32
  %42 = or i64 %38, %41
  store i64 %42, ptr %18, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  %43 = load i64, ptr %11, align 8, !tbaa !9
  %44 = call noundef i64 @_ZN4Simd7AlignLoEmm(i64 noundef %43, i64 noundef 2)
  store i64 %44, ptr %19, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  store i64 0, ptr %20, align 8, !tbaa !9
  br label %45

45:                                               ; preds = %78, %8
  %46 = load i64, ptr %20, align 8, !tbaa !9
  %47 = load i64, ptr %12, align 8, !tbaa !9
  %48 = icmp ult i64 %46, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %45
  store i32 2, ptr %21, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  br label %81

50:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #3
  store i64 0, ptr %22, align 8, !tbaa !9
  br label %51

51:                                               ; preds = %61, %50
  %52 = load i64, ptr %22, align 8, !tbaa !9
  %53 = load i64, ptr %19, align 8, !tbaa !9
  %54 = icmp ult i64 %52, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %51
  store i32 5, ptr %21, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #3
  br label %64

56:                                               ; preds = %51
  %57 = load i64, ptr %18, align 8, !tbaa !9
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = load i64, ptr %22, align 8, !tbaa !9
  %60 = getelementptr inbounds i32, ptr %58, i64 %59
  store i64 %57, ptr %60, align 8, !tbaa !9
  br label %61

61:                                               ; preds = %56
  %62 = load i64, ptr %22, align 8, !tbaa !9
  %63 = add i64 %62, 2
  store i64 %63, ptr %22, align 8, !tbaa !9
  br label %51, !llvm.loop !14

64:                                               ; preds = %55
  %65 = load i64, ptr %11, align 8, !tbaa !9
  %66 = load i64, ptr %19, align 8, !tbaa !9
  %67 = icmp ne i64 %65, %66
  br i1 %67, label %68, label %74

68:                                               ; preds = %64
  %69 = load i32, ptr %17, align 4, !tbaa !12
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = load i64, ptr %11, align 8, !tbaa !9
  %72 = sub i64 %71, 1
  %73 = getelementptr inbounds i32, ptr %70, i64 %72
  store i32 %69, ptr %73, align 4, !tbaa !12
  br label %74

74:                                               ; preds = %68, %64
  %75 = load i64, ptr %10, align 8, !tbaa !9
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %76, i64 %75
  store ptr %77, ptr %9, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %74
  %79 = load i64, ptr %20, align 8, !tbaa !9
  %80 = add i64 %79, 1
  store i64 %80, ptr %20, align 8, !tbaa !9
  br label %45, !llvm.loop !16

81:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline 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 #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, !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: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4Simd7AlignLoEmm(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4Simd4Base8FillBgraEPhmmmhhhh(ptr nocapture noundef writeonly %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i8 noundef zeroext %4, i8 noundef zeroext %5, i8 noundef zeroext %6, i8 noundef zeroext %7) local_unnamed_addr #1 {
  %9 = zext i8 %4 to i32
  %10 = zext i8 %5 to i32
  %11 = shl nuw nsw i32 %10, 8
  %12 = or disjoint i32 %11, %9
  %13 = zext i8 %6 to i32
  %14 = shl nuw nsw i32 %13, 16
  %15 = or disjoint i32 %12, %14
  %16 = zext i8 %7 to i32
  %17 = shl nuw i32 %16, 24
  %18 = or disjoint i32 %15, %17
  %19 = zext i32 %18 to i64
  %20 = mul nuw i64 %19, 4294967297
  %21 = tail call noundef i64 @_ZN4Simd7AlignLoEmm(i64 noundef %2, i64 noundef 2)
  %.not33 = icmp eq i64 %3, 0
  br i1 %.not33, label %._crit_edge29, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %8
  %.not34 = icmp eq i64 %21, 0
  %.not = icmp eq i64 %21, %2
  %22 = add i64 %2, -1
  br i1 %.not34, label %.preheader.lr.ph.split, label %.preheader.lr.ph.split.us

.preheader.lr.ph.split.us:                        ; preds = %.preheader.lr.ph
  br i1 %.not, label %.preheader.us.us.preheader, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph.split.us
  %23 = add i64 %21, -1
  %24 = lshr i64 %23, 1
  %25 = add nuw i64 %24, 1
  %min.iters.check = icmp ult i64 %21, 7
  %n.vec = and i64 %25, -4
  %ind.end = shl i64 %n.vec, 1
  %broadcast.splatinsert = insertelement <2 x i64> poison, i64 %20, i64 0
  %broadcast.splat = shufflevector <2 x i64> %broadcast.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
  %cmp.n = icmp eq i64 %25, %n.vec
  br label %.preheader.us

.preheader.us.us.preheader:                       ; preds = %.preheader.lr.ph.split.us
  %umax = tail call i64 @llvm.umax.i64(i64 %2, i64 2)
  %26 = add i64 %umax, -1
  %27 = lshr i64 %26, 1
  %28 = add nuw i64 %27, 1
  %min.iters.check46 = icmp ult i64 %2, 7
  %n.vec49 = and i64 %28, -4
  %ind.end50 = shl i64 %n.vec49, 1
  %broadcast.splatinsert55 = insertelement <2 x i64> poison, i64 %20, i64 0
  %broadcast.splat56 = shufflevector <2 x i64> %broadcast.splatinsert55, <2 x i64> poison, <2 x i32> zeroinitializer
  %cmp.n58 = icmp eq i64 %28, %n.vec49
  br label %.preheader.us.us

.preheader.us.us:                                 ; preds = %.preheader.us.us.preheader, %._crit_edge.us.us
  %.02228.us.us = phi i64 [ %36, %._crit_edge.us.us ], [ 0, %.preheader.us.us.preheader ]
  %.02327.us.us = phi ptr [ %35, %._crit_edge.us.us ], [ %0, %.preheader.us.us.preheader ]
  br i1 %min.iters.check46, label %scalar.ph45.preheader, label %vector.body52

vector.body52:                                    ; preds = %.preheader.us.us, %vector.body52
  %index53 = phi i64 [ %index.next57, %vector.body52 ], [ 0, %.preheader.us.us ]
  %.idx59 = shl i64 %index53, 3
  %29 = getelementptr inbounds i8, ptr %.02327.us.us, i64 %.idx59
  %30 = getelementptr inbounds i8, ptr %29, i64 16
  store <2 x i64> %broadcast.splat56, ptr %29, align 8, !tbaa !5
  store <2 x i64> %broadcast.splat56, ptr %30, align 8, !tbaa !5
  %index.next57 = add nuw i64 %index53, 4
  %31 = icmp eq i64 %index.next57, %n.vec49
  br i1 %31, label %middle.block44, label %vector.body52, !llvm.loop !9

middle.block44:                                   ; preds = %vector.body52
  br i1 %cmp.n58, label %._crit_edge.us.us, label %scalar.ph45.preheader

scalar.ph45.preheader:                            ; preds = %middle.block44, %.preheader.us.us
  %.026.us.us.ph = phi i64 [ 0, %.preheader.us.us ], [ %ind.end50, %middle.block44 ]
  br label %scalar.ph45

scalar.ph45:                                      ; preds = %scalar.ph45.preheader, %scalar.ph45
  %.026.us.us = phi i64 [ %33, %scalar.ph45 ], [ %.026.us.us.ph, %scalar.ph45.preheader ]
  %32 = getelementptr inbounds i32, ptr %.02327.us.us, i64 %.026.us.us
  store i64 %20, ptr %32, align 8, !tbaa !5
  %33 = add nuw i64 %.026.us.us, 2
  %34 = icmp ult i64 %33, %2
  br i1 %34, label %scalar.ph45, label %._crit_edge.us.us, !llvm.loop !13

._crit_edge.us.us:                                ; preds = %scalar.ph45, %middle.block44
  %35 = getelementptr inbounds i8, ptr %.02327.us.us, i64 %1
  %36 = add nuw i64 %.02228.us.us, 1
  %exitcond38.not = icmp eq i64 %36, %3
  br i1 %exitcond38.not, label %._crit_edge29, label %.preheader.us.us, !llvm.loop !14

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.02228.us = phi i64 [ %45, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %.02327.us = phi ptr [ %44, %._crit_edge.us ], [ %0, %.preheader.us.preheader ]
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.preheader.us, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.preheader.us ]
  %.idx = shl i64 %index, 3
  %37 = getelementptr inbounds i8, ptr %.02327.us, i64 %.idx
  %38 = getelementptr inbounds i8, ptr %37, i64 16
  store <2 x i64> %broadcast.splat, ptr %37, align 8, !tbaa !5
  store <2 x i64> %broadcast.splat, ptr %38, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %39 = icmp eq i64 %index.next, %n.vec
  br i1 %39, label %middle.block, label %vector.body, !llvm.loop !15

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader.us
  %.026.us.ph = phi i64 [ 0, %.preheader.us ], [ %ind.end, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.026.us = phi i64 [ %41, %scalar.ph ], [ %.026.us.ph, %scalar.ph.preheader ]
  %40 = getelementptr inbounds i32, ptr %.02327.us, i64 %.026.us
  store i64 %20, ptr %40, align 8, !tbaa !5
  %41 = add nuw i64 %.026.us, 2
  %42 = icmp ult i64 %41, %21
  br i1 %42, label %scalar.ph, label %._crit_edge.us, !llvm.loop !16

._crit_edge.us:                                   ; preds = %scalar.ph, %middle.block
  %43 = getelementptr inbounds i32, ptr %.02327.us, i64 %22
  store i32 %18, ptr %43, align 4, !tbaa !17
  %44 = getelementptr inbounds i8, ptr %.02327.us, i64 %1
  %45 = add nuw i64 %.02228.us, 1
  %exitcond.not = icmp eq i64 %45, %3
  br i1 %exitcond.not, label %._crit_edge29, label %.preheader.us, !llvm.loop !14

.preheader.lr.ph.split:                           ; preds = %.preheader.lr.ph
  br i1 %.not, label %._crit_edge29, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader.lr.ph.split
  %xtraiter = and i64 %3, 7
  %46 = icmp ult i64 %3, 8
  br i1 %46, label %._crit_edge29.loopexit.unr-lcssa, label %.preheader.preheader.new

.preheader.preheader.new:                         ; preds = %.preheader.preheader
  %unroll_iter = and i64 %3, -8
  br label %.preheader

.preheader:                                       ; preds = %.preheader, %.preheader.preheader.new
  %.02327 = phi ptr [ %0, %.preheader.preheader.new ], [ %62, %.preheader ]
  %niter = phi i64 [ 0, %.preheader.preheader.new ], [ %niter.next.7, %.preheader ]
  %47 = getelementptr inbounds i32, ptr %.02327, i64 %22
  store i32 %18, ptr %47, align 4, !tbaa !17
  %48 = getelementptr inbounds i8, ptr %.02327, i64 %1
  %49 = getelementptr inbounds i32, ptr %48, i64 %22
  store i32 %18, ptr %49, align 4, !tbaa !17
  %50 = getelementptr inbounds i8, ptr %48, i64 %1
  %51 = getelementptr inbounds i32, ptr %50, i64 %22
  store i32 %18, ptr %51, align 4, !tbaa !17
  %52 = getelementptr inbounds i8, ptr %50, i64 %1
  %53 = getelementptr inbounds i32, ptr %52, i64 %22
  store i32 %18, ptr %53, align 4, !tbaa !17
  %54 = getelementptr inbounds i8, ptr %52, i64 %1
  %55 = getelementptr inbounds i32, ptr %54, i64 %22
  store i32 %18, ptr %55, align 4, !tbaa !17
  %56 = getelementptr inbounds i8, ptr %54, i64 %1
  %57 = getelementptr inbounds i32, ptr %56, i64 %22
  store i32 %18, ptr %57, align 4, !tbaa !17
  %58 = getelementptr inbounds i8, ptr %56, i64 %1
  %59 = getelementptr inbounds i32, ptr %58, i64 %22
  store i32 %18, ptr %59, align 4, !tbaa !17
  %60 = getelementptr inbounds i8, ptr %58, i64 %1
  %61 = getelementptr inbounds i32, ptr %60, i64 %22
  store i32 %18, ptr %61, align 4, !tbaa !17
  %62 = getelementptr inbounds i8, ptr %60, i64 %1
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge29.loopexit.unr-lcssa, label %.preheader, !llvm.loop !14

._crit_edge29.loopexit.unr-lcssa:                 ; preds = %.preheader, %.preheader.preheader
  %.02327.unr = phi ptr [ %0, %.preheader.preheader ], [ %62, %.preheader ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge29, label %.preheader.epil

.preheader.epil:                                  ; preds = %._crit_edge29.loopexit.unr-lcssa, %.preheader.epil
  %.02327.epil = phi ptr [ %64, %.preheader.epil ], [ %.02327.unr, %._crit_edge29.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.preheader.epil ], [ 0, %._crit_edge29.loopexit.unr-lcssa ]
  %63 = getelementptr inbounds i32, ptr %.02327.epil, i64 %22
  store i32 %18, ptr %63, align 4, !tbaa !17
  %64 = getelementptr inbounds i8, ptr %.02327.epil, i64 %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_edge29, label %.preheader.epil, !llvm.loop !19

._crit_edge29:                                    ; preds = %._crit_edge.us, %._crit_edge.us.us, %._crit_edge29.loopexit.unr-lcssa, %.preheader.epil, %.preheader.lr.ph.split, %8
  ret void
}

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

attributes #0 = { alwaysinline 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 #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" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10, !11, !12}
!16 = distinct !{!16, !10, !12, !11}
!17 = !{!18, !18, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.unroll.disable"}


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