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

; 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"

%"struct.Simd::View" = type <{ i64, i64, i64, i32, [4 x i8], ptr, i8, [7 x i8] }>

@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [10 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Test14FillRandomMaskERN4Simd4ViewINS0_9AllocatorEEEh = external hidden unnamed_addr constant [43 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4Simd4ViewINS_9AllocatorEE9PixelSizeENS2_6FormatE(i32 noundef) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Test14FillRandomMaskERN4Simd4ViewINS0_9AllocatorEEEh(ptr noundef nonnull align 8 dereferenceable(41) %0, i8 noundef zeroext %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %"struct.Simd::View", ptr %11, i32 0, i32 5
  %13 = load ptr, ptr %12, align 8, !tbaa !10
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  br label %18

16:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 288, ptr noundef @__PRETTY_FUNCTION__._ZN4Test14FillRandomMaskERN4Simd4ViewINS0_9AllocatorEEEh) #4
  unreachable

17:                                               ; No predecessors!
  br label %18

18:                                               ; preds = %17, %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.Simd::View", ptr %19, i32 0, i32 0
  %21 = load i64, ptr %20, align 8, !tbaa !15
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %"struct.Simd::View", ptr %22, i32 0, i32 3
  %24 = load i32, ptr %23, align 8, !tbaa !16
  %25 = call noundef i64 @_ZN4Simd4ViewINS_9AllocatorEE9PixelSizeENS2_6FormatE(i32 noundef %24)
  %26 = mul i64 %21, %25
  store i64 %26, ptr %5, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 0, ptr %6, align 8, !tbaa !17
  br label %27

27:                                               ; preds = %72, %18
  %28 = load i64, ptr %6, align 8, !tbaa !17
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.Simd::View", ptr %29, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !18
  %32 = icmp ult i64 %28, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %27
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %75

34:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %35 = load i64, ptr %6, align 8, !tbaa !17
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %"struct.Simd::View", ptr %36, i32 0, i32 2
  %38 = load i64, ptr %37, align 8, !tbaa !19
  %39 = mul i64 %35, %38
  store i64 %39, ptr %8, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %40 = call noundef ptr @_ZN4Test6Rand8uEv()
  store ptr %40, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store i64 0, ptr %10, align 8, !tbaa !17
  br label %41

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

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

46:                                               ; preds = %41
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = load i64, ptr %10, align 8, !tbaa !17
  %49 = getelementptr inbounds i8, ptr %47, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !9
  %51 = zext i8 %50 to i32
  %52 = and i32 %51, 1
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %57

54:                                               ; preds = %46
  %55 = load i8, ptr %4, align 1, !tbaa !9
  %56 = zext i8 %55 to i32
  br label %58

57:                                               ; preds = %46
  br label %58

58:                                               ; preds = %57, %54
  %59 = phi i32 [ %56, %54 ], [ 0, %57 ]
  %60 = trunc i32 %59 to i8
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %"struct.Simd::View", ptr %61, i32 0, i32 5
  %63 = load ptr, ptr %62, align 8, !tbaa !10
  %64 = load i64, ptr %8, align 8, !tbaa !17
  %65 = getelementptr inbounds i8, ptr %63, i64 %64
  store i8 %60, ptr %65, align 1, !tbaa !9
  br label %66

66:                                               ; preds = %58
  %67 = load i64, ptr %10, align 8, !tbaa !17
  %68 = add i64 %67, 1
  store i64 %68, ptr %10, align 8, !tbaa !17
  %69 = load i64, ptr %8, align 8, !tbaa !17
  %70 = add nsw i64 %69, 1
  store i64 %70, ptr %8, align 8, !tbaa !17
  br label %41, !llvm.loop !20

71:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %72

72:                                               ; preds = %71
  %73 = load i64, ptr %6, align 8, !tbaa !17
  %74 = add i64 %73, 1
  store i64 %74, ptr %6, align 8, !tbaa !17
  br label %27, !llvm.loop !22

75:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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 = { 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 #3 = { 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 #4 = { noreturn nounwind }
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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 32}
!11 = !{!"_ZTSN4Simd4ViewINS_9AllocatorEEE", !12, i64 0, !12, i64 8, !12, i64 16, !13, i64 24, !6, i64 32, !14, i64 40}
!12 = !{!"long", !7, i64 0}
!13 = !{!"_ZTSN4Simd4ViewINS_9AllocatorEE6FormatE", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!11, !12, i64 0}
!16 = !{!11, !13, i64 24}
!17 = !{!12, !12, i64 0}
!18 = !{!11, !12, i64 8}
!19 = !{!11, !12, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


; 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"

@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [10 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Test14FillRandomMaskERN4Simd4ViewINS0_9AllocatorEEEh = external hidden unnamed_addr constant [43 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4Simd4ViewINS_9AllocatorEE9PixelSizeENS2_6FormatE(i32 noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4Test14FillRandomMaskERN4Simd4ViewINS0_9AllocatorEEEh(ptr nocapture noundef nonnull readonly align 8 dereferenceable(41) %0, i8 noundef zeroext %1) local_unnamed_addr #2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %5, label %6

5:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 288, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4Test14FillRandomMaskERN4Simd4ViewINS0_9AllocatorEEEh) #3
  unreachable

6:                                                ; preds = %2
  %7 = load i64, ptr %0, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load i32, ptr %8, align 8, !tbaa !14
  %10 = tail call noundef i64 @_ZN4Simd4ViewINS_9AllocatorEE9PixelSizeENS2_6FormatE(i32 noundef %9)
  %.fr = freeze i64 %7
  %11 = mul i64 %10, %.fr
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load i64, ptr %12, align 8, !tbaa !15
  %.not25 = icmp eq i64 %13, 0
  br i1 %.not25, label %._crit_edge24, label %.lr.ph23

.lr.ph23:                                         ; preds = %6
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %.not27 = icmp eq i64 %11, 0
  br i1 %.not27, label %.lr.ph23.split, label %.lr.ph.us.preheader

.lr.ph.us.preheader:                              ; preds = %.lr.ph23
  %xtraiter = and i64 %11, 1
  %15 = icmp eq i64 %11, 1
  %unroll_iter = and i64 %11, -2
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.01621.us = phi i64 [ %38, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %16 = load i64, ptr %14, align 8, !tbaa !16
  %17 = mul i64 %16, %.01621.us
  %18 = tail call noundef ptr @_ZN4Test6Rand8uEv()
  br i1 %15, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new

.lr.ph.us.new:                                    ; preds = %.lr.ph.us, %.lr.ph.us.new
  %.020.us = phi i64 [ %31, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %.01719.us = phi i64 [ %32, %.lr.ph.us.new ], [ %17, %.lr.ph.us ]
  %niter = phi i64 [ %niter.next.1, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %19 = getelementptr inbounds i8, ptr %18, i64 %.020.us
  %20 = load i8, ptr %19, align 1, !tbaa !17
  %21 = and i8 %20, 1
  %.not18.us = icmp eq i8 %21, 0
  %narrow.us = select i1 %.not18.us, i8 0, i8 %1
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 %.01719.us
  store i8 %narrow.us, ptr %23, align 1, !tbaa !17
  %24 = or disjoint i64 %.020.us, 1
  %25 = getelementptr inbounds i8, ptr %18, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !17
  %27 = and i8 %26, 1
  %.not18.us.1 = icmp eq i8 %27, 0
  %narrow.us.1 = select i1 %.not18.us.1, i8 0, i8 %1
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr i8, ptr %28, i64 %.01719.us
  %30 = getelementptr i8, ptr %29, i64 1
  store i8 %narrow.us.1, ptr %30, align 1, !tbaa !17
  %31 = add nuw i64 %.020.us, 2
  %32 = add nsw i64 %.01719.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 %.lr.ph.us.new, !llvm.loop !18

._crit_edge.us.unr-lcssa:                         ; preds = %.lr.ph.us.new, %.lr.ph.us
  %.020.us.unr = phi i64 [ 0, %.lr.ph.us ], [ %31, %.lr.ph.us.new ]
  %.01719.us.unr = phi i64 [ %17, %.lr.ph.us ], [ %32, %.lr.ph.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %33 = getelementptr inbounds i8, ptr %18, i64 %.020.us.unr
  %34 = load i8, ptr %33, align 1, !tbaa !17
  %35 = and i8 %34, 1
  %.not18.us.epil = icmp eq i8 %35, 0
  %narrow.us.epil = select i1 %.not18.us.epil, i8 0, i8 %1
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 %.01719.us.unr
  store i8 %narrow.us.epil, ptr %37, align 1, !tbaa !17
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %38 = add nuw i64 %.01621.us, 1
  %39 = load i64, ptr %12, align 8, !tbaa !15
  %40 = icmp ult i64 %38, %39
  br i1 %40, label %.lr.ph.us, label %._crit_edge24, !llvm.loop !20

._crit_edge24:                                    ; preds = %._crit_edge.us, %.lr.ph23.split, %6
  ret void

.lr.ph23.split:                                   ; preds = %.lr.ph23, %.lr.ph23.split
  %.01621 = phi i64 [ %42, %.lr.ph23.split ], [ 0, %.lr.ph23 ]
  %41 = tail call noundef ptr @_ZN4Test6Rand8uEv()
  %42 = add nuw i64 %.01621, 1
  %43 = load i64, ptr %12, align 8, !tbaa !15
  %44 = icmp ult i64 %42, %43
  br i1 %44, label %.lr.ph23.split, label %._crit_edge24, !llvm.loop !20
}

attributes #0 = { noreturn nounwind "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 = { 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 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 #3 = { noreturn 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, !11, i64 32}
!6 = !{!"_ZTSN4Simd4ViewINS_9AllocatorEEE", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !11, i64 32, !12, i64 40}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN4Simd4ViewINS_9AllocatorEE6FormatE", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !10, i64 24}
!15 = !{!6, !7, i64 8}
!16 = !{!6, !7, i64 16}
!17 = !{!8, !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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