; 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_type_t = type { i32, i32, i64, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i8, ptr, ptr, ptr }
%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_ctx_t = type { ptr, ptr, ptr, ptr, ptr, %struct.actormap_t, ptr, i64, %struct.ponyint_serialise_t, ptr, ptr, ptr }
%struct.ponyint_serialise_t = type { %struct.hashmap_t }

@.str.1 = external hidden unnamed_addr constant [76 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [13 x i8], align 1
@__func__.pony_create = external hidden unnamed_addr constant [12 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local noalias ptr @pony_create(ptr noundef %0, ptr noundef %1, i1 noundef zeroext %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = zext i1 %2 to i8
  store i8 %8, ptr %6, align 1, !tbaa !9
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %3
  br label %13

12:                                               ; preds = %3
  call void @ponyint_assert_fail(ptr noundef @.str.6, ptr noundef @.str.1, i64 noundef 860, ptr noundef @__func__.pony_create)
  br label %13

13:                                               ; preds = %12, %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._pony_type_t, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = zext i32 %16 to i64
  %18 = call noalias ptr @ponyint_pool_alloc_size(i64 noundef %17)
  store ptr %18, ptr %7, align 8, !tbaa !5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._pony_type_t, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = zext i32 %22 to i64
  call void @llvm.memset.p0.i64(ptr align 64 %19, i8 0, i64 %23, i1 false)
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.pony_actor_t, ptr %25, i32 0, i32 0
  store ptr %24, ptr %26, align 64, !tbaa !15
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.pony_actor_t, ptr %27, i32 0, i32 1
  call void @ponyint_messageq_init(ptr noundef %28)
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.pony_actor_t, ptr %29, i32 0, i32 4
  call void @ponyint_heap_init(ptr noundef %30)
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.pony_actor_t, ptr %31, i32 0, i32 8
  call void @ponyint_gc_done(ptr noundef %32)
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.pony_ctx_t, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !23
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %48

37:                                               ; preds = %13
  %38 = load i8, ptr %6, align 1, !tbaa !9, !range !26, !noundef !27
  %39 = trunc i8 %38 to i1
  br i1 %39, label %48, label %40

40:                                               ; preds = %37
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.pony_actor_t, ptr %41, i32 0, i32 8
  %43 = getelementptr inbounds %struct.gc_t, ptr %42, i32 0, i32 2
  store i64 256, ptr %43, align 8, !tbaa !28
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.pony_ctx_t, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !23
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ponyint_gc_createactor(ptr noundef %46, ptr noundef %47)
  br label %52

48:                                               ; preds = %37, %13
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.pony_actor_t, ptr %49, i32 0, i32 8
  %51 = getelementptr inbounds %struct.gc_t, ptr %50, i32 0, i32 2
  store i64 0, ptr %51, align 8, !tbaa !28
  br label %52

52:                                               ; preds = %48, %40
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53
  br label %55

55:                                               ; preds = %54
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret ptr %56
}

declare noalias ptr @ponyint_pool_alloc_size(i64 noundef) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

declare void @ponyint_messageq_init(ptr noundef) #0

declare void @ponyint_heap_init(ptr noundef) #0

declare void @ponyint_gc_done(ptr noundef) #0

declare void @ponyint_gc_createactor(ptr noundef, ptr noundef) #0

attributes #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !13, i64 4}
!12 = !{!"_pony_type_t", !13, i64 0, !13, i64 4, !14, i64 8, !13, i64 16, !13, 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, !13, i64 96, !10, i64 100, !6, i64 104, !6, i64 112, !6, i64 120}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"pony_actor_t", !6, i64 0, !17, i64 8, !7, i64 24, !18, i64 64, !14, i64 200, !7, i64 208, !13, 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, !14, i64 120, !14, i64 128}
!19 = !{!"gc_t", !13, i64 0, !13, i64 4, !14, i64 8, !20, i64 16, !22, i64 48, !6, i64 80}
!20 = !{!"objectmap_t", !21, i64 0}
!21 = !{!"hashmap_t", !14, i64 0, !14, i64 8, !6, i64 16, !6, i64 24}
!22 = !{!"actormap_t", !21, i64 0}
!23 = !{!24, !6, i64 8}
!24 = !{!"pony_ctx_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !22, i64 40, !6, i64 72, !14, i64 80, !25, i64 88, !6, i64 120, !6, i64 128, !6, i64 136}
!25 = !{!"ponyint_serialise_t", !21, i64 0}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = !{!16, !14, i64 224}


; 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.6 = external hidden unnamed_addr constant [13 x i8], align 1
@__func__.pony_create = external hidden unnamed_addr constant [12 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @pony_create(ptr nocapture noundef readonly %0, ptr noundef %1, i1 noundef zeroext %2) local_unnamed_addr #1 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %4, label %5

4:                                                ; preds = %3
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.1, i64 noundef 860, ptr noundef nonnull @__func__.pony_create) #3
  br label %5

5:                                                ; preds = %3, %4
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = zext i32 %7 to i64
  %9 = tail call noalias ptr @ponyint_pool_alloc_size(i64 noundef %8) #3
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = zext i32 %10 to i64
  tail call void @llvm.memset.p0.i64(ptr align 64 %9, i8 0, i64 %11, i1 false)
  store ptr %1, ptr %9, align 64, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %9, i64 8
  tail call void @ponyint_messageq_init(ptr noundef nonnull %12) #3
  %13 = getelementptr inbounds i8, ptr %9, i64 64
  tail call void @ponyint_heap_init(ptr noundef nonnull %13) #3
  %14 = getelementptr inbounds i8, ptr %9, i64 216
  tail call void @ponyint_gc_done(ptr noundef nonnull %14) #3
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !21
  %.not15 = icmp eq ptr %16, null
  %brmerge = or i1 %.not15, %2
  %17 = getelementptr inbounds i8, ptr %9, i64 224
  br i1 %brmerge, label %19, label %18

18:                                               ; preds = %5
  store i64 256, ptr %17, align 8, !tbaa !24
  tail call void @ponyint_gc_createactor(ptr noundef nonnull %16, ptr noundef nonnull %9) #3
  br label %20

19:                                               ; preds = %5
  store i64 0, ptr %17, align 8, !tbaa !24
  br label %20

20:                                               ; preds = %18, %19
  ret ptr %9
}

declare noalias ptr @ponyint_pool_alloc_size(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare void @ponyint_messageq_init(ptr noundef) local_unnamed_addr #0

declare void @ponyint_heap_init(ptr noundef) local_unnamed_addr #0

declare void @ponyint_gc_done(ptr noundef) local_unnamed_addr #0

declare void @ponyint_gc_createactor(ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 4}
!6 = !{!"_pony_type_t", !7, i64 0, !7, i64 4, !10, i64 8, !7, i64 16, !7, i64 20, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !7, i64 96, !12, i64 100, !11, i64 104, !11, i64 112, !11, i64 120}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!14, !11, i64 0}
!14 = !{!"pony_actor_t", !11, i64 0, !15, i64 8, !8, i64 24, !16, i64 64, !10, i64 200, !8, i64 208, !7, i64 212, !17, i64 216}
!15 = !{!"messageq_t", !8, i64 0, !11, i64 8}
!16 = !{!"heap_t", !8, i64 0, !8, i64 40, !11, i64 80, !8, i64 88, !10, i64 120, !10, i64 128}
!17 = !{!"gc_t", !7, i64 0, !7, i64 4, !10, i64 8, !18, i64 16, !20, i64 48, !11, i64 80}
!18 = !{!"objectmap_t", !19, i64 0}
!19 = !{!"hashmap_t", !10, i64 0, !10, i64 8, !11, i64 16, !11, i64 24}
!20 = !{!"actormap_t", !19, i64 0}
!21 = !{!22, !11, i64 8}
!22 = !{!"pony_ctx_t", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !20, i64 40, !11, i64 72, !10, i64 80, !23, i64 88, !11, i64 120, !11, i64 128, !11, i64 136}
!23 = !{!"ponyint_serialise_t", !19, i64 0}
!24 = !{!14, !10, i64 224}


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