; LLVM IR from stan-dev/math :: lib/tbb_2020.3/src/test/test_blocked_range.ll (Z12ParallelTestv)

; 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.tbb::blocked_range" = type { i32, i32, i64 }
%struct.Striker = type { i8 }

@Array = external dso_local global [4194304 x i8], align 16
@.str.17 = external hidden unnamed_addr constant [94 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [16 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: mustprogress uwtable
declare dso_local void @_Z11ReportErrorPKciS0_S0_(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z12ParallelTestv() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca %"class.tbb::blocked_range", align 8
  %4 = alloca %struct.Striker, align 1
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %46, %0
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 4194304
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %48

10:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #3
  %11 = load i32, ptr %1, align 4, !tbaa !5
  call void @_ZN3tbb13blocked_rangeIiEC2Eiim(ptr noundef nonnull align 8 dereferenceable(16) %3, i32 noundef 0, i32 noundef %11, i64 noundef 10)
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  call void @_ZN3tbb12parallel_forINS_13blocked_rangeIiEE7StrikerEEvRKT_RKT0_(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull align 1 dereferenceable(1) %4)
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %33, %10
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = icmp slt i32 %13, 4194304
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %36

16:                                               ; preds = %12
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [4194304 x i8], ptr @Array, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = zext i8 %20 to i32
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = icmp slt i32 %22, %23
  %25 = zext i1 %24 to i32
  %26 = icmp eq i32 %21, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %16
  br label %29

28:                                               ; preds = %16
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.17, i32 noundef 101, ptr noundef @.str.18, ptr noundef null)
  br label %29

29:                                               ; preds = %28, %27
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [4194304 x i8], ptr @Array, i64 0, i64 %31
  store i8 0, ptr %32, align 1, !tbaa !9
  br label %33

33:                                               ; preds = %29
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %5, align 4, !tbaa !5
  br label %12, !llvm.loop !10

36:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #3
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %1, align 4, !tbaa !5
  %39 = icmp slt i32 %38, 3
  br i1 %39, label %40, label %43

40:                                               ; preds = %37
  %41 = load i32, ptr %1, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  br label %46

43:                                               ; preds = %37
  %44 = load i32, ptr %1, align 4, !tbaa !5
  %45 = mul nsw i32 %44, 3
  br label %46

46:                                               ; preds = %43, %40
  %47 = phi i32 [ %42, %40 ], [ %45, %43 ]
  store i32 %47, ptr %1, align 4, !tbaa !5
  br label %6, !llvm.loop !12

48:                                               ; preds = %9
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3tbb13blocked_rangeIiEC2Eiim(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef, i64 noundef) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3tbb12parallel_forINS_13blocked_rangeIiEE7StrikerEEvRKT_RKT0_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 1 dereferenceable(1)) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

%"class.tbb::blocked_range" = type { i32, i32, i64 }
%struct.Striker = type { i8 }

@Array = external dso_local local_unnamed_addr global [4194304 x i8], align 16
@.str.17 = external hidden unnamed_addr constant [94 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [16 x i8], align 1

; 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: mustprogress uwtable
declare dso_local void @_Z11ReportErrorPKciS0_S0_(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z12ParallelTestv() local_unnamed_addr #1 {
  %1 = alloca %"class.tbb::blocked_range", align 8
  %2 = alloca %struct.Striker, align 1
  br label %4

3:                                                ; preds = %6
  ret void

4:                                                ; preds = %0, %6
  %.01113 = phi i32 [ 0, %0 ], [ %10, %6 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #3
  call void @_ZN3tbb13blocked_rangeIiEC2Eiim(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef 0, i32 noundef %.01113, i64 noundef 10)
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2) #3
  call void @_ZN3tbb12parallel_forINS_13blocked_rangeIiEE7StrikerEEvRKT_RKT0_(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 1 dereferenceable(1) %2)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #3
  %5 = sext i32 %.01113 to i64
  br label %12

6:                                                ; preds = %19
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #3
  %7 = icmp slt i32 %.01113, 3
  %8 = add nsw i32 %.01113, 1
  %9 = mul nsw i32 %.01113, 3
  %10 = select i1 %7, i32 %8, i32 %9
  %11 = icmp slt i32 %10, 4194304
  br i1 %11, label %4, label %3, !llvm.loop !5

12:                                               ; preds = %4, %19
  %indvars.iv = phi i64 [ 0, %4 ], [ %indvars.iv.next, %19 ]
  %13 = getelementptr inbounds [4194304 x i8], ptr @Array, i64 0, i64 %indvars.iv
  %14 = load i8, ptr %13, align 1, !tbaa !7
  %15 = icmp slt i64 %indvars.iv, %5
  %16 = zext i1 %15 to i8
  %17 = icmp eq i8 %14, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %12
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.17, i32 noundef 101, ptr noundef nonnull @.str.18, ptr noundef null)
  br label %19

19:                                               ; preds = %12, %18
  store i8 0, ptr %13, align 1, !tbaa !7
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 4194304
  br i1 %exitcond.not, label %6, label %12, !llvm.loop !10
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3tbb13blocked_rangeIiEC2Eiim(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef, i64 noundef) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3tbb12parallel_forINS_13blocked_rangeIiEE7StrikerEEvRKT_RKT0_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = distinct !{!10, !6}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass