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

; 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 }
%struct.gc_t = type { i32, i32, i64, %struct.objectmap_t, %struct.actormap_t, ptr }
%struct.actormap_t = type { %struct.hashmap_t }
%struct.object_t = type { ptr, i64, i32, i8, ptr }

@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [70 x i8], align 1
@__func__.ponyint_gc_release = external hidden unnamed_addr constant [19 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [25 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

declare ptr @ponyint_objectmap_next(ptr noundef, ptr noundef) #1

declare void @ponyint_actorref_free(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @ponyint_gc_release(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.actorref_t, ptr %12, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !9
  store i64 %14, ptr %5, align 8, !tbaa !15
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.gc_t, ptr %15, i32 0, i32 2
  %17 = load i64, ptr %16, align 8, !tbaa !16
  %18 = load i64, ptr %5, align 8, !tbaa !15
  %19 = icmp uge i64 %17, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %2
  br label %22

21:                                               ; preds = %2
  call void @ponyint_assert_fail(ptr noundef @.str, ptr noundef @.str.1, i64 noundef 760, ptr noundef @__func__.ponyint_gc_release)
  br label %22

22:                                               ; preds = %21, %20
  %23 = load i64, ptr %5, align 8, !tbaa !15
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.gc_t, ptr %24, i32 0, i32 2
  %26 = load i64, ptr %25, align 8, !tbaa !16
  %27 = sub i64 %26, %23
  store i64 %27, ptr %25, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.actorref_t, ptr %28, i32 0, i32 3
  store ptr %29, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 -1, ptr %7, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 -1, ptr %9, align 8, !tbaa !15
  br label %30

30:                                               ; preds = %51, %22
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = call ptr @ponyint_objectmap_next(ptr noundef %31, ptr noundef %7)
  store ptr %32, ptr %8, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %59

34:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.object_t, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !19
  store ptr %37, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.gc_t, ptr %38, i32 0, i32 3
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = call ptr @ponyint_objectmap_getobject(ptr noundef %39, ptr noundef %40, ptr noundef %9)
  store ptr %41, ptr %11, align 8, !tbaa !5
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.object_t, ptr %42, i32 0, i32 1
  %44 = load i64, ptr %43, align 8, !tbaa !22
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.object_t, ptr %45, i32 0, i32 1
  %47 = load i64, ptr %46, align 8, !tbaa !22
  %48 = icmp uge i64 %44, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %34
  br label %51

50:                                               ; preds = %34
  call void @ponyint_assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i64 noundef 773, ptr noundef @__func__.ponyint_gc_release)
  br label %51

51:                                               ; preds = %50, %49
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.object_t, ptr %52, i32 0, i32 1
  %54 = load i64, ptr %53, align 8, !tbaa !22
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.object_t, ptr %55, i32 0, i32 1
  %57 = load i64, ptr %56, align 8, !tbaa !22
  %58 = sub i64 %57, %54
  store i64 %58, ptr %56, align 8, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %30, !llvm.loop !23

59:                                               ; preds = %30
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ponyint_actorref_free(ptr noundef %60)
  %61 = load i64, ptr %5, align 8, !tbaa !15
  %62 = icmp ugt i64 %61, 0
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i1 %62
}

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

declare ptr @ponyint_objectmap_getobject(ptr noundef, ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"actorref_t", !6, i64 0, !11, i64 8, !12, i64 16, !13, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"objectmap_t", !14, i64 0}
!14 = !{!"hashmap_t", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!11, !11, i64 0}
!16 = !{!17, !11, i64 8}
!17 = !{!"gc_t", !12, i64 0, !12, i64 4, !11, i64 8, !13, i64 16, !18, i64 48, !6, i64 80}
!18 = !{!"actormap_t", !14, i64 0}
!19 = !{!20, !6, i64 0}
!20 = !{!"object_t", !6, i64 0, !11, i64 8, !12, i64 16, !21, i64 20, !6, i64 24}
!21 = !{!"_Bool", !7, i64 0}
!22 = !{!20, !11, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"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"

@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [70 x i8], align 1
@__func__.ponyint_gc_release = external hidden unnamed_addr constant [19 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1

; 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

declare ptr @ponyint_objectmap_next(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @ponyint_actorref_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @ponyint_gc_release(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !14
  %.not = icmp ult i64 %8, %6
  br i1 %.not, label %9, label %10

9:                                                ; preds = %2
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i64 noundef 760, ptr noundef nonnull @__func__.ponyint_gc_release) #3
  %.pre = load i64, ptr %7, align 8, !tbaa !14
  br label %10

10:                                               ; preds = %2, %9
  %11 = phi i64 [ %8, %2 ], [ %.pre, %9 ]
  %12 = sub i64 %11, %6
  store i64 %12, ptr %7, align 8, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %1, i64 24
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store i64 -1, ptr %3, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  store i64 -1, ptr %4, align 8, !tbaa !17
  %14 = call ptr @ponyint_objectmap_next(ptr noundef nonnull %13, ptr noundef nonnull %3) #3
  %.not1517 = icmp eq ptr %14, null
  br i1 %.not1517, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %10
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  br label %16

16:                                               ; preds = %.lr.ph, %25
  %17 = phi ptr [ %14, %.lr.ph ], [ %29, %25 ]
  %18 = load ptr, ptr %17, align 8, !tbaa !18
  %19 = call ptr @ponyint_objectmap_getobject(ptr noundef nonnull %15, ptr noundef %18, ptr noundef nonnull %4) #3
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %21 = load i64, ptr %20, align 8, !tbaa !21
  %22 = getelementptr inbounds i8, ptr %17, i64 8
  %23 = load i64, ptr %22, align 8, !tbaa !21
  %.not16 = icmp ult i64 %21, %23
  br i1 %.not16, label %24, label %25

24:                                               ; preds = %16
  call void @ponyint_assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i64 noundef 773, ptr noundef nonnull @__func__.ponyint_gc_release) #3
  %.pre18 = load i64, ptr %22, align 8, !tbaa !21
  %.pre19 = load i64, ptr %20, align 8, !tbaa !21
  br label %25

25:                                               ; preds = %16, %24
  %26 = phi i64 [ %21, %16 ], [ %.pre19, %24 ]
  %27 = phi i64 [ %23, %16 ], [ %.pre18, %24 ]
  %28 = sub i64 %26, %27
  store i64 %28, ptr %20, align 8, !tbaa !21
  %29 = call ptr @ponyint_objectmap_next(ptr noundef nonnull %13, ptr noundef nonnull %3) #3
  %.not15 = icmp eq ptr %29, null
  br i1 %.not15, label %._crit_edge, label %16, !llvm.loop !22

._crit_edge:                                      ; preds = %25, %10
  call void @ponyint_actorref_free(ptr noundef %1) #3
  %30 = icmp ne i64 %6, 0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret i1 %30
}

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

declare ptr @ponyint_objectmap_getobject(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !10, i64 8}
!6 = !{!"actorref_t", !7, i64 0, !10, i64 8, !11, i64 16, !12, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"objectmap_t", !13, i64 0}
!13 = !{!"hashmap_t", !10, i64 0, !10, i64 8, !7, i64 16, !7, i64 24}
!14 = !{!15, !10, i64 8}
!15 = !{!"gc_t", !11, i64 0, !11, i64 4, !10, i64 8, !12, i64 16, !16, i64 48, !7, i64 80}
!16 = !{!"actormap_t", !13, i64 0}
!17 = !{!10, !10, i64 0}
!18 = !{!19, !7, i64 0}
!19 = !{!"object_t", !7, i64 0, !10, i64 8, !11, i64 16, !20, i64 20, !7, i64 24}
!20 = !{!"_Bool", !8, i64 0}
!21 = !{!19, !10, i64 8}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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