; LLVM IR from adventure-db/adventure :: src/db/store (btree)

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

; 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: nounwind uwtable
define dso_local void @btree_destroy(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i16, align 2
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = load i64, ptr %4, align 8, !tbaa !9
  %10 = call i64 @read_ui64(ptr noundef %8, i64 noundef %9, i16 noundef zeroext 0)
  store i64 %10, ptr %5, align 8, !tbaa !9
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = lshr i64 %11, 56
  %13 = and i64 %12, 65535
  %14 = and i64 %13, 2
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %16, label %19

16:                                               ; preds = %2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load i64, ptr %4, align 8, !tbaa !9
  call void @store_free(ptr noundef %17, i64 noundef %18)
  br label %54

19:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #4
  store i16 8, ptr %6, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load i64, ptr %4, align 8, !tbaa !9
  %22 = load i16, ptr %6, align 2, !tbaa !11
  %23 = call i64 @read_ui64(ptr noundef %20, i64 noundef %21, i16 noundef zeroext %22)
  store i64 %23, ptr %7, align 8, !tbaa !9
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load i64, ptr %7, align 8, !tbaa !9
  call void @btree_destroy(ptr noundef %24, i64 noundef %25)
  %26 = load i16, ptr %6, align 2, !tbaa !11
  %27 = zext i16 %26 to i64
  %28 = add i64 %27, 8
  %29 = trunc i64 %28 to i16
  store i16 %29, ptr %6, align 2, !tbaa !11
  br label %30

30:                                               ; preds = %37, %19
  %31 = load i16, ptr %6, align 2, !tbaa !11
  %32 = zext i16 %31 to i64
  %33 = load i64, ptr %5, align 8, !tbaa !9
  %34 = lshr i64 %33, 0
  %35 = and i64 %34, 65535
  %36 = icmp ult i64 %32, %35
  br i1 %36, label %37, label %51

37:                                               ; preds = %30
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = load i64, ptr %4, align 8, !tbaa !9
  %40 = load i16, ptr %6, align 2, !tbaa !11
  %41 = zext i16 %40 to i32
  %42 = add nsw i32 %41, 8
  %43 = trunc i32 %42 to i16
  %44 = call i64 @read_ui64(ptr noundef %38, i64 noundef %39, i16 noundef zeroext %43)
  store i64 %44, ptr %7, align 8, !tbaa !9
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = load i64, ptr %7, align 8, !tbaa !9
  call void @btree_destroy(ptr noundef %45, i64 noundef %46)
  %47 = load i16, ptr %6, align 2, !tbaa !11
  %48 = zext i16 %47 to i64
  %49 = add i64 %48, 16
  %50 = trunc i64 %49 to i16
  store i16 %50, ptr %6, align 2, !tbaa !11
  br label %30, !llvm.loop !13

51:                                               ; preds = %30
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = load i64, ptr %4, align 8, !tbaa !9
  call void @store_free(ptr noundef %52, i64 noundef %53)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #4
  br label %54

54:                                               ; preds = %51, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @read_ui64(ptr noundef, i64 noundef, i16 noundef zeroext) #2

declare void @store_free(ptr noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { inlinehint 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 = { "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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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: nounwind uwtable
define dso_local void @btree_destroy(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i64 @read_ui64(ptr noundef %0, i64 noundef %1, i16 noundef zeroext 0)
  %4 = and i64 %3, 144115188075855872
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %5, label %._crit_edge

5:                                                ; preds = %2
  %6 = tail call i64 @read_ui64(ptr noundef %0, i64 noundef %1, i16 noundef zeroext 8)
  tail call void @btree_destroy(ptr noundef %0, i64 noundef %6)
  %7 = and i64 %3, 65535
  %8 = icmp ugt i64 %7, 16
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %5
  %9 = trunc i64 %3 to i16
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.021 = phi i16 [ %12, %.lr.ph ], [ 16, %.lr.ph.preheader ]
  %10 = or disjoint i16 %.021, 8
  %11 = tail call i64 @read_ui64(ptr noundef %0, i64 noundef %1, i16 noundef zeroext %10)
  tail call void @btree_destroy(ptr noundef %0, i64 noundef %11)
  %12 = add i16 %.021, 16
  %13 = icmp ult i16 %12, %9
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %5, %2
  tail call void @store_free(ptr noundef %0, i64 noundef %1) #3
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @read_ui64(ptr noundef, i64 noundef, i16 noundef zeroext) local_unnamed_addr #1

declare void @store_free(ptr noundef, i64 noundef) local_unnamed_addr #2

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass