; LLVM IR from KoishiDB/Koishi-DB :: src/disk/block_iterator.ll (ZN8koishidb13BlockIterator4SeekERKNS_5SliceE)

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

%"class.koishidb::Slice" = type { ptr, i64 }
%"class.koishidb::BlockIterator" = type { %"class.koishidb::Iterator", %"class.std::__cxx11::basic_string", ptr, i64, ptr, i32, %"class.koishidb::Slice" }
%"class.koishidb::Iterator" = type { ptr }
%"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] }

; 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
define dso_local noundef zeroext i1 @_ZN8koishidb13BlockIterator4SeekERKNS_5SliceE(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) unnamed_addr #1 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %"class.koishidb::Slice", align 8
  %7 = alloca %"class.koishidb::Slice", align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds ptr, ptr %9, i64 5
  %11 = load ptr, ptr %10, align 8
  call void %11(ptr noundef nonnull align 8 dereferenceable(88) %8)
  %12 = load ptr, ptr %8, align 8, !tbaa !9
  %13 = getelementptr inbounds ptr, ptr %12, i64 4
  %14 = load ptr, ptr %13, align 8
  call void %14(ptr noundef nonnull align 8 dereferenceable(88) %8)
  br label %15

15:                                               ; preds = %39, %2
  %16 = load ptr, ptr %8, align 8, !tbaa !9
  %17 = getelementptr inbounds ptr, ptr %16, i64 2
  %18 = load ptr, ptr %17, align 8
  %19 = call noundef zeroext i1 %18(ptr noundef nonnull align 8 dereferenceable(88) %8)
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #2
  br i1 %19, label %20, label %37

20:                                               ; preds = %15
  %21 = getelementptr inbounds %"class.koishidb::BlockIterator", ptr %8, i32 0, i32 4
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = load ptr, ptr %8, align 8, !tbaa !9
  %24 = getelementptr inbounds ptr, ptr %23, i64 7
  %25 = load ptr, ptr %24, align 8
  %26 = call { ptr, i64 } %25(ptr noundef nonnull align 8 dereferenceable(88) %8)
  %27 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 0
  %28 = extractvalue { ptr, i64 } %26, 0
  store ptr %28, ptr %27, align 8
  %29 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 1
  %30 = extractvalue { ptr, i64 } %26, 1
  store i64 %30, ptr %29, align 8
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load ptr, ptr %22, align 8, !tbaa !9
  %33 = getelementptr inbounds ptr, ptr %32, i64 2
  %34 = load ptr, ptr %33, align 8
  %35 = call noundef i32 %34(ptr noundef nonnull align 8 dereferenceable(8) %22, ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 8 dereferenceable(16) %31)
  %36 = icmp eq i32 %35, -1
  br label %37

37:                                               ; preds = %20, %15
  %38 = phi i1 [ false, %15 ], [ %36, %20 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #2
  br i1 %38, label %39, label %43

39:                                               ; preds = %37
  %40 = load ptr, ptr %8, align 8, !tbaa !9
  %41 = getelementptr inbounds ptr, ptr %40, i64 4
  %42 = load ptr, ptr %41, align 8
  call void %42(ptr noundef nonnull align 8 dereferenceable(88) %8)
  br label %15, !llvm.loop !19

43:                                               ; preds = %37
  %44 = load ptr, ptr %8, align 8, !tbaa !9
  %45 = getelementptr inbounds ptr, ptr %44, i64 2
  %46 = load ptr, ptr %45, align 8
  %47 = call noundef zeroext i1 %46(ptr noundef nonnull align 8 dereferenceable(88) %8)
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #2
  br i1 %47, label %48, label %65

48:                                               ; preds = %43
  %49 = getelementptr inbounds %"class.koishidb::BlockIterator", ptr %8, i32 0, i32 4
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = load ptr, ptr %8, align 8, !tbaa !9
  %52 = getelementptr inbounds ptr, ptr %51, i64 7
  %53 = load ptr, ptr %52, align 8
  %54 = call { ptr, i64 } %53(ptr noundef nonnull align 8 dereferenceable(88) %8)
  %55 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 0
  %56 = extractvalue { ptr, i64 } %54, 0
  store ptr %56, ptr %55, align 8
  %57 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 1
  %58 = extractvalue { ptr, i64 } %54, 1
  store i64 %58, ptr %57, align 8
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load ptr, ptr %50, align 8, !tbaa !9
  %61 = getelementptr inbounds ptr, ptr %60, i64 2
  %62 = load ptr, ptr %61, align 8
  %63 = call noundef i32 %62(ptr noundef nonnull align 8 dereferenceable(8) %50, ptr noundef nonnull align 8 dereferenceable(16) %7, ptr noundef nonnull align 8 dereferenceable(16) %59)
  %64 = icmp eq i32 %63, 0
  br label %65

65:                                               ; preds = %48, %43
  %66 = phi i1 [ false, %43 ], [ %64, %48 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #2
  br i1 %66, label %67, label %68

67:                                               ; preds = %65
  store i1 true, ptr %3, align 1
  br label %69

68:                                               ; preds = %65
  store i1 false, ptr %3, align 1
  br label %69

69:                                               ; preds = %68, %67
  %70 = load i1, ptr %3, align 1
  ret i1 %70
}

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 = { 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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !6, i64 56}
!12 = !{!"_ZTSN8koishidb13BlockIteratorE", !13, i64 0, !14, i64 8, !6, i64 40, !16, i64 48, !6, i64 56, !17, i64 64, !18, i64 72}
!13 = !{!"_ZTSN8koishidb8IteratorE"}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !15, i64 0, !16, i64 8, !7, i64 16}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!"_ZTSN8koishidb5SliceE", !6, i64 0, !16, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"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"

%"class.koishidb::Slice" = type { ptr, i64 }

; 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN8koishidb13BlockIterator4SeekERKNS_5SliceE(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) unnamed_addr #1 align 2 {
  %3 = alloca %"class.koishidb::Slice", align 8
  %4 = alloca %"class.koishidb::Slice", align 8
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 40
  %7 = load ptr, ptr %6, align 8
  tail call void %7(ptr noundef nonnull align 8 dereferenceable(88) %0)
  %8 = load ptr, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 32
  %10 = load ptr, ptr %9, align 8
  tail call void %10(ptr noundef nonnull align 8 dereferenceable(88) %0)
  %11 = load ptr, ptr %0, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %13 = load ptr, ptr %12, align 8
  %14 = tail call noundef zeroext i1 %13(ptr noundef nonnull align 8 dereferenceable(88) %0)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #2
  br i1 %14, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %2
  %15 = getelementptr inbounds i8, ptr %0, i64 56
  %16 = getelementptr inbounds i8, ptr %3, i64 8
  br label %17

17:                                               ; preds = %.lr.ph, %30
  %18 = load ptr, ptr %15, align 8, !tbaa !8
  %19 = load ptr, ptr %0, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 56
  %21 = load ptr, ptr %20, align 8
  %22 = call { ptr, i64 } %21(ptr noundef nonnull align 8 dereferenceable(88) %0)
  %23 = extractvalue { ptr, i64 } %22, 0
  store ptr %23, ptr %3, align 8
  %24 = extractvalue { ptr, i64 } %22, 1
  store i64 %24, ptr %16, align 8
  %25 = load ptr, ptr %18, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  %27 = load ptr, ptr %26, align 8
  %28 = call noundef i32 %27(ptr noundef nonnull align 8 dereferenceable(8) %18, ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull align 8 dereferenceable(16) %1)
  %29 = icmp eq i32 %28, -1
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #2
  br i1 %29, label %30, label %.loopexit

30:                                               ; preds = %17
  %31 = load ptr, ptr %0, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i64 32
  %33 = load ptr, ptr %32, align 8
  call void %33(ptr noundef nonnull align 8 dereferenceable(88) %0)
  %34 = load ptr, ptr %0, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 16
  %36 = load ptr, ptr %35, align 8
  %37 = call noundef zeroext i1 %36(ptr noundef nonnull align 8 dereferenceable(88) %0)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #2
  br i1 %37, label %17, label %.critedge, !llvm.loop !18

.critedge:                                        ; preds = %30, %2
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #2
  br label %.loopexit

.loopexit:                                        ; preds = %17, %.critedge
  %38 = load ptr, ptr %0, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i64 16
  %40 = load ptr, ptr %39, align 8
  %41 = call noundef zeroext i1 %40(ptr noundef nonnull align 8 dereferenceable(88) %0)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #2
  br i1 %41, label %42, label %.critedge2

42:                                               ; preds = %.loopexit
  %43 = getelementptr inbounds i8, ptr %0, i64 56
  %44 = load ptr, ptr %43, align 8, !tbaa !8
  %45 = load ptr, ptr %0, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 56
  %47 = load ptr, ptr %46, align 8
  %48 = call { ptr, i64 } %47(ptr noundef nonnull align 8 dereferenceable(88) %0)
  %49 = extractvalue { ptr, i64 } %48, 0
  store ptr %49, ptr %4, align 8
  %50 = getelementptr inbounds i8, ptr %4, i64 8
  %51 = extractvalue { ptr, i64 } %48, 1
  store i64 %51, ptr %50, align 8
  %52 = load ptr, ptr %44, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 16
  %54 = load ptr, ptr %53, align 8
  %55 = call noundef i32 %54(ptr noundef nonnull align 8 dereferenceable(8) %44, ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 8 dereferenceable(16) %1)
  %56 = icmp eq i32 %55, 0
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #2
  br i1 %56, label %58, label %57

.critedge2:                                       ; preds = %.loopexit
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #2
  br label %57

57:                                               ; preds = %.critedge2, %42
  br label %58

58:                                               ; preds = %42, %57
  %.0 = phi i1 [ false, %57 ], [ true, %42 ]
  ret i1 %.0
}

attributes #0 = { mustprogress 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 = { 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !13, i64 56}
!9 = !{!"_ZTSN8koishidb13BlockIteratorE", !10, i64 0, !11, i64 8, !13, i64 40, !15, i64 48, !13, i64 56, !16, i64 64, !17, i64 72}
!10 = !{!"_ZTSN8koishidb8IteratorE"}
!11 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !12, i64 0, !15, i64 8, !14, i64 16}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !13, i64 0}
!13 = !{!"any pointer", !14, i64 0}
!14 = !{!"omnipotent char", !7, i64 0}
!15 = !{!"long", !14, i64 0}
!16 = !{!"int", !14, i64 0}
!17 = !{!"_ZTSN8koishidb5SliceE", !13, i64 0, !15, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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