; LLVM IR from wichue/nethello :: src/base/Logger.ll (ZN3chw14AsyncLogWriter3runEv)

; 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.chw::AsyncLogWriter" = type { %"class.chw::LogWriter", i8, %"class.chw::Semaphore", %"class.std::mutex", %"class.std::shared_ptr.18", %"class.chw::List" }
%"class.chw::LogWriter" = type { ptr }
%"class.chw::Semaphore" = type { i64, %"class.std::recursive_mutex", %"class.std::_V2::condition_variable_any" }
%"class.std::recursive_mutex" = type { %"class.std::__recursive_mutex_base" }
%"class.std::__recursive_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::_V2::condition_variable_any" = type { %"class.std::condition_variable", %"class.std::shared_ptr.15" }
%"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 }
%"class.std::shared_ptr.15" = type { %"class.std::__shared_ptr.16" }
%"class.std::__shared_ptr.16" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }
%"class.std::mutex" = type { %"class.std::__mutex_base" }
%"class.std::__mutex_base" = type { %union.pthread_mutex_t }
%"class.std::shared_ptr.18" = type { %"class.std::__shared_ptr.19" }
%"class.std::__shared_ptr.19" = type { ptr, %"class.std::__shared_count" }
%"class.chw::List" = type { %"class.std::__cxx11::list" }
%"class.std::__cxx11::list" = type { %"class.std::__cxx11::_List_base" }
%"class.std::__cxx11::_List_base" = type { %"struct.std::__cxx11::_List_base<std::pair<std::shared_ptr<chw::LogContext>, chw::Logger *>, std::allocator<std::pair<std::shared_ptr<chw::LogContext>, chw::Logger *>>>::_List_impl" }
%"struct.std::__cxx11::_List_base<std::pair<std::shared_ptr<chw::LogContext>, chw::Logger *>, std::allocator<std::pair<std::shared_ptr<chw::LogContext>, chw::Logger *>>>::_List_impl" = type { %"struct.std::__detail::_List_node_header" }
%"struct.std::__detail::_List_node_header" = type { %"struct.std::__detail::_List_node_base", i64 }
%"struct.std::__detail::_List_node_base" = type { ptr, ptr }

@.str.4 = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3chw14AsyncLogWriter8flushAllEv(ptr noundef nonnull align 8 dereferenceable(208)) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3chw14AsyncLogWriter3runEv(ptr noundef nonnull align 8 dereferenceable(208) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  call void @_ZN3chw13setThreadNameEPKc(ptr noundef @.str.4)
  br label %4

4:                                                ; preds = %9, %1
  %5 = getelementptr inbounds %"class.chw::AsyncLogWriter", ptr %3, i32 0, i32 1
  %6 = load i8, ptr %5, align 8, !tbaa !9, !range !33, !noundef !34
  %7 = trunc i8 %6 to i1
  %8 = xor i1 %7, true
  br i1 %8, label %9, label %11

9:                                                ; preds = %4
  %10 = getelementptr inbounds %"class.chw::AsyncLogWriter", ptr %3, i32 0, i32 2
  call void @_ZN3chw9Semaphore4waitEv(ptr noundef nonnull align 8 dereferenceable(112) %10)
  call void @_ZN3chw14AsyncLogWriter8flushAllEv(ptr noundef nonnull align 8 dereferenceable(208) %3)
  br label %4, !llvm.loop !35

11:                                               ; preds = %4
  ret void
}

