; LLVM IR from stan-dev/math :: lib/tbb_2020.3/src/old/test_mutex_v2.ll (Z8TestMainv)

; 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::task_scheduler_init" = type { ptr }

@_ZL9MinThread = external hidden global i32, align 4
@_ZL9MaxThread = external hidden global i32, align 4
@_ZL7Verbose = external hidden global i8, align 1
@.str.17 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [44 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
define dso_local noundef i32 @_Z8TestMainv() #1 personality ptr @__gxx_personality_v0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca %"class.tbb::task_scheduler_init", align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  %8 = load i32, ptr @_ZL9MinThread, align 4, !tbaa !5
  store i32 %8, ptr %1, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %53, %0
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = load i32, ptr @_ZL9MaxThread, align 4, !tbaa !5
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %15 = load i32, ptr %1, align 4, !tbaa !5
  call void @_ZN3tbb19task_scheduler_initC2Eim(ptr noundef nonnull align 8 dereferenceable(8) %3, i32 noundef %15, i64 noundef 0)
  %16 = load i8, ptr @_ZL7Verbose, align 1, !tbaa !9, !range !11, !noundef !12
  %17 = trunc i8 %16 to i1
  br i1 %17, label %18, label %26

18:                                               ; preds = %14
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = invoke i32 (ptr, ...) @printf(ptr noundef @.str.17, i32 noundef %19)
          to label %21 unwind label %22

21:                                               ; preds = %18
  br label %26

22:                                               ; preds = %18
  %23 = landingpad { ptr, i32 }
          cleanup
  %24 = extractvalue { ptr, i32 } %23, 0
  store ptr %24, ptr %4, align 8
  %25 = extractvalue { ptr, i32 } %23, 1
  store i32 %25, ptr %5, align 4
  br label %57

26:                                               ; preds = %21, %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 3, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %35, %26
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = icmp slt i32 %28, 3
  br i1 %29, label %31, label %30

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

31:                                               ; preds = %27
  invoke void @_Z4TestIN3tbb13spin_rw_mutexEEvPKc(ptr noundef @.str.18)
          to label %32 unwind label %38

32:                                               ; preds = %31
  invoke void @_Z24TestTryAcquire_OneThreadIN3tbb13spin_rw_mutexEEvPKc(ptr noundef @.str.18)
          to label %33 unwind label %38

33:                                               ; preds = %32
  invoke void @_Z20TestReaderWriterLockIN3tbb13spin_rw_mutexEEvPKc(ptr noundef @.str.18)
          to label %34 unwind label %38

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %7, align 4, !tbaa !5
  br label %27, !llvm.loop !13

38:                                               ; preds = %33, %32, %31
  %39 = landingpad { ptr, i32 }
          cleanup
  %40 = extractvalue { ptr, i32 } %39, 0
  store ptr %40, ptr %4, align 8
  %41 = extractvalue { ptr, i32 } %39, 1
  store i32 %41, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %56

42:                                               ; preds = %30
  %43 = load i8, ptr @_ZL7Verbose, align 1, !tbaa !9, !range !11, !noundef !12
  %44 = trunc i8 %43 to i1
  br i1 %44, label %45, label %52

45:                                               ; preds = %42
  %46 = invoke i32 (ptr, ...) @printf(ptr noundef @.str.19)
          to label %47 unwind label %48

47:                                               ; preds = %45
  br label %52

48:                                               ; preds = %45
  %49 = landingpad { ptr, i32 }
          cleanup
  %50 = extractvalue { ptr, i32 } %49, 0
  store ptr %50, ptr %4, align 8
  %51 = extractvalue { ptr, i32 } %49, 1
  store i32 %51, ptr %5, align 4
  br label %56

52:                                               ; preds = %47, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @_ZN3tbb19task_scheduler_initD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %1, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %1, align 4, !tbaa !5
  br label %9, !llvm.loop !15

56:                                               ; preds = %48, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %57

57:                                               ; preds = %56, %22
  call void @_ZN3tbb19task_scheduler_initD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  br label %59

58:                                               ; preds = %13
  ret i32 0

59:                                               ; preds = %57
  %60 = load ptr, ptr %4, align 8
  %61 = load i32, ptr %5, align 4
  %62 = insertvalue { ptr, i32 } poison, ptr %60, 0
  %63 = insertvalue { ptr, i32 } %62, i32 %61, 1
  resume { ptr, i32 } %63
}

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

declare i32 @printf(ptr noundef, ...) #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4TestIN3tbb13spin_rw_mutexEEvPKc(ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z24TestTryAcquire_OneThreadIN3tbb13spin_rw_mutexEEvPKc(ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z20TestReaderWriterLockIN3tbb13spin_rw_mutexEEvPKc(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3tbb19task_scheduler_initD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3 align 2

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 = { "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 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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::task_scheduler_init" = type { ptr }

@_ZL9MinThread = external hidden local_unnamed_addr global i32, align 4
@_ZL9MaxThread = external hidden local_unnamed_addr global i32, align 4
@_ZL7Verbose = external hidden local_unnamed_addr global i8, align 1
@.str.17 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [44 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
define dso_local noundef i32 @_Z8TestMainv() local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %1 = alloca %"class.tbb::task_scheduler_init", align 8
  %2 = load i32, ptr @_ZL9MinThread, align 4, !tbaa !5
  %3 = load i32, ptr @_ZL9MaxThread, align 4, !tbaa !5
  %.not9 = icmp sgt i32 %2, %3
  br i1 %.not9, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %24, %0
  ret i32 0

.lr.ph:                                           ; preds = %0, %24
  %.0710 = phi i32 [ %25, %24 ], [ %2, %0 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  call void @_ZN3tbb19task_scheduler_initC2Eim(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %.0710, i64 noundef 0)
  %4 = load i8, ptr @_ZL7Verbose, align 1, !tbaa !9, !range !11, !noundef !12
  %5 = trunc nuw i8 %4 to i1
  br i1 %5, label %6, label %8

6:                                                ; preds = %.lr.ph
  %7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.17, i32 noundef %.0710)
  br label %8

8:                                                ; preds = %6, %.lr.ph
  invoke void @_Z4TestIN3tbb13spin_rw_mutexEEvPKc(ptr noundef nonnull @.str.18)
          to label %9 unwind label %20

9:                                                ; preds = %8
  invoke void @_Z24TestTryAcquire_OneThreadIN3tbb13spin_rw_mutexEEvPKc(ptr noundef nonnull @.str.18)
          to label %10 unwind label %20

10:                                               ; preds = %9
  invoke void @_Z20TestReaderWriterLockIN3tbb13spin_rw_mutexEEvPKc(ptr noundef nonnull @.str.18)
          to label %11 unwind label %20

11:                                               ; preds = %10
  invoke void @_Z4TestIN3tbb13spin_rw_mutexEEvPKc(ptr noundef nonnull @.str.18)
          to label %12 unwind label %20

12:                                               ; preds = %11
  invoke void @_Z24TestTryAcquire_OneThreadIN3tbb13spin_rw_mutexEEvPKc(ptr noundef nonnull @.str.18)
          to label %13 unwind label %20

13:                                               ; preds = %12
  invoke void @_Z20TestReaderWriterLockIN3tbb13spin_rw_mutexEEvPKc(ptr noundef nonnull @.str.18)
          to label %14 unwind label %20

14:                                               ; preds = %13
  invoke void @_Z4TestIN3tbb13spin_rw_mutexEEvPKc(ptr noundef nonnull @.str.18)
          to label %15 unwind label %20

15:                                               ; preds = %14
  invoke void @_Z24TestTryAcquire_OneThreadIN3tbb13spin_rw_mutexEEvPKc(ptr noundef nonnull @.str.18)
          to label %16 unwind label %20

16:                                               ; preds = %15
  invoke void @_Z20TestReaderWriterLockIN3tbb13spin_rw_mutexEEvPKc(ptr noundef nonnull @.str.18)
          to label %17 unwind label %20

17:                                               ; preds = %16
  %18 = load i8, ptr @_ZL7Verbose, align 1, !tbaa !9, !range !11, !noundef !12
  %19 = trunc nuw i8 %18 to i1
  br i1 %19, label %22, label %24

20:                                               ; preds = %16, %15, %14, %13, %12, %11, %10, %9, %8
  %21 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN3tbb19task_scheduler_initD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %1) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  resume { ptr, i32 } %21

22:                                               ; preds = %17
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.19)
  br label %24

24:                                               ; preds = %22, %17
  call void @_ZN3tbb19task_scheduler_initD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %1) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  %25 = add nsw i32 %.0710, 1
  %26 = load i32, ptr @_ZL9MaxThread, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.0710, %26
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4TestIN3tbb13spin_rw_mutexEEvPKc(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z24TestTryAcquire_OneThreadIN3tbb13spin_rw_mutexEEvPKc(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z20TestReaderWriterLockIN3tbb13spin_rw_mutexEEvPKc(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3tbb19task_scheduler_initD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3 align 2

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 = { nofree 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 #3 = { 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass