; LLVM IR from q191201771/libchef :: test/chef_base_test/chef_wait_event_counter_test.ll (Z12counter_testv)

; 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.chef::wait_event_counter" = type { i32, %"struct.std::atomic", %"class.std::mutex", %"class.std::condition_variable" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%"class.std::mutex" = type { %"class.std::__mutex_base" }
%"class.std::__mutex_base" = type { %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%"class.std::condition_variable" = type { %"class.std::__condvar" }
%"class.std::__condvar" = type { %union.pthread_cond_t }
%union.pthread_cond_t = type { %struct.__pthread_cond_s }
%struct.__pthread_cond_s = type { %union.__atomic_wide_counter, %union.__atomic_wide_counter, [2 x i32], [2 x i32], i32, i32, [2 x i32] }
%union.__atomic_wide_counter = type { i64 }

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

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

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL11check_countRKN4chef18wait_event_counterEii(ptr noundef nonnull align 8 dereferenceable(96), i32 noundef, i32 noundef) #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN4chef18wait_event_counter6notifyEv(ptr noundef nonnull align 8 dereferenceable(96)) #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN4chef18wait_event_counter4waitEv(ptr noundef nonnull align 8 dereferenceable(96)) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN4chef18wait_event_counterD2Ev(ptr noundef nonnull align 8 dereferenceable(96)) unnamed_addr #1 align 2

; 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 void @_Z12counter_testv() #2 personality ptr @__gxx_personality_v0 {
  %1 = alloca i32, align 4
  %2 = alloca %"class.chef::wait_event_counter", align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  store i32 16, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 96, ptr %2) #4
  call void @_ZN4chef18wait_event_counterC2Ei(ptr noundef nonnull align 8 dereferenceable(96) %2, i32 noundef 16)
  invoke void @_ZL11check_countRKN4chef18wait_event_counterEii(ptr noundef nonnull align 8 dereferenceable(96) %2, i32 noundef 16, i32 noundef 0)
          to label %6 unwind label %11

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

7:                                                ; preds = %22, %6
  %8 = load i32, ptr %5, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 16
  br i1 %9, label %15, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %29

11:                                               ; preds = %30, %29, %0
  %12 = landingpad { ptr, i32 }
          cleanup
  %13 = extractvalue { ptr, i32 } %12, 0
  store ptr %13, ptr %3, align 8
  %14 = extractvalue { ptr, i32 } %12, 1
  store i32 %14, ptr %4, align 4
  br label %32

15:                                               ; preds = %7
  %16 = load i32, ptr %5, align 4, !tbaa !5
  invoke void @_ZL11check_countRKN4chef18wait_event_counterEii(ptr noundef nonnull align 8 dereferenceable(96) %2, i32 noundef 16, i32 noundef %16)
          to label %17 unwind label %25

17:                                               ; preds = %15
  invoke void @_ZN4chef18wait_event_counter6notifyEv(ptr noundef nonnull align 8 dereferenceable(96) %2)
          to label %18 unwind label %25

18:                                               ; preds = %17
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  invoke void @_ZL11check_countRKN4chef18wait_event_counterEii(ptr noundef nonnull align 8 dereferenceable(96) %2, i32 noundef 16, i32 noundef %20)
          to label %21 unwind label %25

21:                                               ; preds = %18
  br label %22

22:                                               ; preds = %21
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %5, align 4, !tbaa !5
  br label %7, !llvm.loop !9

25:                                               ; preds = %18, %17, %15
  %26 = landingpad { ptr, i32 }
          cleanup
  %27 = extractvalue { ptr, i32 } %26, 0
  store ptr %27, ptr %3, align 8
  %28 = extractvalue { ptr, i32 } %26, 1
  store i32 %28, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %32

29:                                               ; preds = %10
  invoke void @_ZL11check_countRKN4chef18wait_event_counterEii(ptr noundef nonnull align 8 dereferenceable(96) %2, i32 noundef 16, i32 noundef 16)
          to label %30 unwind label %11

30:                                               ; preds = %29
  invoke void @_ZN4chef18wait_event_counter4waitEv(ptr noundef nonnull align 8 dereferenceable(96) %2)
          to label %31 unwind label %11

31:                                               ; preds = %30
  call void @_ZN4chef18wait_event_counterD2Ev(ptr noundef nonnull align 8 dereferenceable(96) %2) #4
  call void @llvm.lifetime.end.p0(i64 96, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  ret void

32:                                               ; preds = %25, %11
  call void @_ZN4chef18wait_event_counterD2Ev(ptr noundef nonnull align 8 dereferenceable(96) %2) #4
  call void @llvm.lifetime.end.p0(i64 96, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  br label %33

33:                                               ; preds = %32
  %34 = load ptr, ptr %3, align 8
  %35 = load i32, ptr %4, align 4
  %36 = insertvalue { ptr, i32 } poison, ptr %34, 0
  %37 = insertvalue { ptr, i32 } %36, i32 %35, 1
  resume { ptr, i32 } %37
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 = { inlinehint 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 = { 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.chef::wait_event_counter" = type { i32, %"struct.std::atomic", %"class.std::mutex", %"class.std::condition_variable" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%"class.std::mutex" = type { %"class.std::__mutex_base" }
%"class.std::__mutex_base" = type { %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%"class.std::condition_variable" = type { %"class.std::__condvar" }
%"class.std::__condvar" = type { %union.pthread_cond_t }
%union.pthread_cond_t = type { %struct.__pthread_cond_s }
%struct.__pthread_cond_s = type { %union.__atomic_wide_counter, %union.__atomic_wide_counter, [2 x i32], [2 x i32], i32, i32, [2 x i32] }
%union.__atomic_wide_counter = type { i64 }

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

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

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL11check_countRKN4chef18wait_event_counterEii(ptr noundef nonnull align 8 dereferenceable(96), i32 noundef, i32 noundef) local_unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN4chef18wait_event_counter6notifyEv(ptr noundef nonnull align 8 dereferenceable(96)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN4chef18wait_event_counter4waitEv(ptr noundef nonnull align 8 dereferenceable(96)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN4chef18wait_event_counterD2Ev(ptr noundef nonnull align 8 dereferenceable(96)) unnamed_addr #1 align 2

; 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 void @_Z12counter_testv() local_unnamed_addr #2 personality ptr @__gxx_personality_v0 {
  %1 = alloca %"class.chef::wait_event_counter", align 8
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %1) #4
  call void @_ZN4chef18wait_event_counterC2Ei(ptr noundef nonnull align 8 dereferenceable(96) %1, i32 noundef 16)
  invoke void @_ZL11check_countRKN4chef18wait_event_counterEii(ptr noundef nonnull align 8 dereferenceable(96) %1, i32 noundef 16, i32 noundef 0)
          to label %.preheader unwind label %3

.preheader:                                       ; preds = %0, %7
  %.0 = phi i32 [ %8, %7 ], [ 0, %0 ]
  %exitcond.not = icmp eq i32 %.0, 16
  br i1 %exitcond.not, label %2, label %5

2:                                                ; preds = %.preheader
  invoke void @_ZL11check_countRKN4chef18wait_event_counterEii(ptr noundef nonnull align 8 dereferenceable(96) %1, i32 noundef 16, i32 noundef 16)
          to label %11 unwind label %3

3:                                                ; preds = %11, %2, %0
  %4 = landingpad { ptr, i32 }
          cleanup
  br label %13

5:                                                ; preds = %.preheader
  invoke void @_ZL11check_countRKN4chef18wait_event_counterEii(ptr noundef nonnull align 8 dereferenceable(96) %1, i32 noundef 16, i32 noundef %.0)
          to label %6 unwind label %9

6:                                                ; preds = %5
  invoke void @_ZN4chef18wait_event_counter6notifyEv(ptr noundef nonnull align 8 dereferenceable(96) %1)
          to label %7 unwind label %9

7:                                                ; preds = %6
  %8 = add nuw nsw i32 %.0, 1
  invoke void @_ZL11check_countRKN4chef18wait_event_counterEii(ptr noundef nonnull align 8 dereferenceable(96) %1, i32 noundef 16, i32 noundef %8)
          to label %.preheader unwind label %9, !llvm.loop !5

9:                                                ; preds = %7, %6, %5
  %10 = landingpad { ptr, i32 }
          cleanup
  br label %13

11:                                               ; preds = %2
  invoke void @_ZN4chef18wait_event_counter4waitEv(ptr noundef nonnull align 8 dereferenceable(96) %1)
          to label %12 unwind label %3

12:                                               ; preds = %11
  call void @_ZN4chef18wait_event_counterD2Ev(ptr noundef nonnull align 8 dereferenceable(96) %1) #4
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %1) #4
  ret void

13:                                               ; preds = %9, %3
  %.pn = phi { ptr, i32 } [ %10, %9 ], [ %4, %3 ]
  call void @_ZN4chef18wait_event_counterD2Ev(ptr noundef nonnull align 8 dereferenceable(96) %1) #4
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %1) #4
  resume { ptr, i32 } %.pn
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 = { inlinehint 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 = { 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,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass