; LLVM IR from Compaile/ctrack :: examples/multithreaded_prime_counter.ll (Z18countPrimesInRangeii)

; 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.ctrack::vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH::EventHandler" = type <{ %"class.std::chrono::time_point", i32, i32, %"class.std::basic_string_view", %"class.std::basic_string_view", i32, i32, i32, [4 x i8] }>
%"class.std::chrono::time_point" = type { %"class.std::chrono::duration" }
%"class.std::chrono::duration" = type { i64 }
%"class.std::basic_string_view" = type { i64, ptr }

@primeCount = external dso_local global { i32 }, align 4
@.str.19 = external hidden unnamed_addr constant [90 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [19 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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: nounwind
declare i64 @_ZNSt6chrono3_V212system_clock3nowEv() #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z7isPrimei(i32 noundef) #2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z18countPrimesInRangeii(i32 noundef %0, i32 noundef %1) #2 personality ptr @__gxx_personality_v0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %"class.ctrack::vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH::EventHandler", align 8
  %6 = alloca %"class.std::chrono::time_point", align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %5) #4
  %10 = call i64 @_ZNSt6chrono3_V212system_clock3nowEv() #4
  %11 = getelementptr inbounds %"class.std::chrono::time_point", ptr %6, i32 0, i32 0
  %12 = getelementptr inbounds %"class.std::chrono::duration", ptr %11, i32 0, i32 0
  store i64 %10, ptr %12, align 8
  %13 = getelementptr inbounds %"class.std::chrono::time_point", ptr %6, i32 0, i32 0
  %14 = getelementptr inbounds %"class.std::chrono::duration", ptr %13, i32 0, i32 0
  %15 = load i64, ptr %14, align 8
  call void @_ZN6ctrack63vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH12EventHandlerC2EiPKcS3_NSt6chrono10time_pointINS4_3_V212system_clockENS4_8durationIlSt5ratioILl1ELl1000000000EEEEEE(ptr noundef nonnull align 8 dereferenceable(60) %5, i32 noundef 20, ptr noundef @.str.19, ptr noundef @.str.21, i64 %15)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %16 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %16, ptr %7, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %33, %2
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %36

22:                                               ; preds = %17
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = invoke noundef zeroext i1 @_Z7isPrimei(i32 noundef %23)
          to label %25 unwind label %28

25:                                               ; preds = %22
  br i1 %24, label %26, label %32

26:                                               ; preds = %25
  %27 = call noundef i32 @_ZNSt13__atomic_baseIiEppEi(ptr noundef nonnull align 4 dereferenceable(4) @primeCount, i32 noundef 0) #4
  br label %32

28:                                               ; preds = %22
  %29 = landingpad { ptr, i32 }
          cleanup
  %30 = extractvalue { ptr, i32 } %29, 0
  store ptr %30, ptr %8, align 8
  %31 = extractvalue { ptr, i32 } %29, 1
  store i32 %31, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @_ZN6ctrack63vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH12EventHandlerD2Ev(ptr noundef nonnull align 8 dereferenceable(60) %5) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %5) #4
  br label %37

32:                                               ; preds = %26, %25
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %7, align 4, !tbaa !5
  br label %17, !llvm.loop !9

36:                                               ; preds = %21
  call void @_ZN6ctrack63vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH12EventHandlerD2Ev(ptr noundef nonnull align 8 dereferenceable(60) %5) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %5) #4
  ret void

37:                                               ; preds = %28
  %38 = load ptr, ptr %8, align 8
  %39 = load i32, ptr %9, align 4
  %40 = insertvalue { ptr, i32 } poison, ptr %38, 0
  %41 = insertvalue { ptr, i32 } %40, i32 %39, 1
  resume { ptr, i32 } %41
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNSt13__atomic_baseIiEppEi(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; 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.ctrack::vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH::EventHandler" = type <{ %"class.std::chrono::time_point", i32, i32, %"class.std::basic_string_view", %"class.std::basic_string_view", i32, i32, i32, [4 x i8] }>
%"class.std::chrono::time_point" = type { %"class.std::chrono::duration" }
%"class.std::chrono::duration" = type { i64 }
%"class.std::basic_string_view" = type { i64, ptr }

@primeCount = external dso_local global { i32 }, align 4
@.str.19 = external hidden unnamed_addr constant [90 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [19 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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: nounwind
declare i64 @_ZNSt6chrono3_V212system_clock3nowEv() local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z7isPrimei(i32 noundef) local_unnamed_addr #2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z18countPrimesInRangeii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %"class.ctrack::vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH::EventHandler", align 8
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #4
  %4 = tail call i64 @_ZNSt6chrono3_V212system_clock3nowEv() #4
  call void @_ZN6ctrack63vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH12EventHandlerC2EiPKcS3_NSt6chrono10time_pointINS4_3_V212system_clockENS4_8durationIlSt5ratioILl1ELl1000000000EEEEEE(ptr noundef nonnull align 8 dereferenceable(60) %3, i32 noundef 20, ptr noundef nonnull @.str.19, ptr noundef nonnull @.str.21, i64 %4)
  %.not6 = icmp sgt i32 %0, %1
  br i1 %.not6, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %11, %2
  call void @_ZN6ctrack63vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH12EventHandlerD2Ev(ptr noundef nonnull align 8 dereferenceable(60) %3) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #4
  ret void

.lr.ph:                                           ; preds = %2, %11
  %.07 = phi i32 [ %12, %11 ], [ %0, %2 ]
  %5 = invoke noundef zeroext i1 @_Z7isPrimei(i32 noundef %.07)
          to label %6 unwind label %9

6:                                                ; preds = %.lr.ph
  br i1 %5, label %7, label %11

7:                                                ; preds = %6
  %8 = call noundef i32 @_ZNSt13__atomic_baseIiEppEi(ptr noundef nonnull align 4 dereferenceable(4) @primeCount, i32 noundef 0) #4
  br label %11

9:                                                ; preds = %.lr.ph
  %10 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN6ctrack63vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH12EventHandlerD2Ev(ptr noundef nonnull align 8 dereferenceable(60) %3) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #4
  resume { ptr, i32 } %10

11:                                               ; preds = %6, %7
  %12 = add i32 %.07, 1
  %exitcond.not = icmp eq i32 %.07, %1
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNSt13__atomic_baseIiEppEi(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #3 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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