; LLVM IR from stan-dev/math :: lib/tbb_2020.3/src/test/test_blocked_range2d.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_range2d" = type { %"class.tbb::blocked_range", %"class.tbb::blocked_range" }
%"class.tbb::blocked_range" = type { i32, i32, i64 }
%struct.Striker = type { i8 }

@Array = external dso_local global [1024 x [1024 x i8]], align 16
@.str.17 = external hidden unnamed_addr constant [96 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [26 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 i32, align 4
  %4 = alloca %"class.tbb::blocked_range2d", align 8
  %5 = alloca %struct.Striker, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %87, %0
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 1024
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %75, %12
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = icmp slt i32 %14, 1024
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 32, ptr %4) #2
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = load i32, ptr %3, align 4, !tbaa !5
  call void @_ZN3tbb15blocked_range2dIiiEC2Eiimiim(ptr noundef nonnull align 8 dereferenceable(32) %4, i32 noundef 0, i32 noundef %18, i64 noundef 7, i32 noundef 0, i32 noundef %19, i64 noundef 5)
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #2
  call void @_ZN3tbb12parallel_forINS_15blocked_range2dIiiEE7StrikerEEvRKT_RKT0_(ptr noundef nonnull align 8 dereferenceable(32) %4, ptr noundef nonnull align 1 dereferenceable(1) %5)
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %62, %17
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = icmp slt i32 %21, 1024
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  store i32 8, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %65

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %58, %24
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = icmp slt i32 %26, 1024
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  store i32 11, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %61

29:                                               ; preds = %25
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1024 x [1024 x i8]], ptr @Array, i64 0, i64 %31
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1024 x i8], ptr %32, i64 0, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !9
  %37 = zext i8 %36 to i32
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = load i32, ptr %1, align 4, !tbaa !5
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %41, label %45

41:                                               ; preds = %29
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = icmp slt i32 %42, %43
  br label %45

45:                                               ; preds = %41, %29
  %46 = phi i1 [ false, %29 ], [ %44, %41 ]
  %47 = zext i1 %46 to i32
  %48 = icmp eq i32 %37, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %45
  br label %51

50:                                               ; preds = %45
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.17, i32 noundef 127, ptr noundef @.str.18, ptr noundef null)
  br label %51

51:                                               ; preds = %50, %49
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [1024 x [1024 x i8]], ptr @Array, i64 0, i64 %53
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1024 x i8], ptr %54, i64 0, i64 %56
  store i8 0, ptr %57, align 1, !tbaa !9
  br label %58

58:                                               ; preds = %51
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %7, align 4, !tbaa !5
  br label %25, !llvm.loop !10

61:                                               ; preds = %28
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %6, align 4, !tbaa !5
  br label %20, !llvm.loop !12

65:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 32, ptr %4) #2
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %3, align 4, !tbaa !5
  %68 = icmp slt i32 %67, 3
  br i1 %68, label %69, label %72

69:                                               ; preds = %66
  %70 = load i32, ptr %3, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  br label %75

72:                                               ; preds = %66
  %73 = load i32, ptr %3, align 4, !tbaa !5
  %74 = mul nsw i32 %73, 3
  br label %75

75:                                               ; preds = %72, %69
  %76 = phi i32 [ %71, %69 ], [ %74, %72 ]
  store i32 %76, ptr %3, align 4, !tbaa !5
  br label %13, !llvm.loop !13

77:                                               ; preds = %16
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %1, align 4, !tbaa !5
  %80 = icmp slt i32 %79, 3
  br i1 %80, label %81, label %84

81:                                               ; preds = %78
  %82 = load i32, ptr %1, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  br label %87

84:                                               ; preds = %78
  %85 = load i32, ptr %1, align 4, !tbaa !5
  %86 = mul nsw i32 %85, 3
  br label %87

87:                                               ; preds = %84, %81
  %88 = phi i32 [ %83, %81 ], [ %86, %84 ]
  store i32 %88, ptr %1, align 4, !tbaa !5
  br label %8, !llvm.loop !14

89:                                               ; preds = %11
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3tbb12parallel_forINS_15blocked_range2dIiiEE7StrikerEEvRKT_RKT0_(ptr noundef nonnull align 8 dereferenceable(32), 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 = { 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}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !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_range2d" = type { %"class.tbb::blocked_range", %"class.tbb::blocked_range" }
%"class.tbb::blocked_range" = type { i32, i32, i64 }
%struct.Striker = type { i8 }

@Array = external dso_local local_unnamed_addr global [1024 x [1024 x i8]], align 16
@.str.17 = external hidden unnamed_addr constant [96 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [26 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_range2d", align 8
  %2 = alloca %struct.Striker, align 1
  br label %.preheader25

.preheader25:                                     ; preds = %0, %5
  %.02429 = phi i32 [ 0, %0 ], [ %9, %5 ]
  %3 = sext i32 %.02429 to i64
  br label %11

4:                                                ; preds = %5
  ret void

5:                                                ; preds = %14
  %6 = icmp slt i32 %.02429, 3
  %7 = add nsw i32 %.02429, 1
  %8 = mul nsw i32 %.02429, 3
  %9 = select i1 %6, i32 %7, i32 %8
  %10 = icmp slt i32 %9, 1024
  br i1 %10, label %.preheader25, label %4, !llvm.loop !5

11:                                               ; preds = %.preheader25, %14
  %.02328 = phi i32 [ 0, %.preheader25 ], [ %18, %14 ]
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %1) #2
  call void @_ZN3tbb15blocked_range2dIiiEC2Eiimiim(ptr noundef nonnull align 8 dereferenceable(32) %1, i32 noundef 0, i32 noundef %.02429, i64 noundef 7, i32 noundef 0, i32 noundef %.02328, i64 noundef 5)
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2) #2
  call void @_ZN3tbb12parallel_forINS_15blocked_range2dIiiEE7StrikerEEvRKT_RKT0_(ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 1 dereferenceable(1) %2)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #2
  %12 = sext i32 %.02328 to i64
  br label %.preheader

.preheader:                                       ; preds = %11, %20
  %indvars.iv31 = phi i64 [ 0, %11 ], [ %indvars.iv.next32, %20 ]
  %13 = icmp slt i64 %indvars.iv31, %3
  br label %21

14:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %1) #2
  %15 = icmp slt i32 %.02328, 3
  %16 = add nsw i32 %.02328, 1
  %17 = mul nsw i32 %.02328, 3
  %18 = select i1 %15, i32 %16, i32 %17
  %19 = icmp slt i32 %18, 1024
  br i1 %19, label %11, label %5, !llvm.loop !7

20:                                               ; preds = %29
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %exitcond34.not = icmp eq i64 %indvars.iv.next32, 1024
  br i1 %exitcond34.not, label %14, label %.preheader, !llvm.loop !8

21:                                               ; preds = %.preheader, %29
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %29 ]
  %22 = getelementptr inbounds [1024 x [1024 x i8]], ptr @Array, i64 0, i64 %indvars.iv31, i64 %indvars.iv
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = icmp slt i64 %indvars.iv, %12
  %25 = and i1 %13, %24
  %26 = zext i1 %25 to i8
  %27 = icmp eq i8 %23, %26
  br i1 %27, label %29, label %28

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

29:                                               ; preds = %21, %28
  store i8 0, ptr %22, align 1, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 1024
  br i1 %exitcond.not, label %20, label %21, !llvm.loop !12
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3tbb12parallel_forINS_15blocked_range2dIiiEE7StrikerEEvRKT_RKT0_(ptr noundef nonnull align 8 dereferenceable(32), 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 = { 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 = distinct !{!7, !6}
!8 = distinct !{!8, !6}
!9 = !{!10, !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = distinct !{!12, !6}


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