; LLVM IR from turi-code/SFrame :: oss_src/fileio/oss_webstor/sysutils.ll (ZN7webstor8internal9EventSync7waitAnyEPPS1_mj)

; 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::EventWaiter" = type { %union.pthread_mutex_t, %union.pthread_cond_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 }
%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 }
%struct.timespec = type { i64, i64 }
%struct.timeval = type { i64, i64 }

; 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: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) #1

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK7webstor8internal9EventSync10add_waiterEPNS0_11EventWaiterE(ptr noundef nonnull align 8 dereferenceable(92), ptr noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK7webstor8internal9EventSync13remove_waiterEPNS0_11EventWaiterE(ptr noundef nonnull align 8 dereferenceable(92), ptr noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7webstor8internal9EventSync9get_stateEv(ptr noundef nonnull align 8 dereferenceable(92)) #3 align 2

; Function Attrs: nounwind
declare i32 @gettimeofday(ptr noundef, ptr noundef) #1

declare i32 @pthread_cond_timedwait(ptr noundef, ptr noundef, ptr noundef) #4

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7webstor8internal9EventSync7waitAnyEPPS1_mj(ptr noundef %0, i64 noundef %1, i32 noundef %2) #2 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca %"class.webstor::internal::EventWaiter", align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca %struct.timespec, align 8
  %15 = alloca %struct.timeval, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i64, align 8
  %19 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 88, ptr %8) #5
  call void @_ZN7webstor8internal11EventWaiterC1Ev(ptr noundef nonnull align 8 dereferenceable(88) %8)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %30, %3
  %21 = load i64, ptr %9, align 8, !tbaa !9
  %22 = load i64, ptr %6, align 8, !tbaa !9
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %33

25:                                               ; preds = %20
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i64, ptr %9, align 8, !tbaa !9
  %28 = getelementptr inbounds ptr, ptr %26, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  call void @_ZNK7webstor8internal9EventSync10add_waiterEPNS0_11EventWaiterE(ptr noundef nonnull align 8 dereferenceable(92) %29, ptr noundef %8)
  br label %30

30:                                               ; preds = %25
  %31 = load i64, ptr %9, align 8, !tbaa !9
  %32 = add i64 %31, 1
  store i64 %32, ptr %9, align 8, !tbaa !9
  br label %20, !llvm.loop !13

33:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %47, %33
  %35 = load i64, ptr %11, align 8, !tbaa !9
  %36 = load i64, ptr %6, align 8, !tbaa !9
  %37 = icmp ult i64 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %50

39:                                               ; preds = %34
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i64, ptr %11, align 8, !tbaa !9
  %42 = getelementptr inbounds ptr, ptr %40, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = call noundef i32 @_ZNK7webstor8internal9EventSync9get_stateEv(ptr noundef nonnull align 8 dereferenceable(92) %43)
  %45 = load i32, ptr %10, align 4, !tbaa !11
  %46 = add nsw i32 %45, %44
  store i32 %46, ptr %10, align 4, !tbaa !11
  br label %47

47:                                               ; preds = %39
  %48 = load i64, ptr %11, align 8, !tbaa !9
  %49 = add i64 %48, 1
  store i64 %49, ptr %11, align 8, !tbaa !9
  br label %34, !llvm.loop !15

50:                                               ; preds = %38
  %51 = load i32, ptr %10, align 4, !tbaa !11
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %69

53:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store i64 0, ptr %12, align 8, !tbaa !9
  br label %54

54:                                               ; preds = %64, %53
  %55 = load i64, ptr %12, align 8, !tbaa !9
  %56 = load i64, ptr %6, align 8, !tbaa !9
  %57 = icmp ult i64 %55, %56
  br i1 %57, label %59, label %58

58:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %67

59:                                               ; preds = %54
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = load i64, ptr %12, align 8, !tbaa !9
  %62 = getelementptr inbounds ptr, ptr %60, i64 %61
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  call void @_ZNK7webstor8internal9EventSync13remove_waiterEPNS0_11EventWaiterE(ptr noundef nonnull align 8 dereferenceable(92) %63, ptr noundef %8)
  br label %64

64:                                               ; preds = %59
  %65 = load i64, ptr %12, align 8, !tbaa !9
  %66 = add i64 %65, 1
  store i64 %66, ptr %12, align 8, !tbaa !9
  br label %54, !llvm.loop !16

67:                                               ; preds = %58
  %68 = load i32, ptr %10, align 4, !tbaa !11
  store i32 %68, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %144

69:                                               ; preds = %50
  %70 = getelementptr inbounds %"class.webstor::internal::EventWaiter", ptr %8, i32 0, i32 0
  %71 = call i32 @pthread_mutex_lock(ptr noundef %70) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %15) #5
  %72 = call i32 @gettimeofday(ptr noundef %15, ptr noundef null) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #5
  %73 = load i32, ptr %7, align 4, !tbaa !11
  %74 = udiv i32 %73, 1000
  store i32 %74, ptr %16, align 4, !tbaa !11
  %75 = load i32, ptr %7, align 4, !tbaa !11
  %76 = urem i32 %75, 1000
  store i32 %76, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #5
  %77 = load i32, ptr %7, align 4, !tbaa !11
  %78 = mul i32 %77, 1000000
  store i32 %78, ptr %17, align 4, !tbaa !11
  %79 = getelementptr inbounds %struct.timeval, ptr %15, i32 0, i32 1
  %80 = load i64, ptr %79, align 8, !tbaa !17
  %81 = mul nsw i64 %80, 1000
  %82 = getelementptr inbounds %struct.timespec, ptr %14, i32 0, i32 1
  store i64 %81, ptr %82, align 8, !tbaa !19
  %83 = getelementptr inbounds %struct.timeval, ptr %15, i32 0, i32 0
  %84 = load i64, ptr %83, align 8, !tbaa !21
  %85 = getelementptr inbounds %struct.timespec, ptr %14, i32 0, i32 0
  store i64 %84, ptr %85, align 8, !tbaa !22
  %86 = load i32, ptr %17, align 4, !tbaa !11
  %87 = zext i32 %86 to i64
  %88 = getelementptr inbounds %struct.timespec, ptr %14, i32 0, i32 1
  %89 = load i64, ptr %88, align 8, !tbaa !19
  %90 = add nsw i64 %89, %87
  store i64 %90, ptr %88, align 8, !tbaa !19
  %91 = load i32, ptr %16, align 4, !tbaa !11
  %92 = zext i32 %91 to i64
  %93 = getelementptr inbounds %struct.timespec, ptr %14, i32 0, i32 0
  %94 = load i64, ptr %93, align 8, !tbaa !22
  %95 = add nsw i64 %94, %92
  store i64 %95, ptr %93, align 8, !tbaa !22
  %96 = getelementptr inbounds %struct.timespec, ptr %14, i32 0, i32 1
  %97 = load i64, ptr %96, align 8, !tbaa !19
  %98 = icmp sgt i64 %97, 1000000000
  br i1 %98, label %99, label %106

99:                                               ; preds = %69
  %100 = getelementptr inbounds %struct.timespec, ptr %14, i32 0, i32 0
  %101 = load i64, ptr %100, align 8, !tbaa !22
  %102 = add nsw i64 %101, 1
  store i64 %102, ptr %100, align 8, !tbaa !22
  %103 = getelementptr inbounds %struct.timespec, ptr %14, i32 0, i32 1
  %104 = load i64, ptr %103, align 8, !tbaa !19
  %105 = sub nsw i64 %104, 1000000000
  store i64 %105, ptr %103, align 8, !tbaa !19
  br label %106

106:                                              ; preds = %99, %69
  %107 = getelementptr inbounds %"class.webstor::internal::EventWaiter", ptr %8, i32 0, i32 1
  %108 = getelementptr inbounds %"class.webstor::internal::EventWaiter", ptr %8, i32 0, i32 0
  %109 = call i32 @pthread_cond_timedwait(ptr noundef %107, ptr noundef %108, ptr noundef %14)
  %110 = getelementptr inbounds %"class.webstor::internal::EventWaiter", ptr %8, i32 0, i32 0
  %111 = call i32 @pthread_mutex_unlock(ptr noundef %110) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  store i64 0, ptr %18, align 8, !tbaa !9
  br label %112

112:                                              ; preds = %122, %106
  %113 = load i64, ptr %18, align 8, !tbaa !9
  %114 = load i64, ptr %6, align 8, !tbaa !9
  %115 = icmp ult i64 %113, %114
  br i1 %115, label %117, label %116

116:                                              ; preds = %112
  store i32 11, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  br label %125

117:                                              ; preds = %112
  %118 = load ptr, ptr %5, align 8, !tbaa !5
  %119 = load i64, ptr %18, align 8, !tbaa !9
  %120 = getelementptr inbounds ptr, ptr %118, i64 %119
  %121 = load ptr, ptr %120, align 8, !tbaa !5
  call void @_ZNK7webstor8internal9EventSync13remove_waiterEPNS0_11EventWaiterE(ptr noundef nonnull align 8 dereferenceable(92) %121, ptr noundef %8)
  br label %122

122:                                              ; preds = %117
  %123 = load i64, ptr %18, align 8, !tbaa !9
  %124 = add i64 %123, 1
  store i64 %124, ptr %18, align 8, !tbaa !9
  br label %112, !llvm.loop !23

125:                                              ; preds = %116
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #5
  store i64 0, ptr %19, align 8, !tbaa !9
  br label %126

126:                                              ; preds = %139, %125
  %127 = load i64, ptr %19, align 8, !tbaa !9
  %128 = load i64, ptr %6, align 8, !tbaa !9
  %129 = icmp ult i64 %127, %128
  br i1 %129, label %131, label %130

130:                                              ; preds = %126
  store i32 14, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  br label %142

131:                                              ; preds = %126
  %132 = load ptr, ptr %5, align 8, !tbaa !5
  %133 = load i64, ptr %19, align 8, !tbaa !9
  %134 = getelementptr inbounds ptr, ptr %132, i64 %133
  %135 = load ptr, ptr %134, align 8, !tbaa !5
  %136 = call noundef i32 @_ZNK7webstor8internal9EventSync9get_stateEv(ptr noundef nonnull align 8 dereferenceable(92) %135)
  %137 = load i32, ptr %10, align 4, !tbaa !11
  %138 = add nsw i32 %137, %136
  store i32 %138, ptr %10, align 4, !tbaa !11
  br label %139

139:                                              ; preds = %131
  %140 = load i64, ptr %19, align 8, !tbaa !9
  %141 = add i64 %140, 1
  store i64 %141, ptr %19, align 8, !tbaa !9
  br label %126, !llvm.loop !24

142:                                              ; preds = %130
  %143 = load i32, ptr %10, align 4, !tbaa !11
  store i32 %143, ptr %4, align 4
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #5
  br label %144

144:                                              ; preds = %142, %67
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 88, ptr %8) #5
  %145 = load i32, ptr %4, align 4
  ret i32 %145
}

declare void @_ZN7webstor8internal11EventWaiterC1Ev(ptr)

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = { "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 }

!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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = !{!18, !10, i64 8}
!18 = !{!"_ZTS7timeval", !10, i64 0, !10, i64 8}
!19 = !{!20, !10, i64 8}
!20 = !{!"_ZTS8timespec", !10, i64 0, !10, i64 8}
!21 = !{!18, !10, i64 0}
!22 = !{!20, !10, i64 0}
!23 = distinct !{!23, !14}
!24 = distinct !{!24, !14}


; 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.webstor::internal::EventWaiter" = type { %union.pthread_mutex_t, %union.pthread_cond_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 }
%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 }
%struct.timespec = type { i64, i64 }
%struct.timeval = type { i64, 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: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK7webstor8internal9EventSync10add_waiterEPNS0_11EventWaiterE(ptr noundef nonnull align 8 dereferenceable(92), ptr noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK7webstor8internal9EventSync13remove_waiterEPNS0_11EventWaiterE(ptr noundef nonnull align 8 dereferenceable(92), ptr noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7webstor8internal9EventSync9get_stateEv(ptr noundef nonnull align 8 dereferenceable(92)) local_unnamed_addr #3 align 2

; Function Attrs: nofree nounwind
declare noundef i32 @gettimeofday(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #4

declare i32 @pthread_cond_timedwait(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #5

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7webstor8internal9EventSync7waitAnyEPPS1_mj(ptr nocapture noundef readonly %0, i64 noundef %1, i32 noundef %2) local_unnamed_addr #2 align 2 {
  %4 = alloca %"class.webstor::internal::EventWaiter", align 8
  %5 = alloca %struct.timespec, align 8
  %6 = alloca %struct.timeval, align 8
  call void @llvm.lifetime.start.p0(i64 88, ptr nonnull %4) #6
  call void @_ZN7webstor8internal11EventWaiterC1Ev(ptr noundef nonnull align 8 dereferenceable(88) %4)
  %.not58 = icmp eq i64 %1, 0
  br i1 %.not58, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.04044 = phi i64 [ %9, %.lr.ph ], [ 0, %3 ]
  %7 = getelementptr inbounds ptr, ptr %0, i64 %.04044
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZNK7webstor8internal9EventSync10add_waiterEPNS0_11EventWaiterE(ptr noundef nonnull align 8 dereferenceable(92) %8, ptr noundef nonnull %4)
  %9 = add nuw i64 %.04044, 1
  %exitcond.not = icmp eq i64 %9, %1
  br i1 %exitcond.not, label %.lr.ph47, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph47
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %._crit_edge.thread, label %.lr.ph49

.lr.ph47:                                         ; preds = %.lr.ph, %.lr.ph47
  %.03846 = phi i64 [ %14, %.lr.ph47 ], [ 0, %.lr.ph ]
  %.03945 = phi i32 [ %13, %.lr.ph47 ], [ 0, %.lr.ph ]
  %10 = getelementptr inbounds ptr, ptr %0, i64 %.03846
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = call noundef i32 @_ZNK7webstor8internal9EventSync9get_stateEv(ptr noundef nonnull align 8 dereferenceable(92) %11)
  %13 = add nsw i32 %12, %.03945
  %14 = add nuw i64 %.03846, 1
  %exitcond64.not = icmp eq i64 %14, %1
  br i1 %exitcond64.not, label %._crit_edge, label %.lr.ph47, !llvm.loop !11

.lr.ph49:                                         ; preds = %._crit_edge, %.lr.ph49
  %.03748 = phi i64 [ %17, %.lr.ph49 ], [ 0, %._crit_edge ]
  %15 = getelementptr inbounds ptr, ptr %0, i64 %.03748
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  call void @_ZNK7webstor8internal9EventSync13remove_waiterEPNS0_11EventWaiterE(ptr noundef nonnull align 8 dereferenceable(92) %16, ptr noundef nonnull %4)
  %17 = add nuw i64 %.03748, 1
  %exitcond65.not = icmp eq i64 %17, %1
  br i1 %exitcond65.not, label %.loopexit, label %.lr.ph49, !llvm.loop !12

._crit_edge.thread:                               ; preds = %3, %._crit_edge
  %18 = call i32 @pthread_mutex_lock(ptr noundef nonnull %4) #6
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #6
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #6
  %19 = call i32 @gettimeofday(ptr noundef nonnull %6, ptr noundef null) #6
  %20 = udiv i32 %2, 1000
  %21 = urem i32 %2, 1000
  %22 = mul nuw nsw i32 %21, 1000000
  %23 = getelementptr inbounds i8, ptr %6, i64 8
  %24 = load i64, ptr %23, align 8, !tbaa !13
  %25 = mul nsw i64 %24, 1000
  %26 = getelementptr inbounds i8, ptr %5, i64 8
  %27 = load i64, ptr %6, align 8, !tbaa !16
  %28 = zext nneg i32 %22 to i64
  %29 = add nsw i64 %25, %28
  store i64 %29, ptr %26, align 8, !tbaa !17
  %30 = zext nneg i32 %20 to i64
  %31 = add nsw i64 %27, %30
  store i64 %31, ptr %5, align 8, !tbaa !19
  %32 = icmp sgt i64 %29, 1000000000
  br i1 %32, label %33, label %36

33:                                               ; preds = %._crit_edge.thread
  %34 = add nsw i64 %31, 1
  store i64 %34, ptr %5, align 8, !tbaa !19
  %35 = add nsw i64 %29, -1000000000
  store i64 %35, ptr %26, align 8, !tbaa !17
  br label %36

36:                                               ; preds = %33, %._crit_edge.thread
  %37 = getelementptr inbounds i8, ptr %4, i64 40
  %38 = call i32 @pthread_cond_timedwait(ptr noundef nonnull %37, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %39 = call i32 @pthread_mutex_unlock(ptr noundef nonnull %4) #6
  br i1 %.not58, label %._crit_edge56, label %.lr.ph52

.lr.ph52:                                         ; preds = %36, %.lr.ph52
  %.03550 = phi i64 [ %42, %.lr.ph52 ], [ 0, %36 ]
  %40 = getelementptr inbounds ptr, ptr %0, i64 %.03550
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  call void @_ZNK7webstor8internal9EventSync13remove_waiterEPNS0_11EventWaiterE(ptr noundef nonnull align 8 dereferenceable(92) %41, ptr noundef nonnull %4)
  %42 = add nuw i64 %.03550, 1
  %exitcond66.not = icmp eq i64 %42, %1
  br i1 %exitcond66.not, label %.lr.ph55, label %.lr.ph52, !llvm.loop !20

._crit_edge56:                                    ; preds = %.lr.ph55, %36
  %.1.lcssa = phi i32 [ 0, %36 ], [ %46, %.lr.ph55 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #6
  br label %.loopexit

.lr.ph55:                                         ; preds = %.lr.ph52, %.lr.ph55
  %.054 = phi i64 [ %47, %.lr.ph55 ], [ 0, %.lr.ph52 ]
  %.153 = phi i32 [ %46, %.lr.ph55 ], [ 0, %.lr.ph52 ]
  %43 = getelementptr inbounds ptr, ptr %0, i64 %.054
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = call noundef i32 @_ZNK7webstor8internal9EventSync9get_stateEv(ptr noundef nonnull align 8 dereferenceable(92) %44)
  %46 = add nsw i32 %45, %.153
  %47 = add nuw i64 %.054, 1
  %exitcond67.not = icmp eq i64 %47, %1
  br i1 %exitcond67.not, label %._crit_edge56, label %.lr.ph55, !llvm.loop !21

.loopexit:                                        ; preds = %.lr.ph49, %._crit_edge56
  %.036 = phi i32 [ %.1.lcssa, %._crit_edge56 ], [ %13, %.lr.ph49 ]
  call void @llvm.lifetime.end.p0(i64 88, ptr nonnull %4) #6
  ret i32 %.036
}

declare void @_ZN7webstor8internal11EventWaiterC1Ev(ptr) local_unnamed_addr

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = { 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 #5 = { "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 #6 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = !{!14, !15, i64 8}
!14 = !{!"_ZTS7timeval", !15, i64 0, !15, i64 8}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !15, i64 0}
!17 = !{!18, !15, i64 8}
!18 = !{!"_ZTS8timespec", !15, i64 0, !15, i64 8}
!19 = !{!18, !15, i64 0}
!20 = distinct !{!20, !10}
!21 = distinct !{!21, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass