; LLVM IR from tuplex/tuplex :: tuplex/utils/src (int_hashmap)

; 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._int64_hashmap_map = type { i32, i32, ptr }
%struct._int_hashmap_element = type { i64, 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: mustprogress nounwind uwtable
define dso_local i64 @int64_hashmap_bucket_count(ptr noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %8, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %1
  store i64 0, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %37

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %13

13:                                               ; preds = %32, %12
  %14 = load i32, ptr %7, align 4, !tbaa !11
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._int64_hashmap_map, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !13
  %18 = icmp ult i32 %14, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %13
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %35

20:                                               ; preds = %13
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._int64_hashmap_map, ptr %21, i32 0, i32 2
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = load i32, ptr %7, align 4, !tbaa !11
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds %struct._int_hashmap_element, ptr %23, i64 %25
  %27 = getelementptr inbounds %struct._int_hashmap_element, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 8, !tbaa !16
  %29 = sext i32 %28 to i64
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = add i64 %30, %29
  store i64 %31, ptr %6, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %20
  %33 = load i32, ptr %7, align 4, !tbaa !11
  %34 = add i32 %33, 1
  store i32 %34, ptr %7, align 4, !tbaa !11
  br label %13, !llvm.loop !18

35:                                               ; preds = %19
  %36 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %36, ptr %2, align 8
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %37

37:                                               ; preds = %35, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %38 = load i64, ptr %2, align 8
  ret i64 %38
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ZTS18_int64_hashmap_map", !12, i64 0, !12, i64 4, !6, i64 8}
!15 = !{!14, !6, i64 8}
!16 = !{!17, !12, i64 8}
!17 = !{!"_ZTS20_int_hashmap_element", !10, i64 0, !12, i64 8, !6, i64 16}
!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._int_hashmap_element = type { i64, i32, ptr }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local i64 @int64_hashmap_bucket_count(ptr noundef readonly %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %1
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %.not14 = icmp eq i32 %2, 0
  br i1 %.not14, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !11
  %wide.trip.count = zext i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %5 = icmp ult i32 %2, 4
  br i1 %5, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.new

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

6:                                                ; preds = %6, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %6 ]
  %.0912 = phi i64 [ 0, %.lr.ph.new ], [ %22, %6 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %6 ]
  %7 = getelementptr inbounds %struct._int_hashmap_element, ptr %4, i64 %indvars.iv, i32 1
  %8 = load i32, ptr %7, align 8, !tbaa !12
  %9 = sext i32 %8 to i64
  %10 = add i64 %.0912, %9
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %11 = getelementptr inbounds %struct._int_hashmap_element, ptr %4, i64 %indvars.iv.next, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !12
  %13 = sext i32 %12 to i64
  %14 = add i64 %10, %13
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %15 = getelementptr inbounds %struct._int_hashmap_element, ptr %4, i64 %indvars.iv.next.1, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !12
  %17 = sext i32 %16 to i64
  %18 = add i64 %14, %17
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %19 = getelementptr inbounds %struct._int_hashmap_element, ptr %4, i64 %indvars.iv.next.2, i32 1
  %20 = load i32, ptr %19, align 8, !tbaa !12
  %21 = sext i32 %20 to i64
  %22 = add i64 %18, %21
  %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 %6, !llvm.loop !15

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

.epil.preheader:                                  ; preds = %.loopexit.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %.loopexit.loopexit.unr-lcssa ]
  %.0912.epil = phi i64 [ %26, %.epil.preheader ], [ %.0912.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %23 = getelementptr inbounds %struct._int_hashmap_element, ptr %4, i64 %indvars.iv.epil, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !12
  %25 = sext i32 %24 to i64
  %26 = add i64 %.0912.epil, %25
  %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 %.epil.preheader, !llvm.loop !17

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.epil.preheader, %.preheader, %1
  %.010 = phi i64 [ 0, %1 ], [ 0, %.preheader ], [ %.lcssa.ph, %.loopexit.loopexit.unr-lcssa ], [ %26, %.epil.preheader ]
  ret i64 %.010
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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" }

!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, !7, i64 0}
!6 = !{!"_ZTS18_int64_hashmap_map", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!13, !7, i64 8}
!13 = !{!"_ZTS20_int_hashmap_element", !14, i64 0, !7, i64 8, !10, i64 16}
!14 = !{!"long", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass