; LLVM IR from KoishiDB/Koishi-DB :: src/disk/filterblock_reader.ll (ZN8koishidb17FilterBlockReaderC2ERKNS_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::FilterBlockReader" = type { %"class.koishidb::BloomFilter", ptr, ptr, i64, i64 }
%"class.koishidb::BloomFilter" = type { i32, i32 }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8koishidb17FilterBlockReaderC2ERKNS_5SliceE(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) unnamed_addr #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  %9 = getelementptr inbounds %"class.koishidb::FilterBlockReader", ptr %8, i32 0, i32 0
  call void @_ZN8koishidb11BloomFilterC2Ei(ptr noundef nonnull align 4 dereferenceable(8) %9, i32 noundef 10)
  %10 = getelementptr inbounds %"class.koishidb::FilterBlockReader", ptr %8, i32 0, i32 1
  store ptr null, ptr %10, align 8, !tbaa !9
  %11 = getelementptr inbounds %"class.koishidb::FilterBlockReader", ptr %8, i32 0, i32 2
  store ptr null, ptr %11, align 8, !tbaa !14
  %12 = getelementptr inbounds %"class.koishidb::FilterBlockReader", ptr %8, i32 0, i32 3
  store i64 0, ptr %12, align 8, !tbaa !15
  %13 = getelementptr inbounds %"class.koishidb::FilterBlockReader", ptr %8, i32 0, i32 4
  store i64 0, ptr %13, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call noundef i64 @_ZNK8koishidb5Slice4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %14)
  store i64 %15, ptr %5, align 8, !tbaa !17
  %16 = load i64, ptr %5, align 8, !tbaa !17
  %17 = icmp ult i64 %16, 5
  br i1 %17, label %18, label %19

18:                                               ; preds = %2
  store i32 1, ptr %6, align 4
  br label %56

19:                                               ; preds = %2
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i64, ptr %5, align 8, !tbaa !17
  %22 = sub i64 %21, 1
  %23 = call noundef signext i8 @_ZNK8koishidb5SliceixEm(ptr noundef nonnull align 8 dereferenceable(16) %20, i64 noundef %22)
  %24 = sext i8 %23 to i64
  %25 = getelementptr inbounds %"class.koishidb::FilterBlockReader", ptr %8, i32 0, i32 4
  store i64 %24, ptr %25, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = call noundef ptr @_ZNK8koishidb5Slice4dataEv(ptr noundef nonnull align 8 dereferenceable(16) %26)
  %28 = load i64, ptr %5, align 8, !tbaa !17
  %29 = getelementptr inbounds i8, ptr %27, i64 %28
  %30 = getelementptr inbounds i8, ptr %29, i64 -5
  %31 = call noundef i32 @_ZN8koishidb13DecodeFixed32EPKc(ptr noundef %30)
  store i32 %31, ptr %7, align 4, !tbaa !18
  %32 = load i32, ptr %7, align 4, !tbaa !18
  %33 = zext i32 %32 to i64
  %34 = load i64, ptr %5, align 8, !tbaa !17
  %35 = sub i64 %34, 5
  %36 = icmp ugt i64 %33, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %19
  store i32 1, ptr %6, align 4
  br label %55

38:                                               ; preds = %19
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = call noundef ptr @_ZNK8koishidb5Slice4dataEv(ptr noundef nonnull align 8 dereferenceable(16) %39)
  %41 = getelementptr inbounds %"class.koishidb::FilterBlockReader", ptr %8, i32 0, i32 1
  store ptr %40, ptr %41, align 8, !tbaa !9
  %42 = getelementptr inbounds %"class.koishidb::FilterBlockReader", ptr %8, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = load i32, ptr %7, align 4, !tbaa !18
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds i8, ptr %43, i64 %45
  %47 = getelementptr inbounds %"class.koishidb::FilterBlockReader", ptr %8, i32 0, i32 2
  store ptr %46, ptr %47, align 8, !tbaa !14
  %48 = load i64, ptr %5, align 8, !tbaa !17
  %49 = sub i64 %48, 5
  %50 = load i32, ptr %7, align 4, !tbaa !18
  %51 = zext i32 %50 to i64
  %52 = sub i64 %49, %51
  %53 = udiv i64 %52, 4
  %54 = getelementptr inbounds %"class.koishidb::FilterBlockReader", ptr %8, i32 0, i32 3
  store i64 %53, ptr %54, align 8, !tbaa !15
  store i32 0, ptr %6, align 4
  br label %55

55:                                               ; preds = %38, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %56

56:                                               ; preds = %55, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %57 = load i32, ptr %6, align 4
  switch i32 %57, label %59 [
    i32 0, label %58
    i32 1, label %58
  ]

58:                                               ; preds = %56, %56
  ret void

59:                                               ; preds = %56
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN8koishidb11BloomFilterC2Ei(ptr noundef nonnull align 4 dereferenceable(8), i32 noundef) unnamed_addr #1 align 2

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

declare noundef i64 @_ZNK8koishidb5Slice4sizeEv(ptr noundef nonnull align 8 dereferenceable(16)) #3

declare noundef signext i8 @_ZNK8koishidb5SliceixEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) #3

declare noundef i32 @_ZN8koishidb13DecodeFixed32EPKc(ptr noundef) #3

declare noundef ptr @_ZNK8koishidb5Slice4dataEv(ptr noundef nonnull align 8 dereferenceable(16)) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTSN8koishidb17FilterBlockReaderE", !11, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !13, i64 32}
!11 = !{!"_ZTSN8koishidb11BloomFilterE", !12, i64 0, !12, i64 4}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !6, i64 16}
!15 = !{!10, !13, i64 24}
!16 = !{!10, !13, i64 32}
!17 = !{!13, !13, i64 0}
!18 = !{!12, !12, 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 void @_ZN8koishidb17FilterBlockReaderC2ERKNS_5SliceE(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) unnamed_addr #0 align 2 {
  tail call void @_ZN8koishidb11BloomFilterC2Ei(ptr noundef nonnull align 4 dereferenceable(8) %0, i32 noundef 10)
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %3, i8 0, i64 32, i1 false)
  %6 = tail call noundef i64 @_ZNK8koishidb5Slice4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %7 = icmp ult i64 %6, 5
  br i1 %7, label %25, label %8

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = add i64 %6, -1
  %11 = tail call noundef signext i8 @_ZNK8koishidb5SliceixEm(ptr noundef nonnull align 8 dereferenceable(16) %1, i64 noundef %10)
  %12 = sext i8 %11 to i64
  store i64 %12, ptr %9, align 8, !tbaa !5
  %13 = tail call noundef ptr @_ZNK8koishidb5Slice4dataEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %14 = getelementptr inbounds i8, ptr %13, i64 %6
  %15 = getelementptr inbounds i8, ptr %14, i64 -5
  %16 = tail call noundef i32 @_ZN8koishidb13DecodeFixed32EPKc(ptr noundef nonnull %15)
  %17 = zext i32 %16 to i64
  %18 = add i64 %6, -5
  %19 = icmp ult i64 %18, %17
  br i1 %19, label %25, label %20

20:                                               ; preds = %8
  %21 = tail call noundef ptr @_ZNK8koishidb5Slice4dataEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  store ptr %21, ptr %3, align 8, !tbaa !13
  %22 = getelementptr inbounds i8, ptr %21, i64 %17
  store ptr %22, ptr %4, align 8, !tbaa !14
  %23 = sub i64 %18, %17
  %24 = lshr i64 %23, 2
  store i64 %24, ptr %5, align 8, !tbaa !15
  br label %25

25:                                               ; preds = %20, %8, %2
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN8koishidb11BloomFilterC2Ei(ptr noundef nonnull align 4 dereferenceable(8), i32 noundef) unnamed_addr #1 align 2

declare noundef i64 @_ZNK8koishidb5Slice4sizeEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

declare noundef signext i8 @_ZNK8koishidb5SliceixEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) local_unnamed_addr #2

declare noundef i32 @_ZN8koishidb13DecodeFixed32EPKc(ptr noundef) local_unnamed_addr #2

declare noundef ptr @_ZNK8koishidb5Slice4dataEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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, !12, i64 32}
!6 = !{!"_ZTSN8koishidb17FilterBlockReaderE", !7, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !12, i64 32}
!7 = !{!"_ZTSN8koishidb11BloomFilterE", !8, i64 0, !8, i64 4}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"long", !9, i64 0}
!13 = !{!6, !11, i64 8}
!14 = !{!6, !11, i64 16}
!15 = !{!6, !12, i64 24}


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