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

; 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._pony_type_t = type { i32, i32, i64, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i8, ptr, ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [76 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [53 x i8], align 1
@__func__.ponyint_actor_destroy = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @has_sync_flag(ptr noundef, i8 noundef zeroext) #0

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nounwind uwtable
define dso_local void @ponyint_actor_destroy(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = call zeroext i1 @has_sync_flag(ptr noundef %7, i8 noundef zeroext 1)
  br i1 %8, label %9, label %10

9:                                                ; preds = %2
  br label %11

10:                                               ; preds = %2
  call void @ponyint_assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i64 noundef 757, ptr noundef @__func__.ponyint_actor_destroy)
  br label %11

11:                                               ; preds = %10, %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr null, ptr %5, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %18, %11
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.pony_actor_t, ptr %13, i32 0, i32 1
  %15 = getelementptr inbounds %struct.messageq_t, ptr %14, i32 0, i32 0
  %16 = load atomic i64, ptr %15 monotonic, align 8
  store i64 %16, ptr %6, align 8
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %17, ptr %5, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %12
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = ptrtoint ptr %19 to i64
  %21 = and i64 %20, 1
  %22 = icmp ne i64 %21, 1
  br i1 %22, label %12, label %23, !llvm.loop !11

23:                                               ; preds = %18
  fence acquire
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.pony_actor_t, ptr %24, i32 0, i32 1
  call void @ponyint_messageq_destroy(ptr noundef %25, i1 noundef zeroext false)
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.pony_actor_t, ptr %26, i32 0, i32 8
  call void @ponyint_gc_destroy(ptr noundef %27)
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.pony_actor_t, ptr %28, i32 0, i32 4
  call void @ponyint_heap_destroy(ptr noundef %29)
  %30 = load i32, ptr %4, align 4, !tbaa !9
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.pony_actor_t, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 64, !tbaa !13
  %34 = getelementptr inbounds %struct._pony_type_t, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !22
  %36 = zext i32 %35 to i64
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  call void @ponyint_pool_free_size(i64 noundef %36, ptr noundef %37)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

declare void @ponyint_messageq_destroy(ptr noundef, i1 noundef zeroext) #1

declare void @ponyint_gc_destroy(ptr noundef) #1

declare void @ponyint_heap_destroy(ptr noundef) #1

declare void @ponyint_pool_free_size(i64 noundef, ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !6, i64 0}
!14 = !{!"pony_actor_t", !6, i64 0, !15, i64 8, !7, i64 24, !16, i64 64, !17, i64 200, !7, i64 208, !10, i64 212, !18, i64 216}
!15 = !{!"messageq_t", !7, i64 0, !6, i64 8}
!16 = !{!"heap_t", !7, i64 0, !7, i64 40, !6, i64 80, !7, i64 88, !17, i64 120, !17, i64 128}
!17 = !{!"long", !7, i64 0}
!18 = !{!"gc_t", !10, i64 0, !10, i64 4, !17, i64 8, !19, i64 16, !21, i64 48, !6, i64 80}
!19 = !{!"objectmap_t", !20, i64 0}
!20 = !{!"hashmap_t", !17, i64 0, !17, i64 8, !6, i64 16, !6, i64 24}
!21 = !{!"actormap_t", !20, i64 0}
!22 = !{!23, !10, i64 4}
!23 = !{!"_pony_type_t", !10, i64 0, !10, i64 4, !17, i64 8, !10, i64 16, !10, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !10, i64 96, !24, i64 100, !6, i64 104, !6, i64 112, !6, i64 120}
!24 = !{!"_Bool", !7, i64 0}


; 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.1 = external hidden unnamed_addr constant [76 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [53 x i8], align 1
@__func__.ponyint_actor_destroy = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @has_sync_flag(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @ponyint_actor_destroy(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call zeroext i1 @has_sync_flag(ptr noundef %0, i8 noundef zeroext 1)
  br i1 %3, label %5, label %4

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

5:                                                ; preds = %2, %4
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  br label %7

7:                                                ; preds = %7, %5
  %8 = load atomic i64, ptr %6 monotonic, align 8
  %9 = and i64 %8, 1
  %.not.not = icmp eq i64 %9, 0
  br i1 %.not.not, label %7, label %10, !llvm.loop !5

10:                                               ; preds = %7
  fence acquire
  tail call void @ponyint_messageq_destroy(ptr noundef nonnull %6, i1 noundef zeroext false) #2
  %11 = getelementptr inbounds i8, ptr %0, i64 216
  tail call void @ponyint_gc_destroy(ptr noundef nonnull %11) #2
  %12 = getelementptr inbounds i8, ptr %0, i64 64
  tail call void @ponyint_heap_destroy(ptr noundef nonnull %12) #2
  %13 = load ptr, ptr %0, align 64, !tbaa !7
  %14 = getelementptr inbounds i8, ptr %13, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !20
  %16 = zext i32 %15 to i64
  tail call void @ponyint_pool_free_size(i64 noundef %16, ptr noundef nonnull %0) #2
  ret void
}

declare void @ponyint_messageq_destroy(ptr noundef, i1 noundef zeroext) local_unnamed_addr #1

declare void @ponyint_gc_destroy(ptr noundef) local_unnamed_addr #1

declare void @ponyint_heap_destroy(ptr noundef) local_unnamed_addr #1

declare void @ponyint_pool_free_size(i64 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !9, i64 0}
!8 = !{!"pony_actor_t", !9, i64 0, !12, i64 8, !10, i64 24, !13, i64 64, !14, i64 200, !10, i64 208, !15, i64 212, !16, i64 216}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"messageq_t", !10, i64 0, !9, i64 8}
!13 = !{!"heap_t", !10, i64 0, !10, i64 40, !9, i64 80, !10, i64 88, !14, i64 120, !14, i64 128}
!14 = !{!"long", !10, i64 0}
!15 = !{!"int", !10, i64 0}
!16 = !{!"gc_t", !15, i64 0, !15, i64 4, !14, i64 8, !17, i64 16, !19, i64 48, !9, i64 80}
!17 = !{!"objectmap_t", !18, i64 0}
!18 = !{!"hashmap_t", !14, i64 0, !14, i64 8, !9, i64 16, !9, i64 24}
!19 = !{!"actormap_t", !18, i64 0}
!20 = !{!21, !15, i64 4}
!21 = !{!"_pony_type_t", !15, i64 0, !15, i64 4, !14, i64 8, !15, i64 16, !15, i64 20, !9, i64 24, !9, i64 32, !9, i64 40, !9, i64 48, !9, i64 56, !9, i64 64, !9, i64 72, !9, i64 80, !9, i64 88, !15, i64 96, !22, i64 100, !9, i64 104, !9, i64 112, !9, i64 120}
!22 = !{!"_Bool", !10, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,SROAPass,SimplifyCFGPass,TailCallElimPass