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

; 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.pony_actor_t = type { ptr, %struct.messageq_t, i8, [39 x i8], %struct.heap_t, i64, i8, i32, %struct.gc_t, [16 x i8] }
%struct.messageq_t = type { ptr, ptr }
%struct.heap_t = type { [5 x ptr], [5 x ptr], ptr, [4 x ptr], i64, i64 }
%struct.gc_t = type { i32, i32, i64, %struct.objectmap_t, %struct.actormap_t, ptr }
%struct.objectmap_t = type { %struct.hashmap_t }
%struct.hashmap_t = type { i64, i64, ptr, ptr }
%struct.actormap_t = type { %struct.hashmap_t }
%struct.block_msg_t = type { %struct.pony_msg_t, ptr, i64, i32, ptr }
%struct.pony_msg_t = type { i32, i32, ptr }

@cycle_detector = external hidden global ptr, align 8
@.str = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [73 x i8], align 1
@__func__.ponyint_cycle_block = external hidden unnamed_addr constant [20 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [18 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 void @ponyint_cycle_block(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.pony_actor_t, ptr %6, i32 0, i32 8
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp eq ptr %7, %8
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  br label %12

11:                                               ; preds = %2
  call void @ponyint_assert_fail(ptr noundef @.str, ptr noundef @.str.1, i64 noundef 1262, ptr noundef @__func__.ponyint_cycle_block)
  br label %12

12:                                               ; preds = %11, %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %13 = call ptr @pony_alloc_msg(i32 noundef 1, i32 noundef -7)
  store ptr %13, ptr %5, align 8, !tbaa !5
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.block_msg_t, ptr %15, i32 0, i32 1
  store ptr %14, ptr %16, align 8, !tbaa !9
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call i64 @ponyint_gc_rc(ptr noundef %17)
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.block_msg_t, ptr %19, i32 0, i32 2
  store i64 %18, ptr %20, align 8, !tbaa !14
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.pony_actor_t, ptr %21, i32 0, i32 7
  %23 = load i32, ptr %22, align 4, !tbaa !15
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.block_msg_t, ptr %24, i32 0, i32 3
  store i32 %23, ptr %25, align 8, !tbaa !23
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = call ptr @ponyint_gc_delta(ptr noundef %26)
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.block_msg_t, ptr %28, i32 0, i32 4
  store ptr %27, ptr %29, align 8, !tbaa !24
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.gc_t, ptr %30, i32 0, i32 5
  %32 = load ptr, ptr %31, align 8, !tbaa !25
  %33 = icmp eq ptr %32, null
  br i1 %33, label %34, label %35

34:                                               ; preds = %12
  br label %36

35:                                               ; preds = %12
  call void @ponyint_assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i64 noundef 1271, ptr noundef @__func__.ponyint_cycle_block)
  br label %36

36:                                               ; preds = %35, %34
  %37 = load ptr, ptr @cycle_detector, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.block_msg_t, ptr %38, i32 0, i32 0
  call void @ponyint_sendv_inject(ptr noundef %37, ptr noundef %39)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

declare ptr @pony_alloc_msg(i32 noundef, i32 noundef) #2

declare i64 @ponyint_gc_rc(ptr noundef) #2

declare ptr @ponyint_gc_delta(ptr noundef) #2

declare void @ponyint_sendv_inject(ptr noundef, ptr noundef) #2

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, !6, i64 16}
!10 = !{!"block_msg_t", !11, i64 0, !6, i64 16, !13, i64 24, !12, i64 32, !6, i64 40}
!11 = !{!"pony_msg_t", !12, i64 0, !12, i64 4, !7, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !13, i64 24}
!15 = !{!16, !12, i64 212}
!16 = !{!"pony_actor_t", !6, i64 0, !17, i64 8, !7, i64 24, !18, i64 64, !13, i64 200, !7, i64 208, !12, i64 212, !19, i64 216}
!17 = !{!"messageq_t", !7, i64 0, !6, i64 8}
!18 = !{!"heap_t", !7, i64 0, !7, i64 40, !6, i64 80, !7, i64 88, !13, i64 120, !13, i64 128}
!19 = !{!"gc_t", !12, i64 0, !12, i64 4, !13, i64 8, !20, i64 16, !22, i64 48, !6, i64 80}
!20 = !{!"objectmap_t", !21, i64 0}
!21 = !{!"hashmap_t", !13, i64 0, !13, i64 8, !6, i64 16, !6, i64 24}
!22 = !{!"actormap_t", !21, i64 0}
!23 = !{!10, !12, i64 32}
!24 = !{!10, !6, i64 40}
!25 = !{!19, !6, i64 80}


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

@cycle_detector = external hidden local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [73 x i8], align 1
@__func__.ponyint_cycle_block = external hidden unnamed_addr constant [20 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @ponyint_cycle_block(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 216
  %4 = icmp eq ptr %3, %1
  br i1 %4, label %6, label %5

5:                                                ; preds = %2
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i64 noundef 1262, ptr noundef nonnull @__func__.ponyint_cycle_block) #2
  br label %6

6:                                                ; preds = %2, %5
  %7 = tail call ptr @pony_alloc_msg(i32 noundef 1, i32 noundef -7) #2
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  store ptr %0, ptr %8, align 8, !tbaa !5
  %9 = tail call i64 @ponyint_gc_rc(ptr noundef %1) #2
  %10 = getelementptr inbounds i8, ptr %7, i64 24
  store i64 %9, ptr %10, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %0, i64 212
  %12 = load i32, ptr %11, align 4, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %7, i64 32
  store i32 %12, ptr %13, align 8, !tbaa !22
  %14 = tail call ptr @ponyint_gc_delta(ptr noundef %1) #2
  %15 = getelementptr inbounds i8, ptr %7, i64 40
  store ptr %14, ptr %15, align 8, !tbaa !23
  %16 = getelementptr inbounds i8, ptr %1, i64 80
  %17 = load ptr, ptr %16, align 8, !tbaa !24
  %18 = icmp eq ptr %17, null
  br i1 %18, label %20, label %19

19:                                               ; preds = %6
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i64 noundef 1271, ptr noundef nonnull @__func__.ponyint_cycle_block) #2
  br label %20

20:                                               ; preds = %6, %19
  %21 = load ptr, ptr @cycle_detector, align 8, !tbaa !25
  tail call void @ponyint_sendv_inject(ptr noundef %21, ptr noundef nonnull %7) #2
  ret void
}

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

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

declare i64 @ponyint_gc_rc(ptr noundef) local_unnamed_addr #1

declare ptr @ponyint_gc_delta(ptr noundef) local_unnamed_addr #1

declare void @ponyint_sendv_inject(ptr noundef, ptr noundef) local_unnamed_addr #1

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 = { 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, !11, i64 16}
!6 = !{!"block_msg_t", !7, i64 0, !11, i64 16, !12, i64 24, !8, i64 32, !11, i64 40}
!7 = !{!"pony_msg_t", !8, i64 0, !8, i64 4, !9, i64 8}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"long", !9, i64 0}
!13 = !{!6, !12, i64 24}
!14 = !{!15, !8, i64 212}
!15 = !{!"pony_actor_t", !11, i64 0, !16, i64 8, !9, i64 24, !17, i64 64, !12, i64 200, !9, i64 208, !8, i64 212, !18, i64 216}
!16 = !{!"messageq_t", !9, i64 0, !11, i64 8}
!17 = !{!"heap_t", !9, i64 0, !9, i64 40, !11, i64 80, !9, i64 88, !12, i64 120, !12, i64 128}
!18 = !{!"gc_t", !8, i64 0, !8, i64 4, !12, i64 8, !19, i64 16, !21, i64 48, !11, i64 80}
!19 = !{!"objectmap_t", !20, i64 0}
!20 = !{!"hashmap_t", !12, i64 0, !12, i64 8, !11, i64 16, !11, i64 24}
!21 = !{!"actormap_t", !20, i64 0}
!22 = !{!6, !8, i64 32}
!23 = !{!6, !11, i64 40}
!24 = !{!18, !11, i64 80}
!25 = !{!11, !11, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass