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

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

; 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 noundef zeroext i1 @_ZN9upscaledb9Histogram13test_if_lowerEPNS_3TxnEP9ups_key_t(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef, ptr noundef) #1 align 2

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

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

20:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %21 = getelementptr inbounds %"struct.upscaledb::Histogram", ptr %11, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr %22, align 8, !tbaa !18
  %25 = getelementptr inbounds ptr, ptr %24, i64 9
  %26 = load ptr, ptr %25, align 8
  %27 = call noundef ptr %26(ptr noundef nonnull align 8 dereferenceable(304) %22, ptr noundef %23, i32 noundef 0)
  store ptr %27, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %28 = getelementptr inbounds %"struct.upscaledb::Histogram", ptr %11, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !17
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.upscaledb::Histogram", ptr %11, i32 0, i32 3
  %32 = load ptr, ptr %29, align 8, !tbaa !18
  %33 = getelementptr inbounds ptr, ptr %32, i64 11
  %34 = load ptr, ptr %33, align 8
  %35 = call noundef i32 %34(ptr noundef nonnull align 8 dereferenceable(304) %29, ptr noundef %30, ptr noundef %31, ptr noundef null, i32 noundef 1)
  store i32 %35, ptr %9, align 4, !tbaa !20
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = icmp eq ptr %36, null
  br i1 %37, label %42, label %38

38:                                               ; preds = %20
  %39 = load ptr, ptr %36, align 8, !tbaa !18
  %40 = getelementptr inbounds ptr, ptr %39, i64 1
  %41 = load ptr, ptr %40, align 8
  call void %41(ptr noundef nonnull align 8 dereferenceable(40) %36) #4
  br label %42

42:                                               ; preds = %38, %20
  %43 = load i32, ptr %9, align 4, !tbaa !20
  %44 = icmp ne i32 %43, 0
  %45 = zext i1 %44 to i64
  %46 = call i64 @llvm.expect.i64(i64 %45, i64 0)
  %47 = icmp ne i64 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %42
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %62

49:                                               ; preds = %42
  %50 = getelementptr inbounds %"struct.upscaledb::Histogram", ptr %11, i32 0, i32 1
  %51 = getelementptr inbounds %"struct.upscaledb::Histogram", ptr %11, i32 0, i32 3
  %52 = getelementptr inbounds %struct.ups_key_t, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !21
  %54 = getelementptr inbounds %"struct.upscaledb::Histogram", ptr %11, i32 0, i32 3
  %55 = getelementptr inbounds %struct.ups_key_t, ptr %54, i32 0, i32 0
  %56 = load i16, ptr %55, align 8, !tbaa !9
  %57 = zext i16 %56 to i64
  call void @_ZN9upscaledb12DynamicArrayIhE4copyEPKhm(ptr noundef nonnull align 8 dereferenceable(17) %50, ptr noundef %53, i64 noundef %57)
  %58 = getelementptr inbounds %"struct.upscaledb::Histogram", ptr %11, i32 0, i32 1
  %59 = call noundef ptr @_ZN9upscaledb12DynamicArrayIhE4dataEv(ptr noundef nonnull align 8 dereferenceable(17) %58)
  %60 = getelementptr inbounds %"struct.upscaledb::Histogram", ptr %11, i32 0, i32 3
  %61 = getelementptr inbounds %struct.ups_key_t, ptr %60, i32 0, i32 1
  store ptr %59, ptr %61, align 8, !tbaa !21
  store i32 0, ptr %10, align 4
  br label %62

62:                                               ; preds = %49, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %63 = load i32, ptr %10, align 4
  switch i32 %63, label %90 [
    i32 0, label %64
    i32 1, label %88
  ]

64:                                               ; preds = %62
  br label %65

65:                                               ; preds = %64, %3
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = call noundef zeroext i1 @_ZN9upscaledb9Histogram13test_if_lowerEPNS_3TxnEP9ups_key_t(ptr noundef nonnull align 8 dereferenceable(104) %11, ptr noundef %66, ptr noundef %67)
  br i1 %68, label %69, label %87

69:                                               ; preds = %65
  %70 = getelementptr inbounds %"struct.upscaledb::Histogram", ptr %11, i32 0, i32 1
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.ups_key_t, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !22
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.ups_key_t, ptr %74, i32 0, i32 0
  %76 = load i16, ptr %75, align 8, !tbaa !23
  %77 = zext i16 %76 to i64
  call void @_ZN9upscaledb12DynamicArrayIhE4copyEPKhm(ptr noundef nonnull align 8 dereferenceable(17) %70, ptr noundef %73, i64 noundef %77)
  %78 = getelementptr inbounds %"struct.upscaledb::Histogram", ptr %11, i32 0, i32 1
  %79 = call noundef ptr @_ZN9upscaledb12DynamicArrayIhE4dataEv(ptr noundef nonnull align 8 dereferenceable(17) %78)
  %80 = getelementptr inbounds %"struct.upscaledb::Histogram", ptr %11, i32 0, i32 3
  %81 = getelementptr inbounds %struct.ups_key_t, ptr %80, i32 0, i32 1
  store ptr %79, ptr %81, align 8, !tbaa !21
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.ups_key_t, ptr %82, i32 0, i32 0
  %84 = load i16, ptr %83, align 8, !tbaa !23
  %85 = getelementptr inbounds %"struct.upscaledb::Histogram", ptr %11, i32 0, i32 3
  %86 = getelementptr inbounds %struct.ups_key_t, ptr %85, i32 0, i32 0
  store i16 %84, ptr %86, align 8, !tbaa !9
  store i1 true, ptr %4, align 1
  br label %88

