; LLVM IR from mkazhdan/DMG :: Util/BaseMultiStreamIO.ll (ZN19MultiStreamIOServerD2Ev)

; 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.MultiStreamIOServer = type <{ ptr, ptr, %"class.std::vector", %"class.boost::recursive_timed_mutex", %"class.boost::recursive_timed_mutex", ptr, i8, [7 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<IOClient *, std::allocator<IOClient *>>::_Vector_impl" }
%"struct.std::_Vector_base<IOClient *, std::allocator<IOClient *>>::_Vector_impl" = type { %"struct.std::_Vector_base<IOClient *, std::allocator<IOClient *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<IOClient *, std::allocator<IOClient *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.boost::recursive_timed_mutex" = type <{ %union.pthread_mutex_t, %union.pthread_cond_t, i8, [7 x i8], i64, i32, [4 x i8] }>
%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 }
%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 }

@_ZTV19MultiStreamIOServer = external dso_local unnamed_addr constant { [4 x ptr] }, align 8
@stderr = external global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [101 x i8], align 1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #0

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z21DeleteCriticalSectionPN5boost21recursive_timed_mutexE(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN19MultiStreamIOServerD2Ev(ptr noundef nonnull align 8 dereferenceable(273) %0) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  store ptr getelementptr inbounds inrange(-16, 16) ({ [4 x ptr] }, ptr @_ZTV19MultiStreamIOServer, i32 0, i32 0, i32 2), ptr %3, align 8, !tbaa !9
  %4 = getelementptr inbounds %class.MultiStreamIOServer, ptr %3, i32 0, i32 1
  %5 = invoke noundef zeroext i1 @_Z14IsActiveThreadRPN5boost6threadE(ptr noundef nonnull align 8 dereferenceable(8) %4)
          to label %6 unwind label %38

6:                                                ; preds = %1
  br i1 %5, label %7, label %30

7:                                                ; preds = %6
  br label %8

8:                                                ; preds = %28, %7
  br label %9

9:                                                ; preds = %8
  %10 = getelementptr inbounds %class.MultiStreamIOServer, ptr %3, i32 0, i32 4
  invoke void @_Z20EnterCriticalSectionPN5boost21recursive_timed_mutexExPKc(ptr noundef %10, i64 noundef 100, ptr noundef @.str.9)
          to label %11 unwind label %38

11:                                               ; preds = %9
  %12 = getelementptr inbounds %class.MultiStreamIOServer, ptr %3, i32 0, i32 2
  %13 = call noundef i64 @_ZNKSt6vectorIP8IOClientSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %12) #5
  %14 = icmp ne i64 %13, 0
  br i1 %14, label %26, label %15

15:                                               ; preds = %11
  %16 = getelementptr inbounds %class.MultiStreamIOServer, ptr %3, i32 0, i32 6
  store i8 0, ptr %16, align 8, !tbaa !11
  %17 = getelementptr inbounds %class.MultiStreamIOServer, ptr %3, i32 0, i32 4
  invoke void @_Z20LeaveCriticalSectionPN5boost21recursive_timed_mutexE(ptr noundef %17)
          to label %18 unwind label %38

18:                                               ; preds = %15
  %19 = getelementptr inbounds %class.MultiStreamIOServer, ptr %3, i32 0, i32 1
  %20 = invoke noundef zeroext i1 @_Z15InterruptThreadRPN5boost6threadE(ptr noundef nonnull align 8 dereferenceable(8) %19)
          to label %21 unwind label %38

21:                                               ; preds = %18
  br i1 %20, label %25, label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr @stderr, align 8, !tbaa !5
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef @.str.10) #5
  br label %25

25:                                               ; preds = %22, %21
  br label %29

26:                                               ; preds = %11
  %27 = getelementptr inbounds %class.MultiStreamIOServer, ptr %3, i32 0, i32 4
  invoke void @_Z20LeaveCriticalSectionPN5boost21recursive_timed_mutexE(ptr noundef %27)
          to label %28 unwind label %38

28:                                               ; preds = %26
  br label %8, !llvm.loop !21

29:                                               ; preds = %25
  br label %30

30:                                               ; preds = %29, %6
  %31 = getelementptr inbounds %class.MultiStreamIOServer, ptr %3, i32 0, i32 3
  invoke void @_Z21DeleteCriticalSectionPN5boost21recursive_timed_mutexE(ptr noundef %31)
          to label %32 unwind label %38

32:                                               ; preds = %30
  %33 = getelementptr inbounds %class.MultiStreamIOServer, ptr %3, i32 0, i32 4
  invoke void @_Z21DeleteCriticalSectionPN5boost21recursive_timed_mutexE(ptr noundef %33)
          to label %34 unwind label %38

34:                                               ; preds = %32
  %35 = getelementptr inbounds %class.MultiStreamIOServer, ptr %3, i32 0, i32 4
  call void @_ZN5boost21recursive_timed_mutexD2Ev(ptr noundef nonnull align 8 dereferenceable(108) %35) #5
  %36 = getelementptr inbounds %class.MultiStreamIOServer, ptr %3, i32 0, i32 3
  call void @_ZN5boost21recursive_timed_mutexD2Ev(ptr noundef nonnull align 8 dereferenceable(108) %36) #5
  %37 = getelementptr inbounds %class.MultiStreamIOServer, ptr %3, i32 0, i32 2
  call void @_ZNSt6vectorIP8IOClientSaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %37) #5
  ret void

38:                                               ; preds = %32, %30, %26, %18, %15, %9, %1
  %39 = landingpad { ptr, i32 }
          catch ptr null
  %40 = extractvalue { ptr, i32 } %39, 0
  call void @__clang_call_terminate(ptr %40) #6
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z14IsActiveThreadRPN5boost6threadE(ptr noundef nonnull align 8 dereferenceable(8)) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z20EnterCriticalSectionPN5boost21recursive_timed_mutexExPKc(ptr noundef, i64 noundef, ptr noundef) #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIP8IOClientSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z20LeaveCriticalSectionPN5boost21recursive_timed_mutexE(ptr noundef) #4

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z15InterruptThreadRPN5boost6threadE(ptr noundef nonnull align 8 dereferenceable(8)) #4

attributes #0 = { noinline noreturn nounwind uwtable "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 = { 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 = { 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 #3 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { noreturn 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, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !18, i64 272}
!12 = !{!"_ZTS19MultiStreamIOServer", !6, i64 8, !13, i64 16, !17, i64 40, !17, i64 152, !6, i64 264, !18, i64 272}
!13 = !{!"_ZTSSt6vectorIP8IOClientSaIS1_EE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIP8IOClientSaIS1_EE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIP8IOClientSaIS1_EE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIP8IOClientSaIS1_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!"_ZTSN5boost21recursive_timed_mutexE", !7, i64 0, !7, i64 40, !18, i64 88, !19, i64 96, !20, i64 104}
!18 = !{!"bool", !7, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!"int", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

@_ZTV19MultiStreamIOServer = external dso_local unnamed_addr constant { [4 x ptr] }, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [101 x i8], align 1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z21DeleteCriticalSectionPN5boost21recursive_timed_mutexE(ptr noundef) local_unnamed_addr #2

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN19MultiStreamIOServerD2Ev(ptr noundef nonnull align 8 dereferenceable(273) %0) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  store ptr getelementptr inbounds inrange(-16, 16) (i8, ptr @_ZTV19MultiStreamIOServer, i64 16), ptr %0, align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = tail call noundef zeroext i1 @_Z14IsActiveThreadRPN5boost6threadE(ptr noundef nonnull align 8 dereferenceable(8) %2)
  br i1 %3, label %.preheader, label %18

.preheader:                                       ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 152
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  br label %6

6:                                                ; preds = %.preheader, %17
  invoke void @_Z20EnterCriticalSectionPN5boost21recursive_timed_mutexExPKc(ptr noundef nonnull %4, i64 noundef 100, ptr noundef nonnull @.str.9)
          to label %7 unwind label %.loopexit

7:                                                ; preds = %6
  %8 = tail call noundef i64 @_ZNKSt6vectorIP8IOClientSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #5
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %9, label %17

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 272
  store i8 0, ptr %10, align 8, !tbaa !8
  invoke void @_Z20LeaveCriticalSectionPN5boost21recursive_timed_mutexE(ptr noundef nonnull %4)
          to label %11 unwind label %.loopexit.split-lp

11:                                               ; preds = %9
  %12 = invoke noundef zeroext i1 @_Z15InterruptThreadRPN5boost6threadE(ptr noundef nonnull align 8 dereferenceable(8) %2)
          to label %13 unwind label %.loopexit.split-lp

13:                                               ; preds = %11
  br i1 %12, label %18, label %14

14:                                               ; preds = %13
  %15 = load ptr, ptr @stderr, align 8, !tbaa !20
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str.10) #6
  br label %18

17:                                               ; preds = %7
  invoke void @_Z20LeaveCriticalSectionPN5boost21recursive_timed_mutexE(ptr noundef nonnull %4)
          to label %6 unwind label %.loopexit, !llvm.loop !21

18:                                               ; preds = %14, %13, %1
  %19 = getelementptr inbounds i8, ptr %0, i64 40
  tail call void @_Z21DeleteCriticalSectionPN5boost21recursive_timed_mutexE(ptr noundef nonnull %19)
  %20 = getelementptr inbounds i8, ptr %0, i64 152
  tail call void @_Z21DeleteCriticalSectionPN5boost21recursive_timed_mutexE(ptr noundef nonnull %20)
  tail call void @_ZN5boost21recursive_timed_mutexD2Ev(ptr noundef nonnull align 8 dereferenceable(108) %20) #5
  tail call void @_ZN5boost21recursive_timed_mutexD2Ev(ptr noundef nonnull align 8 dereferenceable(108) %19) #5
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @_ZNSt6vectorIP8IOClientSaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %21) #5
  ret void

.loopexit:                                        ; preds = %6, %17
  %lpad.loopexit = landingpad { ptr, i32 }
          catch ptr null
  br label %22

.loopexit.split-lp:                               ; preds = %9, %11
  %lpad.loopexit.split-lp = landingpad { ptr, i32 }
          catch ptr null
  br label %22

22:                                               ; preds = %.loopexit.split-lp, %.loopexit
  %lpad.phi = phi { ptr, i32 } [ %lpad.loopexit, %.loopexit ], [ %lpad.loopexit.split-lp, %.loopexit.split-lp ]
  %23 = extractvalue { ptr, i32 } %lpad.phi, 0
  tail call void @__clang_call_terminate(ptr %23) #7
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z14IsActiveThreadRPN5boost6threadE(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z20EnterCriticalSectionPN5boost21recursive_timed_mutexExPKc(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIP8IOClientSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z20LeaveCriticalSectionPN5boost21recursive_timed_mutexE(ptr noundef) local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z15InterruptThreadRPN5boost6threadE(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #4

attributes #0 = { noinline noreturn nounwind uwtable "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 = { 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 = { 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 #3 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { cold nounwind }
attributes #7 = { noreturn 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !17, i64 272}
!9 = !{!"_ZTS19MultiStreamIOServer", !10, i64 8, !12, i64 16, !16, i64 40, !16, i64 152, !10, i64 264, !17, i64 272}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !7, i64 0}
!12 = !{!"_ZTSSt6vectorIP8IOClientSaIS1_EE", !13, i64 0}
!13 = !{!"_ZTSSt12_Vector_baseIP8IOClientSaIS1_EE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIP8IOClientSaIS1_EE12_Vector_implE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIP8IOClientSaIS1_EE17_Vector_impl_dataE", !10, i64 0, !10, i64 8, !10, i64 16}
!16 = !{!"_ZTSN5boost21recursive_timed_mutexE", !11, i64 0, !11, i64 40, !17, i64 88, !18, i64 96, !19, i64 104}
!17 = !{!"bool", !11, i64 0}
!18 = !{!"long", !11, i64 0}
!19 = !{!"int", !11, i64 0}
!20 = !{!10, !10, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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