; LLVM IR from vczh/herodb :: Kernel/Source/Vlpp.ll (ZN2vl11EventObject4WaitEv)

; 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.vl::EventObject" = type { %"class.vl::WaitableObject", ptr }
%"class.vl::WaitableObject" = type { %"class.vl::Object" }
%"class.vl::Object" = type { ptr }
%"struct.vl::threading_internal::EventData" = type { i8, i8, %"class.vl::CriticalSection", %"class.vl::ConditionVariable", i64 }
%"class.vl::CriticalSection" = type { %"class.vl::Object", ptr }
%"class.vl::ConditionVariable" = type { %"class.vl::Object", ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN2vl11EventObject4WaitEv(ptr noundef nonnull align 8 dereferenceable(16) %0) unnamed_addr #0 align 2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8
  %5 = getelementptr inbounds %"class.vl::EventObject", ptr %4, i32 0, i32 1
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = icmp ne ptr %6, null
  br i1 %7, label %9, label %8

8:                                                ; preds = %1
  store i1 false, ptr %2, align 1
  br label %51

9:                                                ; preds = %1
  %10 = getelementptr inbounds %"class.vl::EventObject", ptr %4, i32 0, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds %"struct.vl::threading_internal::EventData", ptr %11, i32 0, i32 2
  call void @_ZN2vl15CriticalSection5EnterEv(ptr noundef nonnull align 8 dereferenceable(16) %12)
  %13 = getelementptr inbounds %"class.vl::EventObject", ptr %4, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds %"struct.vl::threading_internal::EventData", ptr %14, i32 0, i32 1
  %16 = load volatile i8, ptr %15, align 1, !tbaa !13, !range !19, !noundef !20
  %17 = trunc i8 %16 to i1
  br i1 %17, label %18, label %29

18:                                               ; preds = %9
  %19 = getelementptr inbounds %"class.vl::EventObject", ptr %4, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds %"struct.vl::threading_internal::EventData", ptr %20, i32 0, i32 0
  %22 = load i8, ptr %21, align 8, !tbaa !21, !range !19, !noundef !20
  %23 = trunc i8 %22 to i1
  br i1 %23, label %24, label %28

24:                                               ; preds = %18
  %25 = getelementptr inbounds %"class.vl::EventObject", ptr %4, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds %"struct.vl::threading_internal::EventData", ptr %26, i32 0, i32 1
  store volatile i8 0, ptr %27, align 1, !tbaa !13
  br label %28

28:                                               ; preds = %24, %18
  br label %47

29:                                               ; preds = %9
  %30 = getelementptr inbounds %"class.vl::EventObject", ptr %4, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = getelementptr inbounds %"struct.vl::threading_internal::EventData", ptr %31, i32 0, i32 4
  %33 = load volatile i64, ptr %32, align 8, !tbaa !22
  %34 = add nsw i64 %33, 1
  store volatile i64 %34, ptr %32, align 8, !tbaa !22
  %35 = getelementptr inbounds %"class.vl::EventObject", ptr %4, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = getelementptr inbounds %"struct.vl::threading_internal::EventData", ptr %36, i32 0, i32 3
  %38 = getelementptr inbounds %"class.vl::EventObject", ptr %4, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = getelementptr inbounds %"struct.vl::threading_internal::EventData", ptr %39, i32 0, i32 2
  %41 = call noundef zeroext i1 @_ZN2vl17ConditionVariable9SleepWithERNS_15CriticalSectionE(ptr noundef nonnull align 8 dereferenceable(16) %37, ptr noundef nonnull align 8 dereferenceable(16) %40)
  %42 = getelementptr inbounds %"class.vl::EventObject", ptr %4, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = getelementptr inbounds %"struct.vl::threading_internal::EventData", ptr %43, i32 0, i32 4
  %45 = load volatile i64, ptr %44, align 8, !tbaa !22
  %46 = add nsw i64 %45, -1
  store volatile i64 %46, ptr %44, align 8, !tbaa !22
  br label %47

47:                                               ; preds = %29, %28
  %48 = getelementptr inbounds %"class.vl::EventObject", ptr %4, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !9
  %50 = getelementptr inbounds %"struct.vl::threading_internal::EventData", ptr %49, i32 0, i32 2
  call void @_ZN2vl15CriticalSection5LeaveEv(ptr noundef nonnull align 8 dereferenceable(16) %50)
  store i1 true, ptr %2, align 1
  br label %51

51:                                               ; preds = %47, %8
  %52 = load i1, ptr %2, align 1
  ret i1 %52
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN2vl17ConditionVariable9SleepWithERNS_15CriticalSectionE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #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 = { 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" }

!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, !6, i64 8}
!10 = !{!"_ZTSN2vl11EventObjectE", !11, i64 0, !6, i64 8}
!11 = !{!"_ZTSN2vl14WaitableObjectE", !12, i64 0}
!12 = !{!"_ZTSN2vl6ObjectE"}
!13 = !{!14, !15, i64 1}
!14 = !{!"_ZTSN2vl18threading_internal9EventDataE", !15, i64 0, !15, i64 1, !16, i64 8, !17, i64 24, !18, i64 40}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"_ZTSN2vl15CriticalSectionE", !12, i64 0, !6, i64 8}
!17 = !{!"_ZTSN2vl17ConditionVariableE", !12, i64 0, !6, i64 8}
!18 = !{!"long", !7, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!14, !15, i64 0}
!22 = !{!14, !18, i64 40}


