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

; 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.15" = type { i64 }
%"struct.vl::database::IdObject" = type { i32 }
%"class.vl::database::log_internal::LogAddressItem" = type { %"class.vl::Object", ptr, %"struct.vl::database::IdObject", i64, i64, %"class.vl::collections::List" }
%"class.vl::Object" = type { ptr }
%"class.vl::collections::List" = 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 }

; 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) #0

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

declare i64 @_ZN2vl8database13BufferManager12GetIndexPageENS0_8IdObjectIiLl0EEE(ptr noundef nonnull align 8 dereferenceable(168), i32) #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN2vl11collections4ListINS_8database8IdObjectImLl1EEES4_E3AddERKS4_(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef nonnull align 8 dereferenceable(8)) #3 align 2

declare noundef ptr @_ZN2vl8database13BufferManager8LockPageENS0_8IdObjectIiLl0EEENS2_ImLl1EEE(ptr noundef nonnull align 8 dereferenceable(168), i32, i64) #2

declare noundef zeroext i1 @_ZN2vl8database13BufferManager10UnlockPageENS0_8IdObjectIiLl0EEENS2_ImLl1EEEPvNS0_15PersistanceTypeE(ptr noundef nonnull align 8 dereferenceable(168), i32, i64, ptr noundef, i32 noundef) #2

; 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
define dso_local noundef i64 @_ZN2vl8database12log_internal14LogAddressItem23InitializeExistingItemsEv(ptr noundef nonnull align 8 dereferenceable(88) %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca %"struct.vl::database::IdObject.15", align 8
  %5 = alloca %"struct.vl::database::IdObject", align 4
  %6 = alloca %"struct.vl::database::IdObject.15", align 8
  %7 = alloca ptr, align 8
  %8 = alloca %"struct.vl::database::IdObject", align 4
  %9 = alloca %"struct.vl::database::IdObject.15", align 8
  %10 = alloca %"struct.vl::database::IdObject", align 4
  %11 = alloca %"struct.vl::database::IdObject.15", align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %12 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store i64 0, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %13 = getelementptr inbounds %"class.vl::database::log_internal::LogAddressItem", ptr %12, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds %"class.vl::database::log_internal::LogAddressItem", ptr %12, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 8 %15, i64 4, i1 false), !tbaa.struct !21
  %16 = getelementptr inbounds %"struct.vl::database::IdObject", ptr %5, i32 0, i32 0
  %17 = load i32, ptr %16, align 4
  %18 = call i64 @_ZN2vl8database13BufferManager12GetIndexPageENS0_8IdObjectIiLl0EEE(ptr noundef nonnull align 8 dereferenceable(168) %14, i32 %17)
  %19 = getelementptr inbounds %"struct.vl::database::IdObject.15", ptr %4, i32 0, i32 0
  store i64 %18, ptr %19, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %20 = call i64 @_ZN2vl8database8IdObjectImLl1EE7InvalidEv()
  %21 = getelementptr inbounds %"struct.vl::database::IdObject.15", ptr %6, i32 0, i32 0
  store i64 %20, ptr %21, align 8
  br label %22

22:                                               ; preds = %24, %1
  %23 = call noundef zeroext i1 @_ZNK2vl8database8IdObjectImLl1EE7IsValidEv(ptr noundef nonnull align 8 dereferenceable(8) %4)
  br i1 %23, label %24, label %53

24:                                               ; preds = %22
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %6, ptr align 8 %4, i64 8, i1 false), !tbaa.struct !23
  %25 = getelementptr inbounds %"class.vl::database::log_internal::LogAddressItem", ptr %12, i32 0, i32 5
  %26 = call noundef i64 @_ZN2vl11collections4ListINS_8database8IdObjectImLl1EEES4_E3AddERKS4_(ptr noundef nonnull align 8 dereferenceable(33) %25, ptr noundef nonnull align 8 dereferenceable(8) %4)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %27 = getelementptr inbounds %"class.vl::database::log_internal::LogAddressItem", ptr %12, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = getelementptr inbounds %"class.vl::database::log_internal::LogAddressItem", ptr %12, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 8 %29, i64 4, i1 false), !tbaa.struct !21
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %6, i64 8, i1 false), !tbaa.struct !23
  %30 = getelementptr inbounds %"struct.vl::database::IdObject", ptr %8, i32 0, i32 0
  %31 = load i32, ptr %30, align 4
  %32 = getelementptr inbounds %"struct.vl::database::IdObject.15", ptr %9, i32 0, i32 0
  %33 = load i64, ptr %32, align 8
  %34 = call noundef ptr @_ZN2vl8database13BufferManager8LockPageENS0_8IdObjectIiLl0EEENS2_ImLl1EEE(ptr noundef nonnull align 8 dereferenceable(168) %28, i32 %31, i64 %33)
  store ptr %34, ptr %7, align 8, !tbaa !5
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds i64, ptr %35, i64 1
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = getelementptr inbounds %"struct.vl::database::IdObject.15", ptr %4, i32 0, i32 0
  store i64 %37, ptr %38, align 8, !tbaa !24
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds i64, ptr %39, i64 0
  %41 = load i64, ptr %40, align 8, !tbaa !9
  %42 = load i64, ptr %3, align 8, !tbaa !9
  %43 = add i64 %42, %41
  store i64 %43, ptr %3, align 8, !tbaa !9
  %44 = getelementptr inbounds %"class.vl::database::log_internal::LogAddressItem", ptr %12, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = getelementptr inbounds %"class.vl::database::log_internal::LogAddressItem", ptr %12, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 8 %46, i64 4, i1 false), !tbaa.struct !21
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 8 %6, i64 8, i1 false), !tbaa.struct !23
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.vl::database::IdObject", ptr %10, i32 0, i32 0
  %49 = load i32, ptr %48, align 4
  %50 = getelementptr inbounds %"struct.vl::database::IdObject.15", ptr %11, i32 0, i32 0
  %51 = load i64, ptr %50, align 8
  %52 = call noundef zeroext i1 @_ZN2vl8database13BufferManager10UnlockPageENS0_8IdObjectIiLl0EEENS2_ImLl1EEEPvNS0_15PersistanceTypeE(ptr noundef nonnull align 8 dereferenceable(168) %45, i32 %49, i64 %51, ptr noundef %47, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %22, !llvm.loop !26

53:                                               ; preds = %22
  %54 = load i64, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret i64 %54
}

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZN2vl8database8IdObjectImLl1EE7InvalidEv() #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK2vl8database8IdObjectImLl1EE7IsValidEv(ptr noundef nonnull align 8 dereferenceable(8)) #4 align 2

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 #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, !6, i64 8}
!12 = !{!"_ZTSN2vl8database12log_internal14LogAddressItemE", !13, i64 0, !6, i64 8, !14, i64 16, !10, i64 24, !10, i64 32, !16, i64 40}
!13 = !{!"_ZTSN2vl6ObjectE"}
!14 = !{!"_ZTSN2vl8database8IdObjectIiLl0EEE", !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!"_ZTSN2vl11collections4ListINS_8database8IdObjectImLl1EEES4_EE", !17, i64 0}
!17 = !{!"_ZTSN2vl11collections8ListBaseINS_8database8IdObjectImLl1EEES4_EE", !18, i64 0, !10, i64 24, !20, i64 32}
!18 = !{!"_ZTSN2vl11collections9ArrayBaseINS_8database8IdObjectImLl1EEEEE", !19, i64 0, !6, i64 8, !10, i64 16}
!19 = !{!"_ZTSN2vl11collections9ListStoreINS_8database8IdObjectImLl1EEELb1EEE", !13, i64 0}
!20 = !{!"bool", !7, i64 0}
!21 = !{i64 0, i64 4, !22}
!22 = !{!15, !15, i64 0}
!23 = !{i64 0, i64 8, !9}
!24 = !{!25, !10, i64 0}
!25 = !{!"_ZTSN2vl8database8IdObjectImLl1EEE", !10, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"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"

%"struct.vl::database::IdObject.15" = type { i64 }

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

declare i64 @_ZN2vl8database13BufferManager12GetIndexPageENS0_8IdObjectIiLl0EEE(ptr noundef nonnull align 8 dereferenceable(168), i32) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN2vl11collections4ListINS_8database8IdObjectImLl1EEES4_E3AddERKS4_(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2 align 2

declare noundef ptr @_ZN2vl8database13BufferManager8LockPageENS0_8IdObjectIiLl0EEENS2_ImLl1EEE(ptr noundef nonnull align 8 dereferenceable(168), i32, i64) local_unnamed_addr #1

declare noundef zeroext i1 @_ZN2vl8database13BufferManager10UnlockPageENS0_8IdObjectIiLl0EEENS2_ImLl1EEEPvNS0_15PersistanceTypeE(ptr noundef nonnull align 8 dereferenceable(168), i32, i64, ptr noundef, i32 noundef) local_unnamed_addr #1

; 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 noundef i64 @_ZN2vl8database12log_internal14LogAddressItem23InitializeExistingItemsEv(ptr noundef nonnull align 8 dereferenceable(88) %0) local_unnamed_addr #2 align 2 {
  %2 = alloca %"struct.vl::database::IdObject.15", align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %.sroa.08.0.copyload = load i32, ptr %5, align 8, !tbaa !19
  %6 = tail call i64 @_ZN2vl8database13BufferManager12GetIndexPageENS0_8IdObjectIiLl0EEE(ptr noundef nonnull align 8 dereferenceable(168) %4, i32 %.sroa.08.0.copyload)
  store i64 %6, ptr %2, align 8
  %7 = tail call i64 @_ZN2vl8database8IdObjectImLl1EE7InvalidEv()
  %8 = call noundef zeroext i1 @_ZNK2vl8database8IdObjectImLl1EE7IsValidEv(ptr noundef nonnull align 8 dereferenceable(8) %2)
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  br label %10

10:                                               ; preds = %.lr.ph, %10
  %.011 = phi i64 [ 0, %.lr.ph ], [ %17, %10 ]
  %.sroa.06.0.copyload = load i64, ptr %2, align 8, !tbaa !20
  %11 = call noundef i64 @_ZN2vl11collections4ListINS_8database8IdObjectImLl1EEES4_E3AddERKS4_(ptr noundef nonnull align 8 dereferenceable(33) %9, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %.sroa.03.0.copyload = load i32, ptr %5, align 8, !tbaa !19
  %13 = call noundef ptr @_ZN2vl8database13BufferManager8LockPageENS0_8IdObjectIiLl0EEENS2_ImLl1EEE(ptr noundef nonnull align 8 dereferenceable(168) %12, i32 %.sroa.03.0.copyload, i64 %.sroa.06.0.copyload)
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  %15 = load i64, ptr %14, align 8, !tbaa !20
  store i64 %15, ptr %2, align 8, !tbaa !21
  %16 = load i64, ptr %13, align 8, !tbaa !20
  %17 = add i64 %16, %.011
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %.sroa.01.0.copyload = load i32, ptr %5, align 8, !tbaa !19
  %19 = call noundef zeroext i1 @_ZN2vl8database13BufferManager10UnlockPageENS0_8IdObjectIiLl0EEENS2_ImLl1EEEPvNS0_15PersistanceTypeE(ptr noundef nonnull align 8 dereferenceable(168) %18, i32 %.sroa.01.0.copyload, i64 %.sroa.06.0.copyload, ptr noundef nonnull %13, i32 noundef 0)
  %20 = call noundef zeroext i1 @_ZNK2vl8database8IdObjectImLl1EE7IsValidEv(ptr noundef nonnull align 8 dereferenceable(8) %2)
  br i1 %20, label %10, label %._crit_edge, !llvm.loop !23

._crit_edge:                                      ; preds = %10, %1
  %.0.lcssa = phi i64 [ 0, %1 ], [ %17, %10 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret i64 %.0.lcssa
}

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZN2vl8database8IdObjectImLl1EE7InvalidEv() local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK2vl8database8IdObjectImLl1EE7IsValidEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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, !8, i64 8}
!6 = !{!"_ZTSN2vl8database12log_internal14LogAddressItemE", !7, i64 0, !8, i64 8, !11, i64 16, !13, i64 24, !13, i64 32, !14, i64 40}
!7 = !{!"_ZTSN2vl6ObjectE"}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSN2vl8database8IdObjectIiLl0EEE", !12, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = !{!"long", !9, i64 0}
!14 = !{!"_ZTSN2vl11collections4ListINS_8database8IdObjectImLl1EEES4_EE", !15, i64 0}
!15 = !{!"_ZTSN2vl11collections8ListBaseINS_8database8IdObjectImLl1EEES4_EE", !16, i64 0, !13, i64 24, !18, i64 32}
!16 = !{!"_ZTSN2vl11collections9ArrayBaseINS_8database8IdObjectImLl1EEEEE", !17, i64 0, !8, i64 8, !13, i64 16}
!17 = !{!"_ZTSN2vl11collections9ListStoreINS_8database8IdObjectImLl1EEELb1EEE", !7, i64 0}
!18 = !{!"bool", !9, i64 0}
!19 = !{!12, !12, i64 0}
!20 = !{!13, !13, i64 0}
!21 = !{!22, !13, i64 0}
!22 = !{!"_ZTSN2vl8database8IdObjectImLl1EEE", !13, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


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