; LLVM IR from cruppstahl/upscaledb :: src/4txn/txn_cursor.ll (ZN9upscaledb9TxnCursor4findEP9ups_key_tj)

; 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.upscaledb::TxnCursor" = type { %"struct.upscaledb::TxnCursorState" }
%"struct.upscaledb::TxnCursorState" = type { ptr, ptr, ptr, ptr }
%"struct.upscaledb::LocalDb" = type { %"struct.upscaledb::Db", %"struct.upscaledb::ScopedPtr", %"struct.upscaledb::ScopedPtr.1", ptr, %"struct.upscaledb::ScopedPtr.3", i64, %"struct.upscaledb::Histogram" }
%"struct.upscaledb::Db" = type { ptr, ptr, ptr, ptr, %"struct.upscaledb::DbConfig", %"struct.upscaledb::DynamicArray", %"struct.upscaledb::DynamicArray" }
%"struct.upscaledb::DbConfig" = type { i16, i32, i32, i64, i32, i64, i32, i32, %"class.std::__cxx11::basic_string" }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"struct.upscaledb::DynamicArray" = type <{ ptr, i64, i8, [7 x i8] }>
%"struct.upscaledb::ScopedPtr" = type { %"class.boost::scoped_ptr" }
%"class.boost::scoped_ptr" = type { ptr }
%"struct.upscaledb::ScopedPtr.1" = type { %"class.boost::scoped_ptr.2" }
%"class.boost::scoped_ptr.2" = type { ptr }
%"struct.upscaledb::ScopedPtr.3" = type { %"class.boost::scoped_ptr.4" }
%"class.boost::scoped_ptr.4" = type { ptr }
%"struct.upscaledb::Histogram" = type { ptr, %"struct.upscaledb::DynamicArray", %"struct.upscaledb::DynamicArray", %struct.ups_key_t, %struct.ups_key_t }
%struct.ups_key_t = type { i16, ptr, i32, i32 }

; 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: mustprogress uwtable
declare dso_local void @_ZN9upscaledb9TxnCursor10set_to_nilEv(ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef ptr @_ZN9upscaledbL2dbERNS_14TxnCursorStateE(ptr noundef nonnull align 8 dereferenceable(32)) #3

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef i32 @_ZN9upscaledbL16move_top_in_nodeEPNS_9TxnCursorEPNS_7TxnNodeEbj(ptr noundef, ptr noundef, i1 noundef zeroext, i32 noundef) #5

declare noundef ptr @_ZN9upscaledb7TxnNode12next_siblingEv(ptr noundef nonnull align 8 dereferenceable(56)) #6

declare noundef ptr @_ZN9upscaledb7TxnNode16previous_siblingEv(ptr noundef nonnull align 8 dereferenceable(56)) #6

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9upscaledb9TxnCursor4findEP9ups_key_tj(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8
  call void @_ZN9upscaledb9TxnCursor10set_to_nilEv(ptr noundef nonnull align 8 dereferenceable(32) %11)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %12 = getelementptr inbounds %"struct.upscaledb::TxnCursor", ptr %11, i32 0, i32 0
  %13 = call noundef ptr @_ZN9upscaledbL2dbERNS_14TxnCursorStateE(ptr noundef nonnull align 8 dereferenceable(32) %12)
  %14 = getelementptr inbounds %"struct.upscaledb::LocalDb", ptr %13, i32 0, i32 2
  %15 = call noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb8TxnIndexEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %14) #7
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = call noundef ptr @_ZN9upscaledb8TxnIndex3getEP9ups_key_tj(ptr noundef nonnull align 8 dereferenceable(72) %15, ptr noundef %16, i32 noundef %17)
  store ptr %18, ptr %8, align 8, !tbaa !5
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %22, label %21

21:                                               ; preds = %3
  store i32 -11, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %59

22:                                               ; preds = %3
  br label %23

23:                                               ; preds = %58, %22
  br label %24

24:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = call noundef i32 @_ZN9upscaledbL16move_top_in_nodeEPNS_9TxnCursorEPNS_7TxnNodeEbj(ptr noundef %11, ptr noundef %25, i1 noundef zeroext false, i32 noundef 0)
  store i32 %26, ptr %10, align 4, !tbaa !9
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = icmp ne i32 %27, -32
  %29 = zext i1 %28 to i64
  %30 = call i64 @llvm.expect.i64(i64 %29, i64 0)
  %31 = icmp ne i64 %30, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %24
  %33 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %33, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %56

34:                                               ; preds = %24
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = and i32 %35, 8192
  %37 = icmp eq i32 %36, 8192
  br i1 %37, label %38, label %41

38:                                               ; preds = %34
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = call noundef ptr @_ZN9upscaledb7TxnNode12next_siblingEv(ptr noundef nonnull align 8 dereferenceable(56) %39)
  store ptr %40, ptr %8, align 8, !tbaa !5
  br label %51

41:                                               ; preds = %34
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = and i32 %42, 4096
  %44 = icmp eq i32 %43, 4096
  br i1 %44, label %45, label %48

45:                                               ; preds = %41
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = call noundef ptr @_ZN9upscaledb7TxnNode16previous_siblingEv(ptr noundef nonnull align 8 dereferenceable(56) %46)
  store ptr %47, ptr %8, align 8, !tbaa !5
  br label %50

48:                                               ; preds = %41
  %49 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %49, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %56

50:                                               ; preds = %45
  br label %51

51:                                               ; preds = %50, %38
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %55, label %54

54:                                               ; preds = %51
  store i32 -11, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %56

55:                                               ; preds = %51
  store i32 0, ptr %9, align 4
  br label %56

56:                                               ; preds = %55, %54, %48, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  %57 = load i32, ptr %9, align 4
  switch i32 %57, label %59 [
    i32 0, label %58
  ]

58:                                               ; preds = %56
  br label %23, !llvm.loop !11

59:                                               ; preds = %56, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  %60 = load i32, ptr %4, align 4
  ret i32 %60
}