; 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 zeroext i1 @_ZN2vl11EventObject4WaitEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp ne ptr %3, null
  br i1 %.not, label %4, label %28

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %3, i64 8
  tail call void @_ZN2vl15CriticalSection5EnterEv(ptr noundef nonnull align 8 dereferenceable(16) %5)
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 1
  %8 = load volatile i8, ptr %7, align 1, !tbaa !12, !range !18, !noundef !19
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %10, label %14

10:                                               ; preds = %4
  %11 = load i8, ptr %6, align 8, !tbaa !20, !range !18, !noundef !19
  %12 = trunc nuw i8 %11 to i1
  br i1 %12, label %13, label %25

13:                                               ; preds = %10
  store volatile i8 0, ptr %7, align 1, !tbaa !12
  br label %25

14:                                               ; preds = %4
  %15 = getelementptr inbounds i8, ptr %6, i64 40
  %16 = load volatile i64, ptr %15, align 8, !tbaa !21
  %17 = add nsw i64 %16, 1
  store volatile i64 %17, ptr %15, align 8, !tbaa !21
  %18 = getelementptr inbounds i8, ptr %6, i64 24
  %19 = getelementptr inbounds i8, ptr %6, i64 8
  %20 = tail call noundef zeroext i1 @_ZN2vl17ConditionVariable9SleepWithERNS_15CriticalSectionE(ptr noundef nonnull align 8 dereferenceable(16) %18, ptr noundef nonnull align 8 dereferenceable(16) %19)
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 40
  %23 = load volatile i64, ptr %22, align 8, !tbaa !21
  %24 = add nsw i64 %23, -1
  store volatile i64 %24, ptr %22, align 8, !tbaa !21
  br label %25

25:                                               ; preds = %10, %13, %14
  %26 = phi ptr [ %6, %10 ], [ %6, %13 ], [ %21, %14 ]
  %27 = getelementptr inbounds i8, ptr %26, i64 8
  tail call void @_ZN2vl15CriticalSection5LeaveEv(ptr noundef nonnull align 8 dereferenceable(16) %27)
  br label %28

28:                                               ; preds = %1, %25
  ret i1 %.not
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2vl15CriticalSection5EnterEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2vl15CriticalSection5LeaveEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN2vl17ConditionVariable9SleepWithERNS_15CriticalSectionE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) 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 = { 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" }

!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, !9, i64 8}
!6 = !{!"_ZTSN2vl11EventObjectE", !7, i64 0, !9, i64 8}
!7 = !{!"_ZTSN2vl14WaitableObjectE", !8, i64 0}
!8 = !{!"_ZTSN2vl6ObjectE"}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!13, !14, i64 1}
!13 = !{!"_ZTSN2vl18threading_internal9EventDataE", !14, i64 0, !14, i64 1, !15, i64 8, !16, i64 24, !17, i64 40}
!14 = !{!"bool", !10, i64 0}
!15 = !{!"_ZTSN2vl15CriticalSectionE", !8, i64 0, !9, i64 8}
!16 = !{!"_ZTSN2vl17ConditionVariableE", !8, i64 0, !9, i64 8}
!17 = !{!"long", !10, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!13, !14, i64 0}
!21 = !{!13, !17, i64 40}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass