; LLVM IR from vczh/herodb :: Kernel/Source/Utility (Lock)

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

%"struct.vl::database::IdObject" = type { i64 }
%"class.vl::SpinLock::Scope" = type { %"class.vl::Object", ptr }
%"class.vl::Object" = type { ptr }
%"class.vl::database::LockManager" = type { %"class.vl::Object", ptr, %"class.vl::SpinLock", %"class.vl::collections::Dictionary", %"class.vl::collections::Dictionary.10", %"class.vl::collections::Array", %"class.vl::collections::Dictionary.33" }
%"class.vl::SpinLock" = type { %"class.vl::Object", i64 }
%"class.vl::collections::Dictionary" = type { %"class.vl::Object", %"class.vl::collections::SortedList", %"class.vl::collections::List", %"class.vl::collections::IEnumerable.9" }
%"class.vl::collections::SortedList" = type { %"class.vl::collections::ListBase.base", %"class.vl::collections::IEnumerable" }
%"class.vl::collections::ListBase.base" = type <{ %"class.vl::collections::ArrayBase.base", i64, i8 }>
%"class.vl::collections::ArrayBase.base" = type { %"class.vl::collections::ListStore", ptr, i64 }
%"class.vl::collections::ListStore" = type { %"class.vl::Object" }
%"class.vl::collections::IEnumerable" = type { %"class.vl::Interface" }
%"class.vl::Interface" = type { ptr }
%"class.vl::collections::List" = type { %"class.vl::collections::ListBase.base.8", %"class.vl::collections::IEnumerable.6" }
%"class.vl::collections::ListBase.base.8" = type <{ %"class.vl::collections::ArrayBase.base.7", i64, i8 }>
%"class.vl::collections::ArrayBase.base.7" = type { %"class.vl::collections::ListStore.5", ptr, i64 }
%"class.vl::collections::ListStore.5" = type { %"class.vl::Object" }
%"class.vl::collections::IEnumerable.6" = type { %"class.vl::Interface" }
%"class.vl::collections::IEnumerable.9" = type { %"class.vl::Interface" }
%"class.vl::collections::Dictionary.10" = type { %"class.vl::Object", %"class.vl::collections::SortedList.11", %"class.vl::collections::List.19", %"class.vl::collections::IEnumerable.27" }
%"class.vl::collections::SortedList.11" = type { %"class.vl::collections::ListBase.base.17", %"class.vl::collections::IEnumerable.15" }
%"class.vl::collections::ListBase.base.17" = type <{ %"class.vl::collections::ArrayBase.base.16", i64, i8 }>
%"class.vl::collections::ArrayBase.base.16" = type { %"class.vl::collections::ListStore.14", ptr, i64 }
%"class.vl::collections::ListStore.14" = type { %"class.vl::Object" }
%"class.vl::collections::IEnumerable.15" = type { %"class.vl::Interface" }
%"class.vl::collections::List.19" = type { %"class.vl::collections::ListBase.base.25", %"class.vl::collections::IEnumerable.23" }
%"class.vl::collections::ListBase.base.25" = type <{ %"class.vl::collections::ArrayBase.base.24", i64, i8 }>
%"class.vl::collections::ArrayBase.base.24" = type { %"class.vl::collections::ListStore.22", ptr, i64 }
%"class.vl::collections::ListStore.22" = type { %"class.vl::Object" }
%"class.vl::collections::IEnumerable.23" = type { %"class.vl::Interface" }
%"class.vl::collections::IEnumerable.27" = type { %"class.vl::Interface" }
%"class.vl::collections::Array" = type { %"class.vl::collections::ArrayBase.base.32", %"class.vl::collections::IEnumerable.31" }
%"class.vl::collections::ArrayBase.base.32" = type { %"class.vl::collections::ListStore.30", ptr, i64 }
%"class.vl::collections::ListStore.30" = type { %"class.vl::Object" }
%"class.vl::collections::IEnumerable.31" = type { %"class.vl::Interface" }
%"class.vl::collections::Dictionary.33" = type { %"class.vl::Object", %"class.vl::collections::SortedList.34", %"class.vl::collections::List.42", %"class.vl::collections::IEnumerable.50" }
%"class.vl::collections::SortedList.34" = type { %"class.vl::collections::ListBase.base.40", %"class.vl::collections::IEnumerable.38" }
%"class.vl::collections::ListBase.base.40" = type <{ %"class.vl::collections::ArrayBase.base.39", i64, i8 }>
%"class.vl::collections::ArrayBase.base.39" = type { %"class.vl::collections::ListStore.37", ptr, i64 }
%"class.vl::collections::ListStore.37" = type { %"class.vl::Object" }
%"class.vl::collections::IEnumerable.38" = type { %"class.vl::Interface" }
%"class.vl::collections::List.42" = type { %"class.vl::collections::ListBase.base.48", %"class.vl::collections::IEnumerable.46" }
%"class.vl::collections::ListBase.base.48" = type <{ %"class.vl::collections::ArrayBase.base.47", i64, i8 }>
%"class.vl::collections::ArrayBase.base.47" = type { %"class.vl::collections::ListStore.45", ptr, i64 }
%"class.vl::collections::ListStore.45" = type { %"class.vl::Object" }
%"class.vl::collections::IEnumerable.46" = type { %"class.vl::Interface" }
%"class.vl::collections::IEnumerable.50" = type { %"class.vl::Interface" }

; 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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN2vl8database11LockManager17ReleaseLockUnsafeENS0_8IdObjectImLl3EEERKNS0_10LockTargetE(ptr noundef nonnull align 8 dereferenceable(400), i64, ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

declare void @_ZN2vl8SpinLock5ScopeC1ERS0_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #3

; Function Attrs: nounwind
declare void @_ZN2vl8SpinLock5ScopeD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #4

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN2vl8database11LockManager11ReleaseLockENS0_8IdObjectImLl3EEERKNS0_10LockTargetE(ptr noundef nonnull align 8 dereferenceable(400) %0, i64 %1, ptr noundef nonnull align 8 dereferenceable(24) %2) #2 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca %"struct.vl::database::IdObject", align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca %"class.vl::SpinLock::Scope", align 8
  %11 = alloca %"struct.vl::database::IdObject", align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = getelementptr inbounds %"struct.vl::database::IdObject", ptr %4, i32 0, i32 0
  store i64 %1, ptr %14, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #5
  store i8 0, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #5
  store i8 1, ptr %8, align 1, !tbaa !9
  %16 = load i8, ptr %8, align 1, !tbaa !9, !range !11, !noundef !12
  %17 = trunc i8 %16 to i1
  br i1 %17, label %18, label %37

18:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #5
  %19 = getelementptr inbounds %"class.vl::database::LockManager", ptr %15, i32 0, i32 2
  call void @_ZN2vl8SpinLock5ScopeC1ERS0_(ptr noundef nonnull align 8 dereferenceable(16) %10, ptr noundef nonnull align 8 dereferenceable(16) %19)
  store ptr %10, ptr %9, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %31, %18
  %21 = load i8, ptr %8, align 1, !tbaa !9, !range !11, !noundef !12
  %22 = trunc i8 %21 to i1
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  call void @_ZN2vl8SpinLock5ScopeD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %10) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %36

24:                                               ; preds = %20
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 8 %4, i64 8, i1 false), !tbaa.struct !13
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %"struct.vl::database::IdObject", ptr %11, i32 0, i32 0
  %27 = load i64, ptr %26, align 8
  %28 = invoke noundef zeroext i1 @_ZN2vl8database11LockManager17ReleaseLockUnsafeENS0_8IdObjectImLl3EEERKNS0_10LockTargetE(ptr noundef nonnull align 8 dereferenceable(400) %15, i64 %27, ptr noundef nonnull align 8 dereferenceable(24) %25)
          to label %29 unwind label %32

29:                                               ; preds = %24
  %30 = zext i1 %28 to i8
  store i8 %30, ptr %7, align 1, !tbaa !9
  br label %31

31:                                               ; preds = %29
  store i8 0, ptr %8, align 1, !tbaa !9
  br label %20, !llvm.loop !16

32:                                               ; preds = %24
  %33 = landingpad { ptr, i32 }
          cleanup
  %34 = extractvalue { ptr, i32 } %33, 0
  store ptr %34, ptr %12, align 8
  %35 = extractvalue { ptr, i32 } %33, 1
  store i32 %35, ptr %13, align 4
  call void @_ZN2vl8SpinLock5ScopeD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %10) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #5
  br label %40

36:                                               ; preds = %23
  br label %37

37:                                               ; preds = %36, %3
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #5
  %38 = load i8, ptr %7, align 1, !tbaa !9, !range !11, !noundef !12
  %39 = trunc i8 %38 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #5
  ret i1 %39

40:                                               ; preds = %32
  %41 = load ptr, ptr %12, align 8
  %42 = load i32, ptr %13, align 4
  %43 = insertvalue { ptr, i32 } poison, ptr %41, 0
  %44 = insertvalue { ptr, i32 } %43, i32 %42, 1
  resume { ptr, i32 } %44
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 "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 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{i64 0, i64 8, !14}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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.vl::SpinLock::Scope" = type { %"class.vl::Object", ptr }
%"class.vl::Object" = type { ptr }

; 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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN2vl8database11LockManager17ReleaseLockUnsafeENS0_8IdObjectImLl3EEERKNS0_10LockTargetE(ptr noundef nonnull align 8 dereferenceable(400), i64, ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

declare void @_ZN2vl8SpinLock5ScopeC1ERS0_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2

; Function Attrs: nounwind
declare void @_ZN2vl8SpinLock5ScopeD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN2vl8database11LockManager11ReleaseLockENS0_8IdObjectImLl3EEERKNS0_10LockTargetE(ptr noundef nonnull align 8 dereferenceable(400) %0, i64 %1, ptr noundef nonnull align 8 dereferenceable(24) %2) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca %"class.vl::SpinLock::Scope", align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  call void @_ZN2vl8SpinLock5ScopeC1ERS0_(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 8 dereferenceable(16) %5)
  %6 = invoke noundef zeroext i1 @_ZN2vl8database11LockManager17ReleaseLockUnsafeENS0_8IdObjectImLl3EEERKNS0_10LockTargetE(ptr noundef nonnull align 8 dereferenceable(400) %0, i64 %1, ptr noundef nonnull align 8 dereferenceable(24) %2)
          to label %7 unwind label %8, !llvm.loop !5

7:                                                ; preds = %3
  call void @_ZN2vl8SpinLock5ScopeD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %4) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  ret i1 %6

8:                                                ; preds = %3
  %9 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN2vl8SpinLock5ScopeD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %4) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  resume { ptr, i32 } %9
}

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 = { 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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,SROAPass,SimplifyCFGPass