; LLVM IR from ponylang/ponyc :: src/libponyrt/gc (actormap)

; 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.actorref_t = type { ptr, i64, i32, %struct.objectmap_t }
%struct.objectmap_t = type { %struct.hashmap_t }
%struct.hashmap_t = type { i64, i64, ptr, 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: nounwind uwtable
declare dso_local void @ponyint_actormap_optimize(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @ponyint_actormap_clearindex(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @ponyint_actormap_next(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @ponyint_actormap_sweep(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i1 noundef zeroext %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i8, align 1
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i8, align 1
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %14 = zext i1 %4 to i8
  store i8 %14, ptr %10, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store i64 -1, ptr %11, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #3
  store i8 0, ptr %13, align 1, !tbaa !11
  br label %15

15:                                               ; preds = %41, %5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = call ptr @ponyint_actormap_next(ptr noundef %16, ptr noundef %11)
  store ptr %17, ptr %12, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %44

19:                                               ; preds = %15
  %20 = load ptr, ptr %12, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.actorref_t, ptr %20, i32 0, i32 2
  %22 = load i32, ptr %21, align 8, !tbaa !15
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = icmp eq i32 %22, %23
  br i1 %24, label %25, label %29

25:                                               ; preds = %19
  %26 = load ptr, ptr %12, align 8, !tbaa !5
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = call ptr @move_unmarked_objects(ptr noundef %26, i32 noundef %27)
  store ptr %28, ptr %12, align 8, !tbaa !5
  br label %41

29:                                               ; preds = %19
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load i64, ptr %11, align 8, !tbaa !13
  call void @ponyint_actormap_clearindex(ptr noundef %30, i64 noundef %31)
  %32 = load i8, ptr %10, align 1, !tbaa !11, !range !19, !noundef !20
  %33 = trunc i8 %32 to i1
  br i1 %33, label %40, label %34

34:                                               ; preds = %29
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = load ptr, ptr %12, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.actorref_t, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !21
  %39 = call ptr @ponyint_deltamap_update(ptr noundef %35, ptr noundef %38, i64 noundef 0)
  store ptr %39, ptr %9, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %34, %29
  store i8 1, ptr %13, align 1, !tbaa !11
  br label %41

41:                                               ; preds = %40, %25
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  call void @send_release(ptr noundef %42, ptr noundef %43)
  br label %15, !llvm.loop !22

44:                                               ; preds = %15
  %45 = load i8, ptr %13, align 1, !tbaa !11, !range !19, !noundef !20
  %46 = trunc i8 %45 to i1
  br i1 %46, label %47, label %49

47:                                               ; preds = %44
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ponyint_actormap_optimize(ptr noundef %48)
  br label %49

49:                                               ; preds = %47, %44
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret ptr %50
}

; Function Attrs: nounwind uwtable
declare hidden ptr @move_unmarked_objects(ptr noundef, i32 noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden void @send_release(ptr noundef, ptr noundef) #1

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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !10, i64 16}
!16 = !{!"actorref_t", !6, i64 0, !14, i64 8, !10, i64 16, !17, i64 24}
!17 = !{!"objectmap_t", !18, i64 0}
!18 = !{!"hashmap_t", !14, i64 0, !14, i64 8, !6, i64 16, !6, i64 24}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!16, !6, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"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"

; 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 void @ponyint_actormap_optimize(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @ponyint_actormap_clearindex(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @ponyint_actormap_next(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @ponyint_actormap_sweep(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i1 noundef zeroext %4) local_unnamed_addr #1 {
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  store i64 -1, ptr %6, align 8, !tbaa !5
  %7 = call ptr @ponyint_actormap_next(ptr noundef %1, ptr noundef nonnull %6)
  %.not18 = icmp eq ptr %7, null
  br i1 %.not18, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %5
  br i1 %4, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %16
  %8 = phi ptr [ %17, %16 ], [ %7, %.lr.ph ]
  %.020.us = phi i1 [ %.1.us, %16 ], [ false, %.lr.ph ]
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = icmp eq i32 %10, %2
  br i1 %11, label %14, label %12

12:                                               ; preds = %.lr.ph.split.us
  %13 = load i64, ptr %6, align 8, !tbaa !5
  call void @ponyint_actormap_clearindex(ptr noundef %1, i64 noundef %13)
  br label %16

14:                                               ; preds = %.lr.ph.split.us
  %15 = call ptr @move_unmarked_objects(ptr noundef nonnull %8, i32 noundef %2)
  br label %16

16:                                               ; preds = %12, %14
  %.013.us = phi ptr [ %15, %14 ], [ %8, %12 ]
  %.1.us = phi i1 [ %.020.us, %14 ], [ true, %12 ]
  call void @send_release(ptr noundef %0, ptr noundef %.013.us)
  %17 = call ptr @ponyint_actormap_next(ptr noundef %1, ptr noundef nonnull %6)
  %.not.us = icmp eq ptr %17, null
  br i1 %.not.us, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !15

.lr.ph.split:                                     ; preds = %.lr.ph, %28
  %18 = phi ptr [ %29, %28 ], [ %7, %.lr.ph ]
  %.020 = phi i1 [ %.1, %28 ], [ false, %.lr.ph ]
  %.01419 = phi ptr [ %.2, %28 ], [ %3, %.lr.ph ]
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  %20 = load i32, ptr %19, align 8, !tbaa !9
  %21 = icmp eq i32 %20, %2
  br i1 %21, label %22, label %24

22:                                               ; preds = %.lr.ph.split
  %23 = call ptr @move_unmarked_objects(ptr noundef nonnull %18, i32 noundef %2)
  br label %28

24:                                               ; preds = %.lr.ph.split
  %25 = load i64, ptr %6, align 8, !tbaa !5
  call void @ponyint_actormap_clearindex(ptr noundef %1, i64 noundef %25)
  %26 = load ptr, ptr %18, align 8, !tbaa !17
  %27 = call ptr @ponyint_deltamap_update(ptr noundef %.01419, ptr noundef %26, i64 noundef 0) #3
  br label %28

28:                                               ; preds = %24, %22
  %.2 = phi ptr [ %.01419, %22 ], [ %27, %24 ]
  %.013 = phi ptr [ %23, %22 ], [ %18, %24 ]
  %.1 = phi i1 [ %.020, %22 ], [ true, %24 ]
  call void @send_release(ptr noundef %0, ptr noundef %.013)
  %29 = call ptr @ponyint_actormap_next(ptr noundef %1, ptr noundef nonnull %6)
  %.not = icmp eq ptr %29, null
  br i1 %.not, label %._crit_edge, label %.lr.ph.split, !llvm.loop !15

._crit_edge:                                      ; preds = %28, %16
  %.014.lcssa = phi ptr [ %3, %16 ], [ %.2, %28 ]
  %.0.lcssa = phi i1 [ %.1.us, %16 ], [ %.1, %28 ]
  br i1 %.0.lcssa, label %30, label %._crit_edge.thread

30:                                               ; preds = %._crit_edge
  call void @ponyint_actormap_optimize(ptr noundef %1)
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %5, %30, %._crit_edge
  %.014.lcssa26 = phi ptr [ %.014.lcssa, %30 ], [ %.014.lcssa, %._crit_edge ], [ %3, %5 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  ret ptr %.014.lcssa26
}

; Function Attrs: nounwind uwtable
declare hidden ptr @move_unmarked_objects(ptr noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare hidden void @send_release(ptr noundef, ptr noundef) local_unnamed_addr #1

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 = { 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 = !{!10, !12, i64 16}
!10 = !{!"actorref_t", !11, i64 0, !6, i64 8, !12, i64 16, !13, i64 24}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"objectmap_t", !14, i64 0}
!14 = !{!"hashmap_t", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!10, !11, i64 0}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass