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

; 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
declare dso_local ptr @ponyint_hashmap_next(ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @ponyint_hashmap_serialise(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %16, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = ptrtoint ptr %17 to i64
  %19 = load i64, ptr %8, align 8, !tbaa !9
  %20 = add i64 %18, %19
  %21 = inttoptr i64 %20 to ptr
  store ptr %21, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.hashmap_t, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = call i64 @pony_serialise_offset(ptr noundef %22, ptr noundef %25)
  store i64 %26, ptr %11, align 8, !tbaa !9
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.hashmap_t, ptr %27, i32 0, i32 0
  %29 = load i64, ptr %28, align 8, !tbaa !13
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.hashmap_t, ptr %30, i32 0, i32 0
  store i64 %29, ptr %31, align 8, !tbaa !13
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.hashmap_t, ptr %32, i32 0, i32 1
  %34 = load i64, ptr %33, align 8, !tbaa !14
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.hashmap_t, ptr %35, i32 0, i32 1
  store i64 %34, ptr %36, align 8, !tbaa !14
  %37 = load i64, ptr %11, align 8, !tbaa !9
  %38 = inttoptr i64 %37 to ptr
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.hashmap_t, ptr %39, i32 0, i32 2
  store ptr %38, ptr %40, align 8, !tbaa !11
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.hashmap_t, ptr %41, i32 0, i32 3
  store ptr null, ptr %42, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.hashmap_t, ptr %43, i32 0, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !14
  %46 = lshr i64 %45, 6
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.hashmap_t, ptr %47, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !14
  %50 = and i64 %49, 63
  %51 = icmp eq i64 %50, 0
  %52 = zext i1 %51 to i64
  %53 = select i1 %51, i32 0, i32 1
  %54 = sext i32 %53 to i64
  %55 = add i64 %46, %54
  store i64 %55, ptr %12, align 8, !tbaa !9
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = ptrtoint ptr %56 to i64
  %58 = load i64, ptr %11, align 8, !tbaa !9
  %59 = add i64 %57, %58
  %60 = inttoptr i64 %59 to ptr
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.hashmap_t, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !11
  %64 = load i64, ptr %12, align 8, !tbaa !9
  %65 = mul i64 %64, 8
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.hashmap_t, ptr %66, i32 0, i32 1
  %68 = load i64, ptr %67, align 8, !tbaa !14
  %69 = mul i64 %68, 16
  %70 = add i64 %65, %69
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %60, ptr align 8 %63, i64 %70, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = ptrtoint ptr %71 to i64
  %73 = load i64, ptr %11, align 8, !tbaa !9
  %74 = add i64 %72, %73
  %75 = load i64, ptr %12, align 8, !tbaa !9
  %76 = mul i64 %75, 8
  %77 = add i64 %74, %76
  %78 = inttoptr i64 %77 to ptr
  store ptr %78, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store i64 -1, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  br label %79

79:                                               ; preds = %94, %4
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.hashmap_t, ptr %80, i32 0, i32 0
  %82 = load i64, ptr %81, align 8, !tbaa !13
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.hashmap_t, ptr %83, i32 0, i32 2
  %85 = load ptr, ptr %84, align 8, !tbaa !11
  %86 = load ptr, ptr %9, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.hashmap_t, ptr %86, i32 0, i32 1
  %88 = load i64, ptr %87, align 8, !tbaa !14
  %89 = load ptr, ptr %9, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.hashmap_t, ptr %89, i32 0, i32 3
  %91 = load ptr, ptr %90, align 8, !tbaa !15
  %92 = call ptr @ponyint_hashmap_next(ptr noundef %14, i64 noundef %82, ptr noundef %85, i64 noundef %88, ptr noundef %91)
  store ptr %92, ptr %15, align 8, !tbaa !5
  %93 = icmp ne ptr %92, null
  br i1 %93, label %94, label %114

94:                                               ; preds = %79
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = load ptr, ptr %15, align 8, !tbaa !5
  %97 = call i64 @pony_serialise_offset(ptr noundef %95, ptr noundef %96)
  %98 = inttoptr i64 %97 to ptr
  %99 = load ptr, ptr %13, align 8, !tbaa !5
  %100 = load i64, ptr %14, align 8, !tbaa !9
  %101 = getelementptr inbounds %struct.hashmap_entry_t, ptr %99, i64 %100
  %102 = getelementptr inbounds %struct.hashmap_entry_t, ptr %101, i32 0, i32 0
  store ptr %98, ptr %102, align 8, !tbaa !16
  %103 = load ptr, ptr %9, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.hashmap_t, ptr %103, i32 0, i32 3
  %105 = load ptr, ptr %104, align 8, !tbaa !15
  %106 = load i64, ptr %14, align 8, !tbaa !9
  %107 = getelementptr inbounds %struct.hashmap_entry_t, ptr %105, i64 %106
  %108 = getelementptr inbounds %struct.hashmap_entry_t, ptr %107, i32 0, i32 1
  %109 = load i64, ptr %108, align 8, !tbaa !18
  %110 = load ptr, ptr %13, align 8, !tbaa !5
  %111 = load i64, ptr %14, align 8, !tbaa !9
  %112 = getelementptr inbounds %struct.hashmap_entry_t, ptr %110, i64 %111
  %113 = getelementptr inbounds %struct.hashmap_entry_t, ptr %112, i32 0, i32 1
  store i64 %109, ptr %113, align 8, !tbaa !18
  br label %79, !llvm.loop !19

114:                                              ; preds = %79
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

declare i64 @pony_serialise_offset(ptr noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!12, !6, i64 16}
!12 = !{!"hashmap_t", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !6, i64 24}
!16 = !{!17, !6, i64 0}
!17 = !{!"hashmap_entry_t", !6, i64 0, !10, i64 8}
!18 = !{!17, !10, 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"

%struct.hashmap_entry_t = 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: nounwind uwtable
declare dso_local ptr @ponyint_hashmap_next(ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @ponyint_hashmap_serialise(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #1 {
  %5 = alloca i64, align 8
  %6 = ptrtoint ptr %2 to i64
  %7 = add i64 %6, %3
  %8 = inttoptr i64 %7 to ptr
  %9 = getelementptr inbounds i8, ptr %1, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = tail call i64 @pony_serialise_offset(ptr noundef %0, ptr noundef %10) #4
  %12 = load i64, ptr %1, align 8, !tbaa !11
  store i64 %12, ptr %8, align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %1, i64 8
  %14 = load i64, ptr %13, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %8, i64 8
  store i64 %14, ptr %15, align 8, !tbaa !12
  %16 = inttoptr i64 %11 to ptr
  %17 = getelementptr inbounds i8, ptr %8, i64 16
  store ptr %16, ptr %17, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %8, i64 24
  store ptr null, ptr %18, align 8, !tbaa !13
  %19 = lshr i64 %14, 6
  %20 = and i64 %14, 63
  %21 = icmp ne i64 %20, 0
  %22 = zext i1 %21 to i64
  %23 = add nuw nsw i64 %19, %22
  %24 = add i64 %11, %6
  %25 = inttoptr i64 %24 to ptr
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = shl nuw nsw i64 %23, 3
  %28 = shl i64 %14, 4
  %29 = add i64 %27, %28
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %25, ptr align 8 %26, i64 %29, i1 false)
  %30 = add i64 %27, %24
  %31 = inttoptr i64 %30 to ptr
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  store i64 -1, ptr %5, align 8, !tbaa !14
  %32 = getelementptr inbounds i8, ptr %1, i64 24
  %33 = load i64, ptr %1, align 8, !tbaa !11
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = load i64, ptr %13, align 8, !tbaa !12
  %36 = load ptr, ptr %32, align 8, !tbaa !13
  %37 = call ptr @ponyint_hashmap_next(ptr noundef nonnull %5, i64 noundef %33, ptr noundef %34, i64 noundef %35, ptr noundef %36)
  %.not30 = icmp eq ptr %37, null
  br i1 %.not30, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %.lr.ph
  %38 = phi ptr [ %50, %.lr.ph ], [ %37, %4 ]
  %39 = call i64 @pony_serialise_offset(ptr noundef %0, ptr noundef nonnull %38) #4
  %40 = inttoptr i64 %39 to ptr
  %41 = load i64, ptr %5, align 8, !tbaa !14
  %42 = getelementptr inbounds %struct.hashmap_entry_t, ptr %31, i64 %41
  store ptr %40, ptr %42, align 8, !tbaa !15
  %43 = load ptr, ptr %32, align 8, !tbaa !13
  %44 = getelementptr inbounds %struct.hashmap_entry_t, ptr %43, i64 %41, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !17
  %46 = getelementptr inbounds %struct.hashmap_entry_t, ptr %31, i64 %41, i32 1
  store i64 %45, ptr %46, align 8, !tbaa !17
  %47 = load i64, ptr %1, align 8, !tbaa !11
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = load i64, ptr %13, align 8, !tbaa !12
  %50 = call ptr @ponyint_hashmap_next(ptr noundef nonnull %5, i64 noundef %47, ptr noundef %48, i64 noundef %49, ptr noundef %43)
  %.not = icmp eq ptr %50, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph, %4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  ret void
}

declare i64 @pony_serialise_offset(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 16}
!6 = !{!"hashmap_t", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !10, i64 24}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"hashmap_entry_t", !10, i64 0, !7, i64 8}
!17 = !{!16, !7, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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