; LLVM IR from pmwkaa/monotone :: monotone/engine/io (memtable)

; 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.Memtable = type { ptr, %struct.Rbtree, i32, i32, i32, i64, i64, i64, %struct.List, i32, %struct.Heap }
%struct.Rbtree = type { ptr }
%struct.List = type { ptr, ptr }
%struct.Heap = type { ptr, ptr, i32, ptr }

; 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: hot inlinehint nounwind uwtable
declare hidden ptr @memtable_search_page(ptr noundef, ptr noundef) #1

; Function Attrs: hot inlinehint nounwind uwtable
declare hidden i32 @memtable_search(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: hot nounwind uwtable
define dso_local zeroext i1 @memtable_seek(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.Memtable, ptr %12, i32 0, i32 4
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %4
  store i1 false, ptr %5, align 1
  br label %41

17:                                               ; preds = %4
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %28

20:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Memtable, ptr %21, i32 0, i32 1
  %23 = call ptr @rbtree_min(ptr noundef %22)
  store ptr %23, ptr %10, align 8, !tbaa !5
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 0
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %25, ptr %26, align 8, !tbaa !5
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 0, ptr %27, align 4, !tbaa !16
  store i1 false, ptr %5, align 1
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %41

28:                                               ; preds = %17
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = call ptr @memtable_search_page(ptr noundef %29, ptr noundef %30) #5
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %31, ptr %32, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #4
  store i8 0, ptr %11, align 1, !tbaa !17
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = call i32 @memtable_search(ptr noundef %33, ptr noundef %35, ptr noundef %36, ptr noundef %11) #5
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %37, ptr %38, align 4, !tbaa !16
  %39 = load i8, ptr %11, align 1, !tbaa !17, !range !19, !noundef !20
  %40 = trunc i8 %39 to i1
  store i1 %40, ptr %5, align 1
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #4
  br label %41

41:                                               ; preds = %28, %20, %16
  %42 = load i1, ptr %5, align 1
  ret i1 %42
}

declare ptr @rbtree_min(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { hot 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 = { hot 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 }
attributes #5 = { hot }

!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, !12, i64 24}
!10 = !{!"Memtable", !6, i64 0, !11, i64 8, !12, i64 16, !12, i64 20, !12, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !14, i64 56, !12, i64 72, !15, i64 80}
!11 = !{!"Rbtree", !6, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"List", !6, i64 0, !6, i64 8}
!15 = !{!"Heap", !6, i64 0, !6, i64 8, !12, i64 16, !6, i64 24}
!16 = !{!12, !12, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"_Bool", !7, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: hot inlinehint nounwind uwtable
declare hidden ptr @memtable_search_page(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: hot inlinehint nounwind uwtable
declare hidden i32 @memtable_search(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: hot nounwind uwtable
define dso_local zeroext i1 @memtable_seek(ptr noundef %0, ptr noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #2 {
  %5 = alloca i8, align 1
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %19, label %9

9:                                                ; preds = %4
  %10 = icmp eq ptr %1, null
  br i1 %10, label %11, label %14

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = tail call ptr @rbtree_min(ptr noundef nonnull %12) #4
  store ptr %13, ptr %2, align 8, !tbaa !15
  store i32 0, ptr %3, align 4, !tbaa !16
  br label %19

14:                                               ; preds = %9
  %15 = tail call ptr @memtable_search_page(ptr noundef nonnull %0, ptr noundef nonnull %1) #5
  store ptr %15, ptr %2, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %5) #4
  store i8 0, ptr %5, align 1, !tbaa !17
  %16 = call i32 @memtable_search(ptr noundef nonnull %0, ptr noundef %15, ptr noundef nonnull %1, ptr noundef nonnull %5) #5
  store i32 %16, ptr %3, align 4, !tbaa !16
  %17 = load i8, ptr %5, align 1, !tbaa !17, !range !19, !noundef !20
  %18 = trunc nuw i8 %17 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #4
  br label %19

19:                                               ; preds = %4, %14, %11
  %.0 = phi i1 [ false, %11 ], [ %18, %14 ], [ false, %4 ]
  ret i1 %.0
}

declare ptr @rbtree_min(ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { hot 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 = { hot 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 }
attributes #5 = { hot }

!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, !11, i64 24}
!6 = !{!"Memtable", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !13, i64 56, !11, i64 72, !14, i64 80}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"Rbtree", !7, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!"List", !7, i64 0, !7, i64 8}
!14 = !{!"Heap", !7, i64 0, !7, i64 8, !11, i64 16, !7, i64 24}
!15 = !{!7, !7, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"_Bool", !8, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}


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