87:                                               ; preds = %65
  store i1 false, ptr %4, align 1
  br label %88

88:                                               ; preds = %87, %69, %62
  %89 = load i1, ptr %4, align 1
  ret i1 %89

90:                                               ; preds = %62
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN9upscaledb12DynamicArrayIhE4copyEPKhm(ptr noundef nonnull align 8 dereferenceable(17), ptr noundef, i64 noundef) #1 align 2

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

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 = { 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, !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}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !8, i64 0}
!20 = !{!16, !16, i64 0}
!21 = !{!10, !6, i64 64}
!22 = !{!14, !6, i64 8}
!23 = !{!14, !15, 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
declare dso_local noundef zeroext i1 @_ZN9upscaledb9Histogram13test_if_lowerEPNS_3TxnEP9ups_key_t(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef, ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN9upscaledb9Histogram24test_and_update_if_lowerEPNS_3TxnEP9ups_key_t(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %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 %7, label %30, !prof !16

7:                                                ; preds = %3
  %8 = load ptr, ptr %0, align 8, !tbaa !17
  %9 = load ptr, ptr %8, align 8, !tbaa !18
  %10 = getelementptr inbounds i8, ptr %9, i64 72
  %11 = load ptr, ptr %10, align 8
  %12 = tail call noundef ptr %11(ptr noundef nonnull align 8 dereferenceable(304) %8, ptr noundef %1, i32 noundef 0)
  %13 = load ptr, ptr %0, align 8, !tbaa !17
  %14 = load ptr, ptr %13, align 8, !tbaa !18
  %15 = getelementptr inbounds i8, ptr %14, i64 88
  %16 = load ptr, ptr %15, align 8
  %17 = tail call noundef i32 %16(ptr noundef nonnull align 8 dereferenceable(304) %13, ptr noundef %12, ptr noundef nonnull %4, ptr noundef null, i32 noundef 1)
  %18 = icmp eq ptr %12, null
  br i1 %18, label %23, label %19

19:                                               ; preds = %7
  %20 = load ptr, ptr %12, align 8, !tbaa !18
  %21 = getelementptr inbounds i8, ptr %20, i64 8
  %22 = load ptr, ptr %21, align 8
  tail call void %22(ptr noundef nonnull align 8 dereferenceable(40) %12) #2
  br label %23

23:                                               ; preds = %19, %7
  %.not.not = icmp eq i32 %17, 0
  br i1 %.not.not, label %.thread, label %41, !prof !20

.thread:                                          ; preds = %23
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  %25 = getelementptr inbounds i8, ptr %0, i64 64
  %26 = load ptr, ptr %25, align 8, !tbaa !21
  %27 = load i16, ptr %4, align 8, !tbaa !5
  %28 = zext i16 %27 to i64
  tail call void @_ZN9upscaledb12DynamicArrayIhE4copyEPKhm(ptr noundef nonnull align 8 dereferenceable(17) %24, ptr noundef %26, i64 noundef %28)
  %29 = tail call noundef ptr @_ZN9upscaledb12DynamicArrayIhE4dataEv(ptr noundef nonnull align 8 dereferenceable(17) %24)
  store ptr %29, ptr %25, align 8, !tbaa !21
  br label %30

30:                                               ; preds = %.thread, %3
  %31 = tail call noundef zeroext i1 @_ZN9upscaledb9Histogram13test_if_lowerEPNS_3TxnEP9ups_key_t(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1, ptr noundef %2)
  br i1 %31, label %32, label %41

32:                                               ; preds = %30
  %33 = getelementptr inbounds i8, ptr %0, i64 8
  %34 = getelementptr inbounds i8, ptr %2, i64 8
  %35 = load ptr, ptr %34, align 8, !tbaa !22
  %36 = load i16, ptr %2, align 8, !tbaa !23
  %37 = zext i16 %36 to i64
  tail call void @_ZN9upscaledb12DynamicArrayIhE4copyEPKhm(ptr noundef nonnull align 8 dereferenceable(17) %33, ptr noundef %35, i64 noundef %37)
  %38 = tail call noundef ptr @_ZN9upscaledb12DynamicArrayIhE4dataEv(ptr noundef nonnull align 8 dereferenceable(17) %33)
  %39 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr %38, ptr %39, align 8, !tbaa !21
  %40 = load i16, ptr %2, align 8, !tbaa !23
  store i16 %40, ptr %4, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %23, %30, %32
  %.1 = phi i1 [ true, %32 ], [ false, %30 ], [ false, %23 ]
  ret i1 %.1
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN9upscaledb12DynamicArrayIhE4copyEPKhm(ptr noundef nonnull align 8 dereferenceable(17), ptr noundef, i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN9upscaledb12DynamicArrayIhE4dataEv(ptr noundef nonnull align 8 dereferenceable(17)) local_unnamed_addr #1 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}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !9, i64 0}
!20 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!21 = !{!6, !7, i64 64}
!22 = !{!13, !7, i64 8}
!23 = !{!13, !14, i64 0}


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