; LLVM IR from begeekmyfriend/CuckooFilter :: cuckoo_filter (cuckoo_filter_init)

; 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.hash_table = type { ptr, ptr, i32, i32 }
%struct.hash_slot_cache = type { i32, i32 }

@hash_table = external hidden global %struct.hash_table, align 8
@nvrom_base_addr = external hidden global ptr, align 8
@nvrom_size = external hidden global i32, align 4

; 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 i32 @cuckoo_filter_init(i64 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %6 = load i64, ptr %3, align 8, !tbaa !5
  %7 = udiv i64 %6, 12
  %8 = add i64 %7, 1
  %9 = mul i64 %8, 32
  %10 = trunc i64 %9 to i32
  %11 = call i32 @next_pow_of_2(i32 noundef %10)
  store i32 %11, ptr @nvrom_size, align 4, !tbaa !9
  %12 = load i32, ptr @nvrom_size, align 4, !tbaa !9
  %13 = add i32 %12, 32
  %14 = zext i32 %13 to i64
  %15 = call noalias ptr @malloc(i64 noundef %14) #7
  store ptr %15, ptr @nvrom_base_addr, align 8, !tbaa !11
  %16 = load ptr, ptr @nvrom_base_addr, align 8, !tbaa !11
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %1
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %66

19:                                               ; preds = %1
  %20 = load ptr, ptr @nvrom_base_addr, align 8, !tbaa !11
  %21 = ptrtoint ptr %20 to i64
  %22 = add i64 %21, 32
  %23 = sub i64 %22, 1
  %24 = and i64 %23, -32
  %25 = inttoptr i64 %24 to ptr
  store ptr %25, ptr @nvrom_base_addr, align 8, !tbaa !11
  %26 = load i32, ptr @nvrom_size, align 4, !tbaa !9
  %27 = udiv i32 %26, 32
  store i32 %27, ptr getelementptr inbounds (%struct.hash_table, ptr @hash_table, i32 0, i32 2), align 8, !tbaa !13
  %28 = load i32, ptr getelementptr inbounds (%struct.hash_table, ptr @hash_table, i32 0, i32 2), align 8, !tbaa !13
  %29 = udiv i32 %28, 4
  store i32 %29, ptr getelementptr inbounds (%struct.hash_table, ptr @hash_table, i32 0, i32 2), align 8, !tbaa !13
  %30 = load i32, ptr getelementptr inbounds (%struct.hash_table, ptr @hash_table, i32 0, i32 2), align 8, !tbaa !13
  %31 = zext i32 %30 to i64
  %32 = call noalias ptr @calloc(i64 noundef %31, i64 noundef 8) #8
  store ptr %32, ptr getelementptr inbounds (%struct.hash_table, ptr @hash_table, i32 0, i32 1), align 8, !tbaa !15
  %33 = load ptr, ptr getelementptr inbounds (%struct.hash_table, ptr @hash_table, i32 0, i32 1), align 8, !tbaa !15
  %34 = icmp eq ptr %33, null
  br i1 %34, label %35, label %36

35:                                               ; preds = %19
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %66

36:                                               ; preds = %19
  %37 = load i32, ptr getelementptr inbounds (%struct.hash_table, ptr @hash_table, i32 0, i32 2), align 8, !tbaa !13
  %38 = udiv i32 %37, 4
  store i32 %38, ptr getelementptr inbounds (%struct.hash_table, ptr @hash_table, i32 0, i32 3), align 4, !tbaa !16
  %39 = load i32, ptr getelementptr inbounds (%struct.hash_table, ptr @hash_table, i32 0, i32 3), align 4, !tbaa !16
  %40 = zext i32 %39 to i64
  %41 = mul i64 %40, 8
  %42 = call noalias ptr @malloc(i64 noundef %41) #7
  store ptr %42, ptr @hash_table, align 8, !tbaa !17
  %43 = load ptr, ptr @hash_table, align 8, !tbaa !17
  %44 = icmp eq ptr %43, null
  br i1 %44, label %45, label %47

45:                                               ; preds = %36
  %46 = load ptr, ptr getelementptr inbounds (%struct.hash_table, ptr @hash_table, i32 0, i32 1), align 8, !tbaa !15
  call void @free(ptr noundef %46) #6
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %66

47:                                               ; preds = %36
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %62, %47
  %49 = load i32, ptr %4, align 4, !tbaa !9
  %50 = load i32, ptr getelementptr inbounds (%struct.hash_table, ptr @hash_table, i32 0, i32 3), align 4, !tbaa !16
  %51 = icmp ult i32 %49, %50
  br i1 %51, label %52, label %65

52:                                               ; preds = %48
  %53 = load ptr, ptr getelementptr inbounds (%struct.hash_table, ptr @hash_table, i32 0, i32 1), align 8, !tbaa !15
  %54 = load i32, ptr %4, align 4, !tbaa !9
  %55 = mul nsw i32 %54, 4
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds %struct.hash_slot_cache, ptr %53, i64 %56
  %58 = load ptr, ptr @hash_table, align 8, !tbaa !17
  %59 = load i32, ptr %4, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds ptr, ptr %58, i64 %60
  store ptr %57, ptr %61, align 8, !tbaa !11
  br label %62

62:                                               ; preds = %52
  %63 = load i32, ptr %4, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %4, align 4, !tbaa !9
  br label %48, !llvm.loop !18

65:                                               ; preds = %48
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %66

66:                                               ; preds = %65, %45, %35, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  %67 = load i32, ptr %2, align 4
  ret i32 %67
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @next_pow_of_2(i32 noundef) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #4

; Function Attrs: nounwind
declare void @free(ptr noundef) #5

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 = { nounwind allocsize(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 allocsize(0,1) "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 #5 = { nounwind "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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { nounwind allocsize(0,1) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !10, i64 16}
!14 = !{!"hash_table", !12, i64 0, !12, i64 8, !10, i64 16, !10, i64 20}
!15 = !{!14, !12, i64 8}
!16 = !{!14, !10, i64 20}
!17 = !{!14, !12, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct.hash_table = type { ptr, ptr, i32, i32 }

@hash_table = external hidden local_unnamed_addr global %struct.hash_table, align 8
@nvrom_base_addr = external hidden local_unnamed_addr global ptr, align 8
@nvrom_size = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @cuckoo_filter_init(i64 noundef %0) local_unnamed_addr #0 {
  %2 = udiv i64 %0, 12
  %.tr = trunc i64 %2 to i32
  %3 = shl i32 %.tr, 5
  %4 = add i32 %3, 32
  %5 = tail call i32 @next_pow_of_2(i32 noundef %4)
  store i32 %5, ptr @nvrom_size, align 4, !tbaa !5
  %6 = add i32 %5, 32
  %7 = zext i32 %6 to i64
  %8 = tail call noalias ptr @malloc(i64 noundef %7) #5
  store ptr %8, ptr @nvrom_base_addr, align 8, !tbaa !9
  %9 = icmp eq ptr %8, null
  br i1 %9, label %.loopexit, label %10

10:                                               ; preds = %1
  %11 = ptrtoint ptr %8 to i64
  %12 = add i64 %11, 31
  %13 = and i64 %12, -32
  %14 = inttoptr i64 %13 to ptr
  store ptr %14, ptr @nvrom_base_addr, align 8, !tbaa !9
  %15 = lshr i32 %5, 7
  store i32 %15, ptr getelementptr inbounds (i8, ptr @hash_table, i64 16), align 8, !tbaa !11
  %16 = zext nneg i32 %15 to i64
  %17 = tail call noalias ptr @calloc(i64 noundef %16, i64 noundef 8) #6
  store ptr %17, ptr getelementptr inbounds (i8, ptr @hash_table, i64 8), align 8, !tbaa !13
  %18 = icmp eq ptr %17, null
  br i1 %18, label %.loopexit, label %19

19:                                               ; preds = %10
  %20 = lshr i32 %5, 9
  store i32 %20, ptr getelementptr inbounds (i8, ptr @hash_table, i64 20), align 4, !tbaa !14
  %21 = shl nuw nsw i32 %20, 3
  %22 = zext nneg i32 %21 to i64
  %23 = tail call noalias ptr @malloc(i64 noundef %22) #5
  store ptr %23, ptr @hash_table, align 8, !tbaa !15
  %24 = icmp eq ptr %23, null
  br i1 %24, label %27, label %.preheader

.preheader:                                       ; preds = %19
  %.not = icmp ult i32 %5, 512
  br i1 %.not, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %20 to i64
  %25 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %wide.trip.count, 3
  %26 = icmp ult i64 %25, 3
  br i1 %26, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 8388604
  br label %.lr.ph

27:                                               ; preds = %19
  tail call void @free(ptr noundef nonnull %17) #7
  br label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %28 = load ptr, ptr getelementptr inbounds (i8, ptr @hash_table, i64 8), align 8, !tbaa !13
  %.idx = shl nsw i64 %indvars.iv, 5
  %29 = getelementptr inbounds i8, ptr %28, i64 %.idx
  %30 = load ptr, ptr @hash_table, align 8, !tbaa !15
  %31 = getelementptr inbounds ptr, ptr %30, i64 %indvars.iv
  store ptr %29, ptr %31, align 8, !tbaa !9
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %32 = load ptr, ptr getelementptr inbounds (i8, ptr @hash_table, i64 8), align 8, !tbaa !13
  %.idx.1 = shl nsw i64 %indvars.iv.next, 5
  %33 = getelementptr inbounds i8, ptr %32, i64 %.idx.1
  %34 = load ptr, ptr @hash_table, align 8, !tbaa !15
  %35 = getelementptr inbounds ptr, ptr %34, i64 %indvars.iv.next
  store ptr %33, ptr %35, align 8, !tbaa !9
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %36 = load ptr, ptr getelementptr inbounds (i8, ptr @hash_table, i64 8), align 8, !tbaa !13
  %.idx.2 = shl nsw i64 %indvars.iv.next.1, 5
  %37 = getelementptr inbounds i8, ptr %36, i64 %.idx.2
  %38 = load ptr, ptr @hash_table, align 8, !tbaa !15
  %39 = getelementptr inbounds ptr, ptr %38, i64 %indvars.iv.next.1
  store ptr %37, ptr %39, align 8, !tbaa !9
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %40 = load ptr, ptr getelementptr inbounds (i8, ptr @hash_table, i64 8), align 8, !tbaa !13
  %.idx.3 = shl nsw i64 %indvars.iv.next.2, 5
  %41 = getelementptr inbounds i8, ptr %40, i64 %.idx.3
  %42 = load ptr, ptr @hash_table, align 8, !tbaa !15
  %43 = getelementptr inbounds ptr, ptr %42, i64 %indvars.iv.next.2
  store ptr %41, ptr %43, align 8, !tbaa !9
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !16

.loopexit.loopexit.unr-lcssa:                     ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %44 = load ptr, ptr getelementptr inbounds (i8, ptr @hash_table, i64 8), align 8, !tbaa !13
  %.idx.epil = shl nsw i64 %indvars.iv.epil, 5
  %45 = getelementptr inbounds i8, ptr %44, i64 %.idx.epil
  %46 = load ptr, ptr @hash_table, align 8, !tbaa !15
  %47 = getelementptr inbounds ptr, ptr %46, i64 %indvars.iv.epil
  store ptr %45, ptr %47, align 8, !tbaa !9
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.loopexit, label %.lr.ph.epil, !llvm.loop !18

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph.epil, %.preheader, %10, %1, %27
  %.06 = phi i32 [ -1, %27 ], [ -1, %1 ], [ -1, %10 ], [ 0, %.preheader ], [ 0, %.lr.ph.epil ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  ret i32 %.06
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @next_pow_of_2(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #5 = { nounwind allocsize(0) }
attributes #6 = { nounwind allocsize(0,1) }
attributes #7 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"hash_table", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 20}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !6, i64 20}
!15 = !{!12, !10, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}


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