declare void @_ZN3chw13setThreadNameEPKc(ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3chw9Semaphore4waitEv(ptr noundef nonnull align 8 dereferenceable(112)) #0 align 2

attributes #0 = { 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 #1 = { "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" }

!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, !12, i64 8}
!10 = !{!"_ZTSN3chw14AsyncLogWriterE", !11, i64 0, !12, i64 8, !13, i64 16, !23, i64 128, !25, i64 168, !27, i64 184}
!11 = !{!"_ZTSN3chw9LogWriterE"}
!12 = !{!"bool", !7, i64 0}
!13 = !{!"_ZTSN3chw9SemaphoreE", !14, i64 0, !15, i64 8, !17, i64 48}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_ZTSSt15recursive_mutex", !16, i64 0}
!16 = !{!"_ZTSSt22__recursive_mutex_base", !7, i64 0}
!17 = !{!"_ZTSNSt3_V222condition_variable_anyE", !18, i64 0, !20, i64 48}
!18 = !{!"_ZTSSt18condition_variable", !19, i64 0}
!19 = !{!"_ZTSSt9__condvar", !7, i64 0}
!20 = !{!"_ZTSSt10shared_ptrISt5mutexE", !21, i64 0}
!21 = !{!"_ZTSSt12__shared_ptrISt5mutexLN9__gnu_cxx12_Lock_policyE2EE", !6, i64 0, !22, i64 8}
!22 = !{!"_ZTSSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EE", !6, i64 0}
!23 = !{!"_ZTSSt5mutex", !24, i64 0}
!24 = !{!"_ZTSSt12__mutex_base", !7, i64 0}
!25 = !{!"_ZTSSt10shared_ptrISt6threadE", !26, i64 0}
!26 = !{!"_ZTSSt12__shared_ptrISt6threadLN9__gnu_cxx12_Lock_policyE2EE", !6, i64 0, !22, i64 8}
!27 = !{!"_ZTSN3chw4ListISt4pairISt10shared_ptrINS_10LogContextEEPNS_6LoggerEEEE", !28, i64 0}
!28 = !{!"_ZTSNSt7__cxx114listISt4pairISt10shared_ptrIN3chw10LogContextEEPNS3_6LoggerEESaIS8_EEE", !29, i64 0}
!29 = !{!"_ZTSNSt7__cxx1110_List_baseISt4pairISt10shared_ptrIN3chw10LogContextEEPNS3_6LoggerEESaIS8_EEE", !30, i64 0}
!30 = !{!"_ZTSNSt7__cxx1110_List_baseISt4pairISt10shared_ptrIN3chw10LogContextEEPNS3_6LoggerEESaIS8_EE10_List_implE", !31, i64 0}
!31 = !{!"_ZTSNSt8__detail17_List_node_headerE", !32, i64 0, !14, i64 16}
!32 = !{!"_ZTSNSt8__detail15_List_node_baseE", !6, i64 0, !6, i64 8}
!33 = !{i8 0, i8 2}
!34 = !{}
!35 = distinct !{!35, !36}
!36 = !{!"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"

@.str.4 = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3chw14AsyncLogWriter8flushAllEv(ptr noundef nonnull align 8 dereferenceable(208)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3chw14AsyncLogWriter3runEv(ptr noundef nonnull align 8 dereferenceable(208) %0) local_unnamed_addr #0 align 2 {
  tail call void @_ZN3chw13setThreadNameEPKc(ptr noundef nonnull @.str.4)
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i8, ptr %2, align 8, !tbaa !5, !range !32, !noundef !33
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  br label %6

6:                                                ; preds = %.lr.ph, %6
  tail call void @_ZN3chw9Semaphore4waitEv(ptr noundef nonnull align 8 dereferenceable(112) %5)
  tail call void @_ZN3chw14AsyncLogWriter8flushAllEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %7 = load i8, ptr %2, align 8, !tbaa !5, !range !32, !noundef !33
  %8 = trunc nuw i8 %7 to i1
  br i1 %8, label %._crit_edge, label %6, !llvm.loop !34

._crit_edge:                                      ; preds = %6, %1
  ret void
}

declare void @_ZN3chw13setThreadNameEPKc(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3chw9Semaphore4waitEv(ptr noundef nonnull align 8 dereferenceable(112)) local_unnamed_addr #0 align 2

attributes #0 = { 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 #1 = { "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" }

!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, !8, i64 8}
!6 = !{!"_ZTSN3chw14AsyncLogWriterE", !7, i64 0, !8, i64 8, !11, i64 16, !22, i64 128, !24, i64 168, !26, i64 184}
!7 = !{!"_ZTSN3chw9LogWriterE"}
!8 = !{!"bool", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSN3chw9SemaphoreE", !12, i64 0, !13, i64 8, !15, i64 48}
!12 = !{!"long", !9, i64 0}
!13 = !{!"_ZTSSt15recursive_mutex", !14, i64 0}
!14 = !{!"_ZTSSt22__recursive_mutex_base", !9, i64 0}
!15 = !{!"_ZTSNSt3_V222condition_variable_anyE", !16, i64 0, !18, i64 48}
!16 = !{!"_ZTSSt18condition_variable", !17, i64 0}
!17 = !{!"_ZTSSt9__condvar", !9, i64 0}
!18 = !{!"_ZTSSt10shared_ptrISt5mutexE", !19, i64 0}
!19 = !{!"_ZTSSt12__shared_ptrISt5mutexLN9__gnu_cxx12_Lock_policyE2EE", !20, i64 0, !21, i64 8}
!20 = !{!"any pointer", !9, i64 0}
!21 = !{!"_ZTSSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EE", !20, i64 0}
!22 = !{!"_ZTSSt5mutex", !23, i64 0}
!23 = !{!"_ZTSSt12__mutex_base", !9, i64 0}
!24 = !{!"_ZTSSt10shared_ptrISt6threadE", !25, i64 0}
!25 = !{!"_ZTSSt12__shared_ptrISt6threadLN9__gnu_cxx12_Lock_policyE2EE", !20, i64 0, !21, i64 8}
!26 = !{!"_ZTSN3chw4ListISt4pairISt10shared_ptrINS_10LogContextEEPNS_6LoggerEEEE", !27, i64 0}
!27 = !{!"_ZTSNSt7__cxx114listISt4pairISt10shared_ptrIN3chw10LogContextEEPNS3_6LoggerEESaIS8_EEE", !28, i64 0}
!28 = !{!"_ZTSNSt7__cxx1110_List_baseISt4pairISt10shared_ptrIN3chw10LogContextEEPNS3_6LoggerEESaIS8_EEE", !29, i64 0}
!29 = !{!"_ZTSNSt7__cxx1110_List_baseISt4pairISt10shared_ptrIN3chw10LogContextEEPNS3_6LoggerEESaIS8_EE10_List_implE", !30, i64 0}
!30 = !{!"_ZTSNSt8__detail17_List_node_headerE", !31, i64 0, !12, i64 16}
!31 = !{!"_ZTSNSt8__detail15_List_node_baseE", !20, i64 0, !20, i64 8}
!32 = !{i8 0, i8 2}
!33 = !{}
!34 = distinct !{!34, !35}
!35 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass