; LLVM IR from ermig1979/Simd :: src/Test/TestRandom.ll (ZN4Test10FillRandomEPfmff)

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #1

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

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef double @_ZN4Test6RandomEv() #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Test10FillRandomEPfmff(ptr noundef %0, i64 noundef %1, float noundef %2, float noundef %3) #4 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca i8, align 1
  %10 = alloca float, align 4
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store float %2, ptr %7, align 4, !tbaa !11
  store float %3, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #5
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = icmp ugt i64 %19, 100000
  %21 = zext i1 %20 to i8
  store i8 %21, ptr %9, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %22 = load float, ptr %8, align 4, !tbaa !11
  %23 = load float, ptr %7, align 4, !tbaa !11
  %24 = fsub float %22, %23
  %25 = fdiv float %24, 3.276700e+04
  store float %25, ptr %10, align 4, !tbaa !11
  %26 = load i8, ptr %9, align 1, !tbaa !13, !range !15, !noundef !16
  %27 = trunc i8 %26 to i1
  br i1 %27, label %28, label %69

28:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %65, %28
  %30 = load i64, ptr %11, align 8, !tbaa !9
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = icmp ult i64 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %68

34:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  store i64 32767, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = load i64, ptr %11, align 8, !tbaa !9
  %37 = sub i64 %35, %36
  store i64 %37, ptr %15, align 8, !tbaa !9
  %38 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %14, ptr noundef nonnull align 8 dereferenceable(8) %15)
  %39 = load i64, ptr %38, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  store i64 %39, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %40 = call noundef ptr @_ZN4Test7Rand16iEv()
  store ptr %40, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  store i64 0, ptr %17, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %61, %34
  %42 = load i64, ptr %17, align 8, !tbaa !9
  %43 = load i64, ptr %13, align 8, !tbaa !9
  %44 = icmp ult i64 %42, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  br label %64

46:                                               ; preds = %41
  %47 = load float, ptr %7, align 4, !tbaa !11
  %48 = load float, ptr %10, align 4, !tbaa !11
  %49 = load ptr, ptr %16, align 8, !tbaa !5
  %50 = load i64, ptr %17, align 8, !tbaa !9
  %51 = getelementptr inbounds i16, ptr %49, i64 %50
  %52 = load i16, ptr %51, align 2, !tbaa !17
  %53 = sext i16 %52 to i32
  %54 = sitofp i32 %53 to float
  %55 = call float @llvm.fmuladd.f32(float %48, float %54, float %47)
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = load i64, ptr %11, align 8, !tbaa !9
  %58 = load i64, ptr %17, align 8, !tbaa !9
  %59 = add i64 %57, %58
  %60 = getelementptr inbounds float, ptr %56, i64 %59
  store float %55, ptr %60, align 4, !tbaa !11
  br label %61

61:                                               ; preds = %46
  %62 = load i64, ptr %17, align 8, !tbaa !9
  %63 = add i64 %62, 1
  store i64 %63, ptr %17, align 8, !tbaa !9
  br label %41, !llvm.loop !19

64:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %65

65:                                               ; preds = %64
  %66 = load i64, ptr %11, align 8, !tbaa !9
  %67 = add i64 %66, 32767
  store i64 %67, ptr %11, align 8, !tbaa !9
  br label %29, !llvm.loop !21

68:                                               ; preds = %33
  br label %90

69:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  store i64 0, ptr %18, align 8, !tbaa !9
  br label %70

70:                                               ; preds = %86, %69
  %71 = load i64, ptr %18, align 8, !tbaa !9
  %72 = load i64, ptr %6, align 8, !tbaa !9
  %73 = icmp ult i64 %71, %72
  br i1 %73, label %75, label %74

74:                                               ; preds = %70
  store i32 8, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  br label %89

75:                                               ; preds = %70
  %76 = load float, ptr %7, align 4, !tbaa !11
  %77 = load float, ptr %8, align 4, !tbaa !11
  %78 = load float, ptr %7, align 4, !tbaa !11
  %79 = fsub float %77, %78
  %80 = call noundef double @_ZN4Test6RandomEv()
  %81 = fptrunc double %80 to float
  %82 = call float @llvm.fmuladd.f32(float %79, float %81, float %76)
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = load i64, ptr %18, align 8, !tbaa !9
  %85 = getelementptr inbounds float, ptr %83, i64 %84
  store float %82, ptr %85, align 4, !tbaa !11
  br label %86

86:                                               ; preds = %75
  %87 = load i64, ptr %18, align 8, !tbaa !9
  %88 = add i64 %87, 1
  store i64 %88, ptr %18, align 8, !tbaa !9
  br label %70, !llvm.loop !22

89:                                               ; preds = %74
  br label %90

90:                                               ; preds = %89, %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #5
  ret void
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4Test7Rand16iEv() #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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) }
attributes #3 = { 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 #4 = { 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 #5 = { 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 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!18, !18, i64 0}
!18 = !{!"short", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}
!22 = distinct !{!22, !20}


; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef double @_ZN4Test6RandomEv() local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4Test10FillRandomEPfmff(ptr nocapture noundef writeonly %0, i64 noundef %1, float noundef %2, float noundef %3) local_unnamed_addr #4 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = icmp ugt i64 %1, 100000
  %8 = fsub float %3, %2
  %9 = fdiv float %8, 3.276700e+04
  br i1 %7, label %.preheader.preheader, label %.preheader29

.preheader.preheader:                             ; preds = %4
  %broadcast.splatinsert = insertelement <4 x float> poison, float %9, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  %broadcast.splatinsert41 = insertelement <4 x float> poison, float %2, i64 0
  %broadcast.splat42 = shufflevector <4 x float> %broadcast.splatinsert41, <4 x float> poison, <4 x i32> zeroinitializer
  br label %.preheader

.preheader29:                                     ; preds = %4
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %.02734 = phi i64 [ %24, %._crit_edge ], [ 0, %.preheader.preheader ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #6
  store i64 32767, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #6
  %10 = sub i64 %1, %.02734
  store i64 %10, ptr %6, align 8, !tbaa !5
  %11 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %12 = load i64, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #6
  %13 = call noundef ptr @_ZN4Test7Rand16iEv()
  %.not35 = icmp eq i64 %12, 0
  br i1 %.not35, label %._crit_edge, label %.lr.ph33

.lr.ph33:                                         ; preds = %.preheader
  %14 = getelementptr float, ptr %0, i64 %.02734
  %min.iters.check = icmp ult i64 %12, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph33
  %.02632.ph = phi i64 [ 0, %.lr.ph33 ], [ %n.vec, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph33
  %n.vec = and i64 %12, -8
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %15 = getelementptr inbounds i16, ptr %13, i64 %index
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %wide.load = load <4 x i16>, ptr %15, align 2, !tbaa !9
  %wide.load40 = load <4 x i16>, ptr %16, align 2, !tbaa !9
  %17 = sitofp <4 x i16> %wide.load to <4 x float>
  %18 = sitofp <4 x i16> %wide.load40 to <4 x float>
  %19 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %broadcast.splat, <4 x float> %17, <4 x float> %broadcast.splat42)
  %20 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %broadcast.splat, <4 x float> %18, <4 x float> %broadcast.splat42)
  %21 = getelementptr float, ptr %14, i64 %index
  %22 = getelementptr i8, ptr %21, i64 16
  store <4 x float> %19, ptr %21, align 4, !tbaa !11
  store <4 x float> %20, ptr %22, align 4, !tbaa !11
  %index.next = add nuw i64 %index, 8
  %23 = icmp eq i64 %index.next, %n.vec
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !13

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

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %.preheader
  %24 = add i64 %.02734, 32767
  %25 = icmp ult i64 %24, %1
  br i1 %25, label %.preheader, label %.loopexit, !llvm.loop !17

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.02632 = phi i64 [ %31, %scalar.ph ], [ %.02632.ph, %scalar.ph.preheader ]
  %26 = getelementptr inbounds i16, ptr %13, i64 %.02632
  %27 = load i16, ptr %26, align 2, !tbaa !9
  %28 = sitofp i16 %27 to float
  %29 = call float @llvm.fmuladd.f32(float %9, float %28, float %2)
  %30 = getelementptr float, ptr %14, i64 %.02632
  store float %29, ptr %30, align 4, !tbaa !11
  %31 = add nuw i64 %.02632, 1
  %exitcond37.not = icmp eq i64 %31, %12
  br i1 %exitcond37.not, label %._crit_edge, label %scalar.ph, !llvm.loop !18

.lr.ph:                                           ; preds = %.preheader29, %.lr.ph
  %.031 = phi i64 [ %36, %.lr.ph ], [ 0, %.preheader29 ]
  %32 = tail call noundef double @_ZN4Test6RandomEv()
  %33 = fptrunc double %32 to float
  %34 = tail call float @llvm.fmuladd.f32(float %8, float %33, float %2)
  %35 = getelementptr inbounds float, ptr %0, i64 %.031
  store float %34, ptr %35, align 4, !tbaa !11
  %36 = add nuw i64 %.031, 1
  %exitcond.not = icmp eq i64 %36, %1
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !19

.loopexit:                                        ; preds = %.lr.ph, %._crit_edge, %.preheader29
  ret void
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4Test7Rand16iEv() local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x float> @llvm.fmuladd.v4f32(<4 x float>, <4 x float>, <4 x float>) #5

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #4 = { 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!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, !14}
!18 = distinct !{!18, !14, !16, !15}
!19 = distinct !{!19, !14}


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