declare noundef ptr @_ZN9upscaledb8TxnIndex3getEP9ups_key_tj(ptr noundef nonnull align 8 dereferenceable(72), ptr noundef, i32 noundef) #6

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #3 = { 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 #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 = { inlinehint 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 #6 = { "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 #7 = { 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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN9upscaledb9TxnCursor10set_to_nilEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef ptr @_ZN9upscaledbL2dbERNS_14TxnCursorStateE(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef i32 @_ZN9upscaledbL16move_top_in_nodeEPNS_9TxnCursorEPNS_7TxnNodeEbj(ptr noundef, ptr noundef, i1 noundef zeroext, i32 noundef) local_unnamed_addr #3

declare noundef ptr @_ZN9upscaledb7TxnNode12next_siblingEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #4

declare noundef ptr @_ZN9upscaledb7TxnNode16previous_siblingEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9upscaledb9TxnCursor4findEP9ups_key_tj(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  tail call void @_ZN9upscaledb9TxnCursor10set_to_nilEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %4 = tail call noundef ptr @_ZN9upscaledbL2dbERNS_14TxnCursorStateE(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %5 = getelementptr inbounds i8, ptr %4, i64 168
  %6 = tail call noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb8TxnIndexEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %5) #5
  %7 = tail call noundef ptr @_ZN9upscaledb8TxnIndex3getEP9ups_key_tj(ptr noundef nonnull align 8 dereferenceable(72) %6, ptr noundef %1, i32 noundef %2)
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %.thread, label %.preheader

.preheader:                                       ; preds = %3
  %8 = and i32 %2, 8192
  %.not22 = icmp eq i32 %8, 0
  br i1 %.not22, label %.preheader.split.us, label %.preheader.split

.preheader.split.us:                              ; preds = %.preheader
  %9 = and i32 %2, 4096
  %.not23 = icmp eq i32 %9, 0
  br i1 %.not23, label %.preheader.split.us.split.us, label %.preheader.split.us.split

.preheader.split.us.split.us:                     ; preds = %.preheader.split.us
  %10 = tail call noundef i32 @_ZN9upscaledbL16move_top_in_nodeEPNS_9TxnCursorEPNS_7TxnNodeEbj(ptr noundef nonnull %0, ptr noundef nonnull %7, i1 noundef zeroext false, i32 noundef 0)
  br label %.thread

.preheader.split.us.split:                        ; preds = %.preheader.split.us, %12
  %.015.us = phi ptr [ %13, %12 ], [ %7, %.preheader.split.us ]
  %11 = tail call noundef i32 @_ZN9upscaledbL16move_top_in_nodeEPNS_9TxnCursorEPNS_7TxnNodeEbj(ptr noundef nonnull %0, ptr noundef nonnull %.015.us, i1 noundef zeroext false, i32 noundef 0)
  %.not21.us = icmp eq i32 %11, -32
  br i1 %.not21.us, label %12, label %.thread, !prof !5

12:                                               ; preds = %.preheader.split.us.split
  %13 = tail call noundef ptr @_ZN9upscaledb7TxnNode16previous_siblingEv(ptr noundef nonnull align 8 dereferenceable(56) %.015.us)
  %.not24.not.us = icmp eq ptr %13, null
  br i1 %.not24.not.us, label %.thread, label %.preheader.split.us.split, !llvm.loop !6

.preheader.split:                                 ; preds = %.preheader, %15
  %.015 = phi ptr [ %16, %15 ], [ %7, %.preheader ]
  %14 = tail call noundef i32 @_ZN9upscaledbL16move_top_in_nodeEPNS_9TxnCursorEPNS_7TxnNodeEbj(ptr noundef nonnull %0, ptr noundef nonnull %.015, i1 noundef zeroext false, i32 noundef 0)
  %.not21 = icmp eq i32 %14, -32
  br i1 %.not21, label %15, label %.thread, !prof !5

15:                                               ; preds = %.preheader.split
  %16 = tail call noundef ptr @_ZN9upscaledb7TxnNode12next_siblingEv(ptr noundef nonnull align 8 dereferenceable(56) %.015)
  %.not24.not = icmp eq ptr %16, null
  br i1 %.not24.not, label %.thread, label %.preheader.split, !llvm.loop !6

.thread:                                          ; preds = %15, %.preheader.split, %.preheader.split.us.split, %12, %.preheader.split.us.split.us, %3
  %.2 = phi i32 [ -11, %3 ], [ %10, %.preheader.split.us.split.us ], [ %11, %.preheader.split.us.split ], [ -11, %12 ], [ %14, %.preheader.split ], [ -11, %15 ]
  ret i32 %.2
}

declare noundef ptr @_ZN9upscaledb8TxnIndex3getEP9ups_key_tj(ptr noundef nonnull align 8 dereferenceable(72), ptr noundef, i32 noundef) local_unnamed_addr #4

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 = { 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 #2 = { 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 = { inlinehint 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 = { "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 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!6 = distinct !{!6, !7}
!7 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LowerExpectIntrinsicPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass