; 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 }

; 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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @ponyint_gc_acquire(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 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
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.actorref_t, ptr %10, i32 0, i32 1
  %12 = load i64, ptr %11, align 8, !tbaa !9
  store i64 %12, ptr %5, align 8, !tbaa !15
  %13 = load i64, ptr %5, align 8, !tbaa !15
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.gc_t, ptr %14, i32 0, i32 2
  %16 = load i64, ptr %15, align 8, !tbaa !16
  %17 = add i64 %16, %13
  store i64 %17, ptr %15, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.actorref_t, ptr %18, i32 0, i32 3
  store ptr %19, 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
  br label %20

20:                                               ; preds = %51, %2
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = call ptr @ponyint_objectmap_next(ptr noundef %21, ptr noundef %7)
  store ptr %22, ptr %8, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %52

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.gc_t, ptr %25, i32 0, i32 3
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.object_t, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !19
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.object_t, ptr %30, i32 0, i32 4
  %32 = load ptr, ptr %31, align 8, !tbaa !22
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.gc_t, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !23
  %36 = call ptr @ponyint_objectmap_getorput(ptr noundef %26, ptr noundef %29, ptr noundef %32, i32 noundef %35)
  store ptr %36, ptr %9, align 8, !tbaa !5
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.object_t, ptr %37, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !24
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.object_t, ptr %40, i32 0, i32 1
  %42 = load i64, ptr %41, align 8, !tbaa !24
  %43 = add i64 %42, %39
  store i64 %43, ptr %41, align 8, !tbaa !24
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.object_t, ptr %44, i32 0, i32 3
  %46 = load i8, ptr %45, align 4, !tbaa !25, !range !26, !noundef !27
  %47 = trunc i8 %46 to i1
  br i1 %47, label %48, label %51

48:                                               ; preds = %24
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.object_t, ptr %49, i32 0, i32 3
  store i8 1, ptr %50, align 4, !tbaa !25
  br label %51

51:                                               ; preds = %48, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %20, !llvm.loop !28

52:                                               ; preds = %20
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ponyint_actorref_free(ptr noundef %53)
  %54 = load i64, ptr %5, align 8, !tbaa !15
  %55 = icmp ugt i64 %54, 0
  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 %55
}

declare ptr @ponyint_objectmap_getorput(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

declare void @ponyint_actorref_free(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, !6, i64 24}
!23 = !{!17, !12, i64 0}
!24 = !{!20, !11, i64 8}
!25 = !{!20, !21, i64 20}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = distinct !{!28, !29}
!29 = !{!"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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @ponyint_gc_acquire(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca i64, align 8
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !14
  %8 = add i64 %7, %5
  store i64 %8, ptr %6, align 8, !tbaa !14
  %9 = 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
  %10 = call ptr @ponyint_objectmap_next(ptr noundef nonnull %9, ptr noundef nonnull %3) #3
  %.not14 = icmp eq ptr %10, null
  br i1 %.not14, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  br label %12

12:                                               ; preds = %.lr.ph, %29
  %13 = phi ptr [ %10, %.lr.ph ], [ %30, %29 ]
  %14 = load ptr, ptr %13, align 8, !tbaa !18
  %15 = getelementptr inbounds i8, ptr %13, i64 24
  %16 = load ptr, ptr %15, align 8, !tbaa !21
  %17 = load i32, ptr %0, align 8, !tbaa !22
  %18 = call ptr @ponyint_objectmap_getorput(ptr noundef nonnull %11, ptr noundef %14, ptr noundef %16, i32 noundef %17) #3
  %19 = getelementptr inbounds i8, ptr %13, i64 8
  %20 = load i64, ptr %19, align 8, !tbaa !23
  %21 = getelementptr inbounds i8, ptr %18, i64 8
  %22 = load i64, ptr %21, align 8, !tbaa !23
  %23 = add i64 %22, %20
  store i64 %23, ptr %21, align 8, !tbaa !23
  %24 = getelementptr inbounds i8, ptr %13, i64 20
  %25 = load i8, ptr %24, align 4, !tbaa !24, !range !25, !noundef !26
  %26 = trunc nuw i8 %25 to i1
  br i1 %26, label %27, label %29

27:                                               ; preds = %12
  %28 = getelementptr inbounds i8, ptr %18, i64 20
  store i8 1, ptr %28, align 4, !tbaa !24
  br label %29

29:                                               ; preds = %27, %12
  %30 = call ptr @ponyint_objectmap_next(ptr noundef nonnull %9, ptr noundef nonnull %3) #3
  %.not = icmp eq ptr %30, null
  br i1 %.not, label %._crit_edge, label %12, !llvm.loop !27

._crit_edge:                                      ; preds = %29, %2
  call void @ponyint_actorref_free(ptr noundef %1) #3
  %31 = icmp ne i64 %5, 0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret i1 %31
}

declare ptr @ponyint_objectmap_getorput(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @ponyint_actorref_free(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, !7, i64 24}
!22 = !{!15, !11, i64 0}
!23 = !{!19, !10, i64 8}
!24 = !{!19, !20, i64 20}
!25 = !{i8 0, i8 2}
!26 = !{}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}


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