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

; 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 @_ZN4Simd4Base6FillUvEPhmmmhh(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i8 noundef zeroext %4, i8 noundef zeroext %5) #2 {
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i8, align 1
  %12 = alloca i8, align 1
  %13 = alloca i16, align 2
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i64 %3, ptr %10, align 8, !tbaa !9
  store i8 %4, ptr %11, align 1, !tbaa !11
  store i8 %5, ptr %12, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %13) #3
  %18 = load i8, ptr %11, align 1, !tbaa !11
  %19 = zext i8 %18 to i32
  %20 = load i8, ptr %12, align 1, !tbaa !11
  %21 = zext i8 %20 to i32
  %22 = shl i32 %21, 8
  %23 = or i32 %19, %22
  %24 = trunc i32 %23 to i16
  store i16 %24, ptr %13, align 2, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %25 = load i16, ptr %13, align 2, !tbaa !12
  %26 = zext i16 %25 to i64
  %27 = load i16, ptr %13, align 2, !tbaa !12
  %28 = zext i16 %27 to i64
  %29 = shl i64 %28, 16
  %30 = or i64 %26, %29
  %31 = load i16, ptr %13, align 2, !tbaa !12
  %32 = zext i16 %31 to i64
  %33 = shl i64 %32, 32
  %34 = or i64 %30, %33
  %35 = load i16, ptr %13, align 2, !tbaa !12
  %36 = zext i16 %35 to i64
  %37 = shl i64 %36, 48
  %38 = or i64 %34, %37
  store i64 %38, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %39 = load i64, ptr %9, align 8, !tbaa !9
  %40 = call noundef i64 @_ZN4Simd7AlignLoEmm(i64 noundef %39, i64 noundef 4)
  store i64 %40, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  store i64 0, ptr %16, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %76, %6
  %42 = load i64, ptr %16, align 8, !tbaa !9
  %43 = load i64, ptr %10, align 8, !tbaa !9
  %44 = icmp ult i64 %42, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %79

46:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  store i64 0, ptr %17, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %56, %46
  %48 = load i64, ptr %17, align 8, !tbaa !9
  %49 = load i64, ptr %15, align 8, !tbaa !9
  %50 = icmp ult i64 %48, %49
  br i1 %50, label %51, label %59

51:                                               ; preds = %47
  %52 = load i64, ptr %14, align 8, !tbaa !9
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load i64, ptr %17, align 8, !tbaa !9
  %55 = getelementptr inbounds i16, ptr %53, i64 %54
  store i64 %52, ptr %55, align 8, !tbaa !9
  br label %56

56:                                               ; preds = %51
  %57 = load i64, ptr %17, align 8, !tbaa !9
  %58 = add i64 %57, 4
  store i64 %58, ptr %17, align 8, !tbaa !9
  br label %47, !llvm.loop !14

59:                                               ; preds = %47
  br label %60

60:                                               ; preds = %69, %59
  %61 = load i64, ptr %17, align 8, !tbaa !9
  %62 = load i64, ptr %9, align 8, !tbaa !9
  %63 = icmp ult i64 %61, %62
  br i1 %63, label %64, label %72

64:                                               ; preds = %60
  %65 = load i16, ptr %13, align 2, !tbaa !12
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = load i64, ptr %17, align 8, !tbaa !9
  %68 = getelementptr inbounds i16, ptr %66, i64 %67
  store i16 %65, ptr %68, align 2, !tbaa !12
  br label %69

69:                                               ; preds = %64
  %70 = load i64, ptr %17, align 8, !tbaa !9
  %71 = add i64 %70, 1
  store i64 %71, ptr %17, align 8, !tbaa !9
  br label %60, !llvm.loop !16

72:                                               ; preds = %60
  %73 = load i64, ptr %8, align 8, !tbaa !9
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds i8, ptr %74, i64 %73
  store ptr %75, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  br label %76

76:                                               ; preds = %72
  %77 = load i64, ptr %16, align 8, !tbaa !9
  %78 = add i64 %77, 1
  store i64 %78, ptr %16, align 8, !tbaa !9
  br label %41, !llvm.loop !17

79:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %13) #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 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !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 @_ZN4Simd4Base6FillUvEPhmmmhh(ptr nocapture noundef writeonly %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i8 noundef zeroext %4, i8 noundef zeroext %5) local_unnamed_addr #1 {
  %7 = zext i8 %4 to i16
  %8 = zext i8 %5 to i16
  %9 = shl nuw i16 %8, 8
  %10 = or disjoint i16 %9, %7
  %11 = zext i16 %10 to i64
  %12 = mul nuw i64 %11, 281479271743489
  %13 = tail call noundef i64 @_ZN4Simd7AlignLoEmm(i64 noundef %2, i64 noundef 4)
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %._crit_edge31, label %.preheader25.lr.ph

.preheader25.lr.ph:                               ; preds = %6
  %.not38 = icmp eq i64 %13, 0
  br i1 %.not38, label %.preheader25.lr.ph.split, label %.preheader25.us.preheader

.preheader25.us.preheader:                        ; preds = %.preheader25.lr.ph
  %14 = add i64 %13, -1
  %15 = and i64 %14, -4
  %16 = add i64 %15, 5
  %umax = tail call i64 @llvm.umax.i64(i64 %2, i64 %16)
  %17 = add i64 %umax, -4
  %18 = sub i64 %17, %15
  %19 = add i64 %13, -1
  %20 = lshr i64 %19, 2
  %21 = add nuw nsw i64 %20, 1
  %min.iters.check48 = icmp ult i64 %13, 13
  %n.vec51 = and i64 %21, 9223372036854775804
  %ind.end52 = shl i64 %n.vec51, 2
  %broadcast.splatinsert57 = insertelement <2 x i64> poison, i64 %12, i64 0
  %broadcast.splat58 = shufflevector <2 x i64> %broadcast.splatinsert57, <2 x i64> poison, <2 x i32> zeroinitializer
  %cmp.n60 = icmp eq i64 %21, %n.vec51
  %min.iters.check = icmp ult i64 %18, 16
  %n.vec = and i64 %18, -16
  %broadcast.splatinsert = insertelement <8 x i16> poison, i16 %10, i64 0
  %broadcast.splat = shufflevector <8 x i16> %broadcast.splatinsert, <8 x i16> poison, <8 x i32> zeroinitializer
  %cmp.n = icmp eq i64 %18, %n.vec
  br label %.preheader25.us

.preheader25.us:                                  ; preds = %.preheader25.us.preheader, %._crit_edge.us
  %.02330.us = phi i64 [ %26, %._crit_edge.us ], [ 0, %.preheader25.us.preheader ]
  %.02429.us = phi ptr [ %25, %._crit_edge.us ], [ %0, %.preheader25.us.preheader ]
  br i1 %min.iters.check48, label %scalar.ph47.preheader, label %vector.body54

scalar.ph47.preheader:                            ; preds = %middle.block46, %.preheader25.us
  %.026.us.ph = phi i64 [ 0, %.preheader25.us ], [ %ind.end52, %middle.block46 ]
  br label %scalar.ph47

vector.body54:                                    ; preds = %.preheader25.us, %vector.body54
  %index55 = phi i64 [ %index.next59, %vector.body54 ], [ 0, %.preheader25.us ]
  %.idx = shl i64 %index55, 3
  %22 = getelementptr inbounds i8, ptr %.02429.us, i64 %.idx
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  store <2 x i64> %broadcast.splat58, ptr %22, align 8, !tbaa !5
  store <2 x i64> %broadcast.splat58, ptr %23, align 8, !tbaa !5
  %index.next59 = add nuw i64 %index55, 4
  %24 = icmp eq i64 %index.next59, %n.vec51
  br i1 %24, label %middle.block46, label %vector.body54, !llvm.loop !9

middle.block46:                                   ; preds = %vector.body54
  br i1 %cmp.n60, label %..preheader_crit_edge.us, label %scalar.ph47.preheader

._crit_edge.us:                                   ; preds = %.lr.ph28.us, %middle.block, %..preheader_crit_edge.us
  %25 = getelementptr inbounds i8, ptr %.02429.us, i64 %1
  %26 = add nuw i64 %.02330.us, 1
  %exitcond.not = icmp eq i64 %26, %3
  br i1 %exitcond.not, label %._crit_edge31, label %.preheader25.us, !llvm.loop !13

.lr.ph28.us:                                      ; preds = %.lr.ph28.us.preheader74, %.lr.ph28.us
  %.127.us = phi i64 [ %28, %.lr.ph28.us ], [ %.127.us.ph, %.lr.ph28.us.preheader74 ]
  %27 = getelementptr inbounds i16, ptr %.02429.us, i64 %.127.us
  store i16 %10, ptr %27, align 2, !tbaa !14
  %28 = add nuw i64 %.127.us, 1
  %29 = icmp ult i64 %28, %2
  br i1 %29, label %.lr.ph28.us, label %._crit_edge.us, !llvm.loop !16

scalar.ph47:                                      ; preds = %scalar.ph47.preheader, %scalar.ph47
  %.026.us = phi i64 [ %31, %scalar.ph47 ], [ %.026.us.ph, %scalar.ph47.preheader ]
  %30 = getelementptr inbounds i16, ptr %.02429.us, i64 %.026.us
  store i64 %12, ptr %30, align 8, !tbaa !5
  %31 = add nuw i64 %.026.us, 4
  %32 = icmp ult i64 %31, %13
  br i1 %32, label %scalar.ph47, label %..preheader_crit_edge.us, !llvm.loop !17

..preheader_crit_edge.us:                         ; preds = %scalar.ph47, %middle.block46
  %.lcssa = phi i64 [ %ind.end52, %middle.block46 ], [ %31, %scalar.ph47 ]
  %33 = icmp ult i64 %.lcssa, %2
  br i1 %33, label %.lr.ph28.us.preheader, label %._crit_edge.us

.lr.ph28.us.preheader:                            ; preds = %..preheader_crit_edge.us
  br i1 %min.iters.check, label %.lr.ph28.us.preheader74, label %vector.ph

.lr.ph28.us.preheader74:                          ; preds = %middle.block, %.lr.ph28.us.preheader
  %.127.us.ph = phi i64 [ %.lcssa, %.lr.ph28.us.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph28.us

vector.ph:                                        ; preds = %.lr.ph28.us.preheader
  %ind.end = add i64 %.lcssa, %n.vec
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = add i64 %.lcssa, %index
  %34 = getelementptr inbounds i16, ptr %.02429.us, i64 %offset.idx
  %35 = getelementptr inbounds i8, ptr %34, i64 16
  store <8 x i16> %broadcast.splat, ptr %34, align 2, !tbaa !14
  store <8 x i16> %broadcast.splat, ptr %35, align 2, !tbaa !14
  %index.next = add nuw i64 %index, 16
  %36 = icmp eq i64 %index.next, %n.vec
  br i1 %36, label %middle.block, label %vector.body, !llvm.loop !18

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %.lr.ph28.us.preheader74

.preheader25.lr.ph.split:                         ; preds = %.preheader25.lr.ph
  %.not39 = icmp eq i64 %2, 0
  br i1 %.not39, label %._crit_edge31, label %.preheader25.us32.preheader

.preheader25.us32.preheader:                      ; preds = %.preheader25.lr.ph.split
  %min.iters.check63 = icmp ult i64 %2, 16
  %n.vec66 = and i64 %2, -16
  %broadcast.splatinsert70 = insertelement <8 x i16> poison, i16 %10, i64 0
  %broadcast.splat71 = shufflevector <8 x i16> %broadcast.splatinsert70, <8 x i16> poison, <8 x i32> zeroinitializer
  %cmp.n73 = icmp eq i64 %n.vec66, %2
  br label %.preheader25.us32

.preheader25.us32:                                ; preds = %.preheader25.us32.preheader, %._crit_edge.us37
  %.02330.us33 = phi i64 [ %43, %._crit_edge.us37 ], [ 0, %.preheader25.us32.preheader ]
  %.02429.us34 = phi ptr [ %42, %._crit_edge.us37 ], [ %0, %.preheader25.us32.preheader ]
  br i1 %min.iters.check63, label %scalar.ph62.preheader, label %vector.body68

vector.body68:                                    ; preds = %.preheader25.us32, %vector.body68
  %index69 = phi i64 [ %index.next72, %vector.body68 ], [ 0, %.preheader25.us32 ]
  %37 = getelementptr inbounds i16, ptr %.02429.us34, i64 %index69
  %38 = getelementptr inbounds i8, ptr %37, i64 16
  store <8 x i16> %broadcast.splat71, ptr %37, align 2, !tbaa !14
  store <8 x i16> %broadcast.splat71, ptr %38, align 2, !tbaa !14
  %index.next72 = add nuw i64 %index69, 16
  %39 = icmp eq i64 %index.next72, %n.vec66
  br i1 %39, label %middle.block61, label %vector.body68, !llvm.loop !19

middle.block61:                                   ; preds = %vector.body68
  br i1 %cmp.n73, label %._crit_edge.us37, label %scalar.ph62.preheader

scalar.ph62.preheader:                            ; preds = %middle.block61, %.preheader25.us32
  %.127.us35.ph = phi i64 [ 0, %.preheader25.us32 ], [ %n.vec66, %middle.block61 ]
  br label %scalar.ph62

scalar.ph62:                                      ; preds = %scalar.ph62.preheader, %scalar.ph62
  %.127.us35 = phi i64 [ %41, %scalar.ph62 ], [ %.127.us35.ph, %scalar.ph62.preheader ]
  %40 = getelementptr inbounds i16, ptr %.02429.us34, i64 %.127.us35
  store i16 %10, ptr %40, align 2, !tbaa !14
  %41 = add nuw i64 %.127.us35, 1
  %exitcond42.not = icmp eq i64 %41, %2
  br i1 %exitcond42.not, label %._crit_edge.us37, label %scalar.ph62, !llvm.loop !20

._crit_edge.us37:                                 ; preds = %scalar.ph62, %middle.block61
  %42 = getelementptr inbounds i8, ptr %.02429.us34, i64 %1
  %43 = add nuw i64 %.02330.us33, 1
  %exitcond43.not = icmp eq i64 %43, %3
  br i1 %exitcond43.not, label %._crit_edge31, label %.preheader25.us32, !llvm.loop !13

._crit_edge31:                                    ; preds = %._crit_edge.us, %._crit_edge.us37, %.preheader25.lr.ph.split, %6
  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}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = distinct !{!16, !10, !12, !11}
!17 = distinct !{!17, !10, !12, !11}
!18 = distinct !{!18, !10, !11, !12}
!19 = distinct !{!19, !10, !11, !12}
!20 = distinct !{!20, !10, !12, !11}


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