; LLVM IR from cruppstahl/upscaledb :: src/4db/histogram.ll (ZN9upscaledb9Histogram13test_if_lowerEPNS_3TxnEP9ups_key_t)

; 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::Histogram" = type { ptr, %"struct.upscaledb::DynamicArray", %"struct.upscaledb::DynamicArray", %struct.ups_key_t, %struct.ups_key_t }
%"struct.upscaledb::DynamicArray" = type <{ ptr, i64, i8, [7 x i8] }>
%struct.ups_key_t = type { i16, ptr, i32, i32 }
%"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::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 }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN9upscaledb9Histogram13test_if_lowerEPNS_3TxnEP9ups_key_t(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1, ptr noundef %2) #0 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %8 = load ptr, ptr %5, align 8
  %9 = getelementptr inbounds %"struct.upscaledb::Histogram", ptr %8, i32 0, i32 3
  %10 = getelementptr inbounds %struct.ups_key_t, ptr %9, i32 0, i32 0
  %11 = load i16, ptr %10, align 8, !tbaa !9
  %12 = zext i16 %11 to i32
  %13 = icmp eq i32 %12, 0
  %14 = zext i1 %13 to i64
  %15 = call i64 @llvm.expect.i64(i64 %14, i64 0)
  %16 = icmp ne i64 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %3
  store i1 false, ptr %4, align 1
  br label %27

18:                                               ; preds = %3
  %19 = getelementptr inbounds %"struct.upscaledb::Histogram", ptr %8, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !17
  %21 = getelementptr inbounds %"struct.upscaledb::LocalDb", ptr %20, i32 0, i32 1
  %22 = call noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10BtreeIndexEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %21) #3
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %"struct.upscaledb::Histogram", ptr %8, i32 0, i32 3
  %25 = call noundef i32 @_ZNK9upscaledb10BtreeIndex12compare_keysEP9ups_key_tS2_(ptr noundef nonnull align 8 dereferenceable(144) %22, ptr noundef %23, ptr noundef %24)
  %26 = icmp slt i32 %25, 0
  store i1 %26, ptr %4, align 1
  br label %27

27:                                               ; preds = %18, %17
  %28 = load i1, ptr %4, align 1
  ret i1 %28
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK9upscaledb10BtreeIndex12compare_keysEP9ups_key_tS2_(ptr noundef nonnull align 8 dereferenceable(144), ptr noundef, ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 = { 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, !15, i64 56}
!10 = !{!"_ZTSN9upscaledb9HistogramE", !6, i64 0, !11, i64 8, !11, i64 32, !14, i64 56, !14, i64 80}
!11 = !{!"_ZTSN9upscaledb12DynamicArrayIhEE", !6, i64 0, !12, i64 8, !13, i64 16}
!12 = !{!"long", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTS9ups_key_t", !15, i64 0, !6, i64 8, !16, i64 16, !16, i64 20}
!15 = !{!"short", !7, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!10, !6, i64 0}


; 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 @_ZN9upscaledb9Histogram13test_if_lowerEPNS_3TxnEP9ups_key_t(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr nocapture noundef readnone %1, ptr noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 56
  %5 = load i16, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i16 %5, 0
  br i1 %6, label %13, label %7, !prof !16

7:                                                ; preds = %3
  %8 = load ptr, ptr %0, align 8, !tbaa !17
  %9 = getelementptr inbounds i8, ptr %8, i64 160
  %10 = tail call noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10BtreeIndexEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %9) #2
  %11 = tail call noundef i32 @_ZNK9upscaledb10BtreeIndex12compare_keysEP9ups_key_tS2_(ptr noundef nonnull align 8 dereferenceable(144) %10, ptr noundef %2, ptr noundef nonnull %4)
  %12 = icmp slt i32 %11, 0
  br label %13

13:                                               ; preds = %3, %7
  %.0 = phi i1 [ %12, %7 ], [ false, %3 ]
  ret i1 %.0
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK9upscaledb10BtreeIndex12compare_keysEP9ups_key_tS2_(ptr noundef nonnull align 8 dereferenceable(144), ptr noundef, ptr noundef) 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" }
attributes #2 = { 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, !14, i64 56}
!6 = !{!"_ZTSN9upscaledb9HistogramE", !7, i64 0, !10, i64 8, !10, i64 32, !13, i64 56, !13, i64 80}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN9upscaledb12DynamicArrayIhEE", !7, i64 0, !11, i64 8, !12, i64 16}
!11 = !{!"long", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{!"_ZTS9ups_key_t", !14, i64 0, !7, i64 8, !15, i64 16, !15, i64 20}
!14 = !{!"short", !8, i64 0}
!15 = !{!"int", !8, i64 0}
!16 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!17 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass