; LLVM IR from turi-code/SFrame :: oss_src/parallel/thread_pool.ll (ZN8graphlab11thread_pool4joinEv)

; 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.std::unique_lock" = type <{ ptr, i8, [7 x i8] }>
%"class.graphlab::thread_pool" = type <{ %"class.graphlab::thread_group", %"class.graphlab::blocking_queue", i64, %"class.graphlab::mutex", %"class.graphlab::conditional", i64, i64, i8, i8, [6 x i8] }>
%"class.graphlab::thread_group" = type { i64, i64, %"class.graphlab::mutex", %"class.graphlab::conditional", %"class.std::queue.0" }
%"class.std::queue.0" = type { %"class.std::deque.1" }
%"class.std::deque.1" = type { %"class.std::_Deque_base.2" }
%"class.std::_Deque_base.2" = type { %"struct.std::_Deque_base<std::pair<unsigned long, const char *>, std::allocator<std::pair<unsigned long, const char *>>>::_Deque_impl" }
%"struct.std::_Deque_base<std::pair<unsigned long, const char *>, std::allocator<std::pair<unsigned long, const char *>>>::_Deque_impl" = type { %"struct.std::_Deque_base<std::pair<unsigned long, const char *>, std::allocator<std::pair<unsigned long, const char *>>>::_Deque_impl_data" }
%"struct.std::_Deque_base<std::pair<unsigned long, const char *>, std::allocator<std::pair<unsigned long, const char *>>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator.6", %"struct.std::_Deque_iterator.6" }
%"struct.std::_Deque_iterator.6" = type { ptr, ptr, ptr, ptr }
%"class.graphlab::blocking_queue" = type <{ i8, [7 x i8], %"class.std::deque.7", %"class.graphlab::mutex", %"class.graphlab::conditional", %"class.graphlab::conditional", i16, i16, [4 x i8] }>
%"class.std::deque.7" = type { %"class.std::_Deque_base.8" }
%"class.std::_Deque_base.8" = type { %"struct.std::_Deque_base<std::pair<boost::function<void ()>, int>, std::allocator<std::pair<boost::function<void ()>, int>>>::_Deque_impl" }
%"struct.std::_Deque_base<std::pair<boost::function<void ()>, int>, std::allocator<std::pair<boost::function<void ()>, int>>>::_Deque_impl" = type { %"struct.std::_Deque_base<std::pair<boost::function<void ()>, int>, std::allocator<std::pair<boost::function<void ()>, int>>>::_Deque_impl_data" }
%"struct.std::_Deque_base<std::pair<boost::function<void ()>, int>, std::allocator<std::pair<boost::function<void ()>, int>>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator.12", %"struct.std::_Deque_iterator.12" }
%"struct.std::_Deque_iterator.12" = type { ptr, ptr, ptr, ptr }
%"class.graphlab::mutex" = 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.graphlab::conditional" = 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 }

declare i32 @__gxx_personality_v0(...)

; 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 @_ZNSt11unique_lockIN8graphlab5mutexEEC2ERS1_(ptr noundef nonnull align 8 dereferenceable(9), ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK8graphlab11conditional4waitERSt11unique_lockINS_5mutexEE(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(9)) #2 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN8graphlab14blocking_queueISt4pairIN5boost8functionIFvvEEEiEE16wait_until_emptyEv(ptr noundef nonnull align 8 dereferenceable(228)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8graphlab11thread_pool4joinEv(ptr noundef nonnull align 8 dereferenceable(530) %0) #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca %"class.std::unique_lock", align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  %7 = getelementptr inbounds %"class.graphlab::thread_pool", ptr %6, i32 0, i32 1
  %8 = call noundef zeroext i1 @_ZN8graphlab14blocking_queueISt4pairIN5boost8functionIFvvEEEiEE16wait_until_emptyEv(ptr noundef nonnull align 8 dereferenceable(228) %7)
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #4
  %9 = getelementptr inbounds %"class.graphlab::thread_pool", ptr %6, i32 0, i32 3
  call void @_ZNSt11unique_lockIN8graphlab5mutexEEC2ERS1_(ptr noundef nonnull align 8 dereferenceable(9) %3, ptr noundef nonnull align 8 dereferenceable(40) %9)
  %10 = getelementptr inbounds %"class.graphlab::thread_pool", ptr %6, i32 0, i32 7
  store i8 1, ptr %10, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %21, %1
  br label %12

12:                                               ; preds = %11
  %13 = getelementptr inbounds %"class.graphlab::thread_pool", ptr %6, i32 0, i32 6
  %14 = load i64, ptr %13, align 8, !tbaa !29
  %15 = getelementptr inbounds %"class.graphlab::thread_pool", ptr %6, i32 0, i32 5
  %16 = load i64, ptr %15, align 8, !tbaa !30
  %17 = icmp eq i64 %14, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %12
  br label %26

19:                                               ; preds = %12
  %20 = getelementptr inbounds %"class.graphlab::thread_pool", ptr %6, i32 0, i32 4
  invoke void @_ZNK8graphlab11conditional4waitERSt11unique_lockINS_5mutexEE(ptr noundef nonnull align 8 dereferenceable(48) %20, ptr noundef nonnull align 8 dereferenceable(9) %3)
          to label %21 unwind label %22

21:                                               ; preds = %19
  br label %11, !llvm.loop !31

22:                                               ; preds = %19
  %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
  call void @_ZNSt11unique_lockIN8graphlab5mutexEED2Ev(ptr noundef nonnull align 8 dereferenceable(9) %3) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #4
  br label %28

26:                                               ; preds = %18
  %27 = getelementptr inbounds %"class.graphlab::thread_pool", ptr %6, i32 0, i32 7
  store i8 0, ptr %27, align 8, !tbaa !9
  call void @_ZNSt11unique_lockIN8graphlab5mutexEED2Ev(ptr noundef nonnull align 8 dereferenceable(9) %3) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #4
  ret void

28:                                               ; preds = %22
  %29 = load ptr, ptr %4, align 8
  %30 = load i32, ptr %5, align 4
  %31 = insertvalue { ptr, i32 } poison, ptr %29, 0
  %32 = insertvalue { ptr, i32 } %31, i32 %30, 1
  resume { ptr, i32 } %32
}

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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !22, i64 528}
!10 = !{!"_ZTSN8graphlab11thread_poolE", !11, i64 0, !21, i64 184, !12, i64 416, !13, i64 424, !14, i64 464, !12, i64 512, !12, i64 520, !22, i64 528, !22, i64 529}
!11 = !{!"_ZTSN8graphlab12thread_groupE", !12, i64 0, !12, i64 8, !13, i64 16, !14, i64 56, !15, i64 104}
!12 = !{!"long", !7, i64 0}
!13 = !{!"_ZTSN8graphlab5mutexE", !7, i64 0}
!14 = !{!"_ZTSN8graphlab11conditionalE", !7, i64 0}
!15 = !{!"_ZTSSt5queueISt4pairImPKcESt5dequeIS3_SaIS3_EEE", !16, i64 0}
!16 = !{!"_ZTSSt5dequeISt4pairImPKcESaIS3_EE", !17, i64 0}
!17 = !{!"_ZTSSt11_Deque_baseISt4pairImPKcESaIS3_EE", !18, i64 0}
!18 = !{!"_ZTSNSt11_Deque_baseISt4pairImPKcESaIS3_EE11_Deque_implE", !19, i64 0}
!19 = !{!"_ZTSNSt11_Deque_baseISt4pairImPKcESaIS3_EE16_Deque_impl_dataE", !6, i64 0, !12, i64 8, !20, i64 16, !20, i64 48}
!20 = !{!"_ZTSSt15_Deque_iteratorISt4pairImPKcERS3_PS3_E", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!21 = !{!"_ZTSN8graphlab14blocking_queueISt4pairIN5boost8functionIFvvEEEiEEE", !22, i64 0, !23, i64 8, !13, i64 88, !14, i64 128, !14, i64 176, !28, i64 224, !28, i64 226}
!22 = !{!"bool", !7, i64 0}
!23 = !{!"_ZTSSt5dequeISt4pairIN5boost8functionIFvvEEEiESaIS5_EE", !24, i64 0}
!24 = !{!"_ZTSSt11_Deque_baseISt4pairIN5boost8functionIFvvEEEiESaIS5_EE", !25, i64 0}
!25 = !{!"_ZTSNSt11_Deque_baseISt4pairIN5boost8functionIFvvEEEiESaIS5_EE11_Deque_implE", !26, i64 0}
!26 = !{!"_ZTSNSt11_Deque_baseISt4pairIN5boost8functionIFvvEEEiESaIS5_EE16_Deque_impl_dataE", !6, i64 0, !12, i64 8, !27, i64 16, !27, i64 48}
!27 = !{!"_ZTSSt15_Deque_iteratorISt4pairIN5boost8functionIFvvEEEiERS5_PS5_E", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!28 = !{!"short", !7, i64 0}
!29 = !{!10, !12, i64 520}
!30 = !{!10, !12, i64 512}
!31 = distinct !{!31, !32}
!32 = !{!"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.std::unique_lock" = type <{ ptr, i8, [7 x i8] }>

declare i32 @__gxx_personality_v0(...)

; 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 @_ZNSt11unique_lockIN8graphlab5mutexEEC2ERS1_(ptr noundef nonnull align 8 dereferenceable(9), ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK8graphlab11conditional4waitERSt11unique_lockINS_5mutexEE(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(9)) local_unnamed_addr #2 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN8graphlab14blocking_queueISt4pairIN5boost8functionIFvvEEEiEE16wait_until_emptyEv(ptr noundef nonnull align 8 dereferenceable(228)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8graphlab11thread_pool4joinEv(ptr noundef nonnull align 8 dereferenceable(530) %0) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca %"class.std::unique_lock", align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 184
  %4 = tail call noundef zeroext i1 @_ZN8graphlab14blocking_queueISt4pairIN5boost8functionIFvvEEEiEE16wait_until_emptyEv(ptr noundef nonnull align 8 dereferenceable(228) %3)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #4
  %5 = getelementptr inbounds i8, ptr %0, i64 424
  call void @_ZNSt11unique_lockIN8graphlab5mutexEEC2ERS1_(ptr noundef nonnull align 8 dereferenceable(9) %2, ptr noundef nonnull align 8 dereferenceable(40) %5)
  %6 = getelementptr inbounds i8, ptr %0, i64 528
  store i8 1, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 520
  %8 = getelementptr inbounds i8, ptr %0, i64 512
  %9 = getelementptr inbounds i8, ptr %0, i64 464
  br label %10

10:                                               ; preds = %14, %1
  %11 = load i64, ptr %7, align 8, !tbaa !28
  %12 = load i64, ptr %8, align 8, !tbaa !29
  %13 = icmp eq i64 %11, %12
  br i1 %13, label %17, label %14

14:                                               ; preds = %10
  invoke void @_ZNK8graphlab11conditional4waitERSt11unique_lockINS_5mutexEE(ptr noundef nonnull align 8 dereferenceable(48) %9, ptr noundef nonnull align 8 dereferenceable(9) %2)
          to label %10 unwind label %15, !llvm.loop !30

15:                                               ; preds = %14
  %16 = landingpad { ptr, i32 }
          cleanup
  call void @_ZNSt11unique_lockIN8graphlab5mutexEED2Ev(ptr noundef nonnull align 8 dereferenceable(9) %2) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #4
  resume { ptr, i32 } %16

17:                                               ; preds = %10
  store i8 0, ptr %6, align 8, !tbaa !5
  call void @_ZNSt11unique_lockIN8graphlab5mutexEED2Ev(ptr noundef nonnull align 8 dereferenceable(9) %2) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #4
  ret void
}

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 = { 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 #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, !21, i64 528}
!6 = !{!"_ZTSN8graphlab11thread_poolE", !7, i64 0, !20, i64 184, !8, i64 416, !11, i64 424, !12, i64 464, !8, i64 512, !8, i64 520, !21, i64 528, !21, i64 529}
!7 = !{!"_ZTSN8graphlab12thread_groupE", !8, i64 0, !8, i64 8, !11, i64 16, !12, i64 56, !13, i64 104}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSN8graphlab5mutexE", !9, i64 0}
!12 = !{!"_ZTSN8graphlab11conditionalE", !9, i64 0}
!13 = !{!"_ZTSSt5queueISt4pairImPKcESt5dequeIS3_SaIS3_EEE", !14, i64 0}
!14 = !{!"_ZTSSt5dequeISt4pairImPKcESaIS3_EE", !15, i64 0}
!15 = !{!"_ZTSSt11_Deque_baseISt4pairImPKcESaIS3_EE", !16, i64 0}
!16 = !{!"_ZTSNSt11_Deque_baseISt4pairImPKcESaIS3_EE11_Deque_implE", !17, i64 0}
!17 = !{!"_ZTSNSt11_Deque_baseISt4pairImPKcESaIS3_EE16_Deque_impl_dataE", !18, i64 0, !8, i64 8, !19, i64 16, !19, i64 48}
!18 = !{!"any pointer", !9, i64 0}
!19 = !{!"_ZTSSt15_Deque_iteratorISt4pairImPKcERS3_PS3_E", !18, i64 0, !18, i64 8, !18, i64 16, !18, i64 24}
!20 = !{!"_ZTSN8graphlab14blocking_queueISt4pairIN5boost8functionIFvvEEEiEEE", !21, i64 0, !22, i64 8, !11, i64 88, !12, i64 128, !12, i64 176, !27, i64 224, !27, i64 226}
!21 = !{!"bool", !9, i64 0}
!22 = !{!"_ZTSSt5dequeISt4pairIN5boost8functionIFvvEEEiESaIS5_EE", !23, i64 0}
!23 = !{!"_ZTSSt11_Deque_baseISt4pairIN5boost8functionIFvvEEEiESaIS5_EE", !24, i64 0}
!24 = !{!"_ZTSNSt11_Deque_baseISt4pairIN5boost8functionIFvvEEEiESaIS5_EE11_Deque_implE", !25, i64 0}
!25 = !{!"_ZTSNSt11_Deque_baseISt4pairIN5boost8functionIFvvEEEiESaIS5_EE16_Deque_impl_dataE", !18, i64 0, !8, i64 8, !26, i64 16, !26, i64 48}
!26 = !{!"_ZTSSt15_Deque_iteratorISt4pairIN5boost8functionIFvvEEEiERS5_PS5_E", !18, i64 0, !18, i64 8, !18, i64 16, !18, i64 24}
!27 = !{!"short", !9, i64 0}
!28 = !{!6, !8, i64 520}
!29 = !{!6, !8, i64 512}
!30 = distinct !{!30, !31}
!31 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,SROAPass,SimplifyCFGPass,TailCallElimPass