; LLVM IR from ponylang/ponyc :: src/libponyrt/ds (hash)

; 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.hashmap_entry_t = type { ptr, i64 }

@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [27 x i8], align 1
@__func__.ponyint_hashmap_next = external hidden unnamed_addr constant [21 x i8], align 1

; 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 ptr @ponyint_hashmap_next(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %5
  store ptr null, ptr %6, align 8
  br label %81

21:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = add i64 %23, 1
  store i64 %24, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %25 = load i64, ptr %12, align 8, !tbaa !9
  %26 = lshr i64 %25, 6
  store i64 %26, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %27 = load i64, ptr %12, align 8, !tbaa !9
  %28 = and i64 %27, 63
  store i64 %28, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  store i64 0, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = load i64, ptr %13, align 8, !tbaa !9
  %31 = getelementptr inbounds i64, ptr %29, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !9
  %33 = load i64, ptr %14, align 8, !tbaa !9
  %34 = lshr i64 %32, %33
  store i64 %34, ptr %16, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %45, %21
  %36 = load i64, ptr %12, align 8, !tbaa !9
  %37 = load i64, ptr %10, align 8, !tbaa !9
  %38 = icmp ult i64 %36, %37
  br i1 %38, label %39, label %77

39:                                               ; preds = %35
  %40 = load i64, ptr %16, align 8, !tbaa !9
  %41 = call i32 @__pony_ffszu(i64 noundef %40)
  %42 = zext i32 %41 to i64
  store i64 %42, ptr %15, align 8, !tbaa !9
  %43 = load i64, ptr %15, align 8, !tbaa !9
  %44 = icmp eq i64 %43, 0
  br i1 %44, label %45, label %56

45:                                               ; preds = %39
  %46 = load i64, ptr %14, align 8, !tbaa !9
  %47 = sub i64 64, %46
  %48 = load i64, ptr %12, align 8, !tbaa !9
  %49 = add i64 %48, %47
  store i64 %49, ptr %12, align 8, !tbaa !9
  %50 = load i64, ptr %13, align 8, !tbaa !9
  %51 = add i64 %50, 1
  store i64 %51, ptr %13, align 8, !tbaa !9
  store i64 0, ptr %14, align 8, !tbaa !9
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = load i64, ptr %13, align 8, !tbaa !9
  %54 = getelementptr inbounds i64, ptr %52, i64 %53
  %55 = load i64, ptr %54, align 8, !tbaa !9
  store i64 %55, ptr %16, align 8, !tbaa !9
  br label %35, !llvm.loop !11

56:                                               ; preds = %39
  %57 = load i64, ptr %15, align 8, !tbaa !9
  %58 = sub i64 %57, 1
  %59 = load i64, ptr %12, align 8, !tbaa !9
  %60 = add i64 %59, %58
  store i64 %60, ptr %12, align 8, !tbaa !9
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = load i64, ptr %12, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.hashmap_entry_t, ptr %61, i64 %62
  %64 = getelementptr inbounds %struct.hashmap_entry_t, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !13
  %66 = icmp ne ptr %65, null
  br i1 %66, label %67, label %68

67:                                               ; preds = %56
  br label %69

68:                                               ; preds = %56
  call void @ponyint_assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i64 noundef 488, ptr noundef @__func__.ponyint_hashmap_next)
  br label %69

69:                                               ; preds = %68, %67
  %70 = load i64, ptr %12, align 8, !tbaa !9
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %70, ptr %71, align 8, !tbaa !9
  %72 = load ptr, ptr %11, align 8, !tbaa !5
  %73 = load i64, ptr %12, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.hashmap_entry_t, ptr %72, i64 %73
  %75 = getelementptr inbounds %struct.hashmap_entry_t, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !13
  store ptr %76, ptr %6, align 8
  store i32 1, ptr %17, align 4
  br label %80

77:                                               ; preds = %35
  %78 = load i64, ptr %10, align 8, !tbaa !9
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %78, ptr %79, align 8, !tbaa !9
  store ptr null, ptr %6, align 8
  store i32 1, ptr %17, align 4
  br label %80

80:                                               ; preds = %77, %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %81

81:                                               ; preds = %80, %20
  %82 = load ptr, ptr %6, align 8
  ret ptr %82
}

declare void @ponyint_assert_fail(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare i32 @__pony_ffszu(i64 noundef) #3

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 = { "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 = { 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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !6, i64 0}
!14 = !{!"hashmap_entry_t", !6, i64 0, !10, i64 8}


; 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.hashmap_entry_t = type { ptr, i64 }

@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [27 x i8], align 1
@__func__.ponyint_hashmap_next = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @ponyint_hashmap_next(ptr nocapture noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3, ptr nocapture noundef readonly %4) local_unnamed_addr #0 {
  %6 = icmp eq i64 %1, 0
  br i1 %6, label %34, label %7

7:                                                ; preds = %5
  %8 = load i64, ptr %0, align 8, !tbaa !5
  %9 = add i64 %8, 1
  %10 = lshr i64 %9, 6
  %11 = and i64 %9, 63
  %12 = icmp ult i64 %9, %3
  br i1 %12, label %.lr.ph.preheader, label %.sink.split

.lr.ph.preheader:                                 ; preds = %7
  %13 = getelementptr inbounds i64, ptr %2, i64 %10
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = lshr i64 %14, %11
  %16 = tail call i32 @__pony_ffszu(i64 noundef %15)
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %28

18:                                               ; preds = %.lr.ph.preheader
  %19 = sub i64 %8, %11
  %20 = add i64 %19, 65
  %21 = icmp ult i64 %20, %3
  br i1 %21, label %.lr.ph, label %.sink.split

.lr.ph:                                           ; preds = %18, %24
  %.02734.in = phi i64 [ %.02734, %24 ], [ %10, %18 ]
  %.02833 = phi i64 [ %25, %24 ], [ %20, %18 ]
  %.02734 = add i64 %.02734.in, 1
  %.036.in = getelementptr inbounds i64, ptr %2, i64 %.02734
  %.036 = load i64, ptr %.036.in, align 8, !tbaa !5
  %22 = tail call i32 @__pony_ffszu(i64 noundef %.036)
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %.loopexit

24:                                               ; preds = %.lr.ph
  %25 = add i64 %.02833, 64
  %26 = icmp ult i64 %25, %3
  br i1 %26, label %.lr.ph, label %.sink.split, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph
  %27 = add i64 %.02833, -1
  br label %28

28:                                               ; preds = %.loopexit, %.lr.ph.preheader
  %.02833.lcssa = phi i64 [ %8, %.lr.ph.preheader ], [ %27, %.loopexit ]
  %.lcssa = phi i32 [ %16, %.lr.ph.preheader ], [ %22, %.loopexit ]
  %29 = zext i32 %.lcssa to i64
  %30 = add i64 %.02833.lcssa, %29
  %31 = getelementptr inbounds %struct.hashmap_entry_t, ptr %4, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !12
  %.not = icmp eq ptr %32, null
  br i1 %.not, label %33, label %.sink.split

33:                                               ; preds = %28
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i64 noundef 488, ptr noundef nonnull @__func__.ponyint_hashmap_next) #3
  %.pre = load ptr, ptr %31, align 8, !tbaa !12
  br label %.sink.split

.sink.split:                                      ; preds = %24, %7, %18, %33, %28
  %.sink = phi i64 [ %30, %28 ], [ %30, %33 ], [ %3, %18 ], [ %3, %7 ], [ %3, %24 ]
  %.1.ph = phi ptr [ %32, %28 ], [ %.pre, %33 ], [ null, %18 ], [ null, %7 ], [ null, %24 ]
  store i64 %.sink, ptr %0, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %.sink.split, %5
  %.1 = phi ptr [ null, %5 ], [ %.1.ph, %.sink.split ]
  ret ptr %.1
}

declare void @ponyint_assert_fail(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare i32 @__pony_ffszu(i64 noundef) local_unnamed_addr #2

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 = { "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 }

!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 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.peeled.count", i32 1}
!12 = !{!13, !14, i64 0}
!13 = !{!"hashmap_entry_t", !14, i64 0, !6, i64 8}
!14 = !{!"any pointer", !7, i64 0}


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