; LLVM IR from turi-code/SFrame :: oss_src/fileio/oss_webstor (asyncurl)

; 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.webstor::internal::AsyncLoop" = type <{ ptr, i8, [7 x i8], %"class.webstor::internal::TaskCtrl", i32, [4 x i8], %"class.webstor::internal::SocketPool", %"class.webstor::internal::ExLockSync", ptr, %"class.std::vector", %"class.std::vector", i64, i8, [7 x i8] }>
%"class.webstor::internal::TaskCtrl" = type { %"class.webstor::internal::auto_scope" }
%"class.webstor::internal::auto_scope" = type { i64 }
%"class.webstor::internal::SocketPool" = type { ptr, %"class.webstor::internal::EventSync" }
%"class.webstor::internal::EventSync" = type <{ %union.pthread_mutex_t, %"class.std::set", 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 }
%"class.std::set" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<webstor::internal::EventWaiter *, webstor::internal::EventWaiter *, std::_Identity<webstor::internal::EventWaiter *>, std::less<webstor::internal::EventWaiter *>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<webstor::internal::EventWaiter *, webstor::internal::EventWaiter *, std::_Identity<webstor::internal::EventWaiter *>, std::less<webstor::internal::EventWaiter *>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"class.webstor::internal::ExLockSync" = type { %"union.webstor::internal::ExLockSync::Data" }
%"union.webstor::internal::ExLockSync::Data" = type { %union.pthread_mutex_t }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<void *, std::allocator<void *>>::_Vector_impl" }
%"struct.std::_Vector_base<void *, std::allocator<void *>>::_Vector_impl" = type { %"struct.std::_Vector_base<void *, std::allocator<void *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<void *, std::allocator<void *>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7webstor8internal9AsyncLoop13handleTimeoutEPvlS2_(ptr noundef %0, i64 noundef %1, ptr noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %10, ptr %7, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %3
  br label %12

12:                                               ; preds = %11
  br label %13

13:                                               ; preds = %12
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %20

16:                                               ; preds = %13
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZN7webstor8internal9AsyncLoop19executeSocketActionEij(ptr noundef nonnull align 8 dereferenceable(241) %17, i32 noundef -1, i32 noundef 0)
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %"class.webstor::internal::AsyncLoop", ptr %18, i32 0, i32 4
  store i32 3000, ptr %19, align 8, !tbaa !11
  br label %27

20:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = trunc i64 %21 to i32
  store i32 %22, ptr %8, align 4, !tbaa !32
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 3000, ptr %9, align 4, !tbaa !32
  %23 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIjERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %24 = load i32, ptr %23, align 4, !tbaa !32
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %"class.webstor::internal::AsyncLoop", ptr %25, i32 0, i32 4
  store i32 %24, ptr %26, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %27

27:                                               ; preds = %20, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i32 0
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7webstor8internal9AsyncLoop19executeSocketActionEij(ptr noundef nonnull align 8 dereferenceable(241), i32 noundef, i32 noundef) #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIjERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !16, i64 24}
!12 = !{!"_ZTSN7webstor8internal9AsyncLoopE", !6, i64 0, !13, i64 8, !14, i64 16, !16, i64 24, !17, i64 32, !27, i64 136, !6, i64 176, !28, i64 184, !28, i64 208, !10, i64 232, !13, i64 240}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSN7webstor8internal8TaskCtrlE", !15, i64 0}
!15 = !{!"_ZTSN7webstor8internal10auto_scopeImNS0_15TaskCtrlDeleterELy0EEE", !10, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!"_ZTSN7webstor8internal10SocketPoolE", !6, i64 0, !18, i64 8}
!18 = !{!"_ZTSN7webstor8internal9EventSyncE", !7, i64 0, !19, i64 40, !16, i64 88}
!19 = !{!"_ZTSSt3setIPN7webstor8internal11EventWaiterESt4lessIS3_ESaIS3_EE", !20, i64 0}
!20 = !{!"_ZTSSt8_Rb_treeIPN7webstor8internal11EventWaiterES3_St9_IdentityIS3_ESt4lessIS3_ESaIS3_EE", !21, i64 0}
!21 = !{!"_ZTSNSt8_Rb_treeIPN7webstor8internal11EventWaiterES3_St9_IdentityIS3_ESt4lessIS3_ESaIS3_EE13_Rb_tree_implIS7_Lb1EEE", !22, i64 0, !24, i64 8}
!22 = !{!"_ZTSSt20_Rb_tree_key_compareISt4lessIPN7webstor8internal11EventWaiterEEE", !23, i64 0}
!23 = !{!"_ZTSSt4lessIPN7webstor8internal11EventWaiterEE"}
!24 = !{!"_ZTSSt15_Rb_tree_header", !25, i64 0, !10, i64 32}
!25 = !{!"_ZTSSt18_Rb_tree_node_base", !26, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!26 = !{!"_ZTSSt14_Rb_tree_color", !7, i64 0}
!27 = !{!"_ZTSN7webstor8internal10ExLockSyncE", !7, i64 0}
!28 = !{!"_ZTSSt6vectorIPvSaIS0_EE", !29, i64 0}
!29 = !{!"_ZTSSt12_Vector_baseIPvSaIS0_EE", !30, i64 0}
!30 = !{!"_ZTSNSt12_Vector_baseIPvSaIS0_EE12_Vector_implE", !31, i64 0}
!31 = !{!"_ZTSNSt12_Vector_baseIPvSaIS0_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!32 = !{!16, !16, i64 0}


; 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"

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7webstor8internal9AsyncLoop13handleTimeoutEPvlS2_(ptr nocapture noundef readnone %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #0 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = icmp eq i64 %1, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %3
  tail call void @_ZN7webstor8internal9AsyncLoop19executeSocketActionEij(ptr noundef nonnull align 8 dereferenceable(241) %2, i32 noundef -1, i32 noundef 0)
  br label %12

8:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %9 = trunc i64 %1 to i32
  store i32 %9, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  store i32 3000, ptr %5, align 4, !tbaa !5
  %10 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIjERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %11 = load i32, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br label %12

12:                                               ; preds = %8, %7
  %.sink = phi i32 [ 3000, %7 ], [ %11, %8 ]
  %13 = getelementptr inbounds i8, ptr %2, i64 24
  store i32 %.sink, ptr %13, align 8
  ret i32 0
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7webstor8internal9AsyncLoop19executeSocketActionEij(ptr noundef nonnull align 8 dereferenceable(241), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIjERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass