; LLVM IR from newbiediver/rioring :: src/udp_server.ll (ZN7rioring10udp_server4stopEv)

; 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::chrono::duration" = type { i64 }
%"class.rioring::socket_object" = type { %"class.rioring::object_base", ptr, i32, %struct.sockaddr_storage, %"struct.std::array", i32, i8, i16, %"struct.std::array.0", %"struct.std::array.1", ptr, %"class.rioring::critical_section", %"class.rioring::io_buffer", %"class.rioring::io_double_buffer", %"class.std::function.2", %"class.std::function.4", %"class.std::function.4" }
%"class.rioring::object_base" = type { ptr, %"class.std::enable_shared_from_this", %"class.std::function", i64 }
%"class.std::enable_shared_from_this" = type { %"class.std::weak_ptr" }
%"class.std::weak_ptr" = type { %"class.std::__weak_ptr" }
%"class.std::__weak_ptr" = type { ptr, %"class.std::__weak_count" }
%"class.std::__weak_count" = type { ptr }
%"class.std::function" = type { %"class.std::_Function_base", ptr }
%"class.std::_Function_base" = type { %"union.std::_Any_data", ptr }
%"union.std::_Any_data" = type { %"union.std::_Nocopy_types" }
%"union.std::_Nocopy_types" = type { { i64, i64 } }
%struct.sockaddr_storage = type { i16, [118 x i8], i64 }
%"struct.std::array" = type { [65536 x i8] }
%"struct.std::array.0" = type { [16 x i8] }
%"struct.std::array.1" = type { [40 x i8] }
%"class.rioring::critical_section" = type { %"class.rioring::lock_base", %"class.std::mutex" }
%"class.rioring::lock_base" = type { ptr }
%"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.rioring::io_buffer" = type { %"class.rioring::buffer_base", ptr, i64, i64, i64 }
%"class.rioring::buffer_base" = type { ptr }
%"class.rioring::io_double_buffer" = type { %"class.rioring::buffer_base", %"class.rioring::io_buffer", %"class.rioring::io_buffer" }
%"class.std::function.2" = type { %"class.std::_Function_base", ptr }
%"class.std::function.4" = type { %"class.std::_Function_base", ptr }

; 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
define dso_local void @_ZN7rioring10udp_server4stopEv(ptr noundef nonnull align 8 dereferenceable(66088) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca %"class.std::chrono::duration", align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @_ZN7rioring13socket_object5closeENS0_10close_typeE(ptr noundef nonnull align 8 dereferenceable(66088) %4, i32 noundef 0)
  br label %5

5:                                                ; preds = %9, %1
  %6 = getelementptr inbounds %"class.rioring::socket_object", ptr %4, i32 0, i32 2
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %12

9:                                                ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %10 = call i64 @_ZNSt8literals15chrono_literalsli2msIJLc49EEEENSt6chrono8durationIlSt5ratioILl1ELl1000EEEEv()
  %11 = getelementptr inbounds %"class.std::chrono::duration", ptr %3, i32 0, i32 0
  store i64 %10, ptr %11, align 8
  call void @_ZNSt11this_thread9sleep_forIlSt5ratioILl1ELl1000EEEEvRKNSt6chrono8durationIT_T0_EE(ptr noundef nonnull align 8 dereferenceable(8) %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %5, !llvm.loop !36

12:                                               ; preds = %5
  ret void
}

declare void @_ZN7rioring13socket_object5closeENS0_10close_typeE(ptr noundef nonnull align 8 dereferenceable(66088), i32 noundef) #2

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

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZNSt8literals15chrono_literalsli2msIJLc49EEEENSt6chrono8durationIlSt5ratioILl1ELl1000EEEEv() #1

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 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !19, i64 72}
!10 = !{!"_ZTSN7rioring13socket_objectE", !11, i64 0, !6, i64 64, !19, i64 72, !20, i64 80, !22, i64 208, !23, i64 65744, !24, i64 65748, !21, i64 65750, !25, i64 65752, !26, i64 65768, !6, i64 65808, !27, i64 65816, !31, i64 65864, !33, i64 65904, !34, i64 65992, !35, i64 66024, !35, i64 66056}
!11 = !{!"_ZTSN7rioring11object_baseE", !12, i64 8, !16, i64 24, !18, i64 56}
!12 = !{!"_ZTSSt23enable_shared_from_thisIN7rioring11object_baseEE", !13, i64 0}
!13 = !{!"_ZTSSt8weak_ptrIN7rioring11object_baseEE", !14, i64 0}
!14 = !{!"_ZTSSt10__weak_ptrIN7rioring11object_baseELN9__gnu_cxx12_Lock_policyE2EE", !6, i64 0, !15, i64 8}
!15 = !{!"_ZTSSt12__weak_countILN9__gnu_cxx12_Lock_policyE2EE", !6, i64 0}
!16 = !{!"_ZTSSt8functionIFvRSt10shared_ptrIN7rioring11object_baseEERKSt10error_codeEE", !17, i64 0, !6, i64 24}
!17 = !{!"_ZTSSt14_Function_base", !7, i64 0, !6, i64 16}
!18 = !{!"long", !7, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = !{!"_ZTS16sockaddr_storage", !21, i64 0, !7, i64 2, !18, i64 120}
!21 = !{!"short", !7, i64 0}
!22 = !{!"_ZTSSt5arrayIhLm65536EE", !7, i64 0}
!23 = !{!"_ZTSN7rioring13socket_object4typeE", !7, i64 0}
!24 = !{!"bool", !7, i64 0}
!25 = !{!"_ZTSSt5arrayIcLm16EE", !7, i64 0}
!26 = !{!"_ZTSSt5arrayIcLm40EE", !7, i64 0}
!27 = !{!"_ZTSN7rioring16critical_sectionE", !28, i64 0, !29, i64 8}
!28 = !{!"_ZTSN7rioring9lock_baseE"}
!29 = !{!"_ZTSSt5mutex", !30, i64 0}
!30 = !{!"_ZTSSt12__mutex_base", !7, i64 0}
!31 = !{!"_ZTSN7rioring9io_bufferE", !32, i64 0, !6, i64 8, !18, i64 16, !18, i64 24, !18, i64 32}
!32 = !{!"_ZTSN7rioring11buffer_baseE"}
!33 = !{!"_ZTSN7rioring16io_double_bufferE", !32, i64 0, !31, i64 8, !31, i64 48}
!34 = !{!"_ZTSSt8functionIFvRSt10shared_ptrIN7rioring13socket_objectEEPNS1_9io_bufferEP8sockaddrEE", !17, i64 0, !6, i64 24}
!35 = !{!"_ZTSSt8functionIFvRSt10shared_ptrIN7rioring13socket_objectEEEE", !17, i64 0, !6, i64 24}
!36 = distinct !{!36, !37}
!37 = !{!"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::chrono::duration" = 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: 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 @_ZN7rioring10udp_server4stopEv(ptr noundef nonnull align 8 dereferenceable(66088) %0) local_unnamed_addr #1 align 2 {
  %2 = alloca %"class.std::chrono::duration", align 8
  tail call void @_ZN7rioring13socket_object5closeENS0_10close_typeE(ptr noundef nonnull align 8 dereferenceable(66088) %0, i32 noundef 0)
  %3 = getelementptr inbounds i8, ptr %0, i64 72
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not1 = icmp eq i32 %4, 0
  br i1 %.not1, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %5 = call i64 @_ZNSt8literals15chrono_literalsli2msIJLc49EEEENSt6chrono8durationIlSt5ratioILl1ELl1000EEEEv()
  store i64 %5, ptr %2, align 8
  call void @_ZNSt11this_thread9sleep_forIlSt5ratioILl1ELl1000EEEEvRKNSt6chrono8durationIT_T0_EE(ptr noundef nonnull align 8 dereferenceable(8) %2)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  %6 = load i32, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !35

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

declare void @_ZN7rioring13socket_object5closeENS0_10close_typeE(ptr noundef nonnull align 8 dereferenceable(66088), i32 noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZNSt8literals15chrono_literalsli2msIJLc49EEEENSt6chrono8durationIlSt5ratioILl1ELl1000EEEEv() local_unnamed_addr #1

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 = { "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, !18, i64 72}
!6 = !{!"_ZTSN7rioring13socket_objectE", !7, i64 0, !11, i64 64, !18, i64 72, !19, i64 80, !21, i64 208, !22, i64 65744, !23, i64 65748, !20, i64 65750, !24, i64 65752, !25, i64 65768, !11, i64 65808, !26, i64 65816, !30, i64 65864, !32, i64 65904, !33, i64 65992, !34, i64 66024, !34, i64 66056}
!7 = !{!"_ZTSN7rioring11object_baseE", !8, i64 8, !15, i64 24, !17, i64 56}
!8 = !{!"_ZTSSt23enable_shared_from_thisIN7rioring11object_baseEE", !9, i64 0}
!9 = !{!"_ZTSSt8weak_ptrIN7rioring11object_baseEE", !10, i64 0}
!10 = !{!"_ZTSSt10__weak_ptrIN7rioring11object_baseELN9__gnu_cxx12_Lock_policyE2EE", !11, i64 0, !14, i64 8}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"_ZTSSt12__weak_countILN9__gnu_cxx12_Lock_policyE2EE", !11, i64 0}
!15 = !{!"_ZTSSt8functionIFvRSt10shared_ptrIN7rioring11object_baseEERKSt10error_codeEE", !16, i64 0, !11, i64 24}
!16 = !{!"_ZTSSt14_Function_base", !12, i64 0, !11, i64 16}
!17 = !{!"long", !12, i64 0}
!18 = !{!"int", !12, i64 0}
!19 = !{!"_ZTS16sockaddr_storage", !20, i64 0, !12, i64 2, !17, i64 120}
!20 = !{!"short", !12, i64 0}
!21 = !{!"_ZTSSt5arrayIhLm65536EE", !12, i64 0}
!22 = !{!"_ZTSN7rioring13socket_object4typeE", !12, i64 0}
!23 = !{!"bool", !12, i64 0}
!24 = !{!"_ZTSSt5arrayIcLm16EE", !12, i64 0}
!25 = !{!"_ZTSSt5arrayIcLm40EE", !12, i64 0}
!26 = !{!"_ZTSN7rioring16critical_sectionE", !27, i64 0, !28, i64 8}
!27 = !{!"_ZTSN7rioring9lock_baseE"}
!28 = !{!"_ZTSSt5mutex", !29, i64 0}
!29 = !{!"_ZTSSt12__mutex_base", !12, i64 0}
!30 = !{!"_ZTSN7rioring9io_bufferE", !31, i64 0, !11, i64 8, !17, i64 16, !17, i64 24, !17, i64 32}
!31 = !{!"_ZTSN7rioring11buffer_baseE"}
!32 = !{!"_ZTSN7rioring16io_double_bufferE", !31, i64 0, !30, i64 8, !30, i64 48}
!33 = !{!"_ZTSSt8functionIFvRSt10shared_ptrIN7rioring13socket_objectEEPNS1_9io_bufferEP8sockaddrEE", !16, i64 0, !11, i64 24}
!34 = !{!"_ZTSSt8functionIFvRSt10shared_ptrIN7rioring13socket_objectEEEE", !16, i64 0, !11, i64 24}
!35 = distinct !{!35, !36}
!36 = !{!"llvm.loop.mustprogress"}


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