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

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

; 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
declare dso_local ptr @ponyint_serialise_get(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @ponyint_serialise_putindex(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @ponyint_serialise_object(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca %struct.serialise_t, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = ptrtoint ptr %13 to i64
  %15 = getelementptr inbounds %struct.serialise_t, ptr %9, i32 0, i32 0
  store i64 %14, ptr %15, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 -1, ptr %10, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.pony_ctx_t, ptr %16, i32 0, i32 8
  %18 = call ptr @ponyint_serialise_get(ptr noundef %17, ptr noundef %9, ptr noundef %10)
  store ptr %18, ptr %11, align 8, !tbaa !5
  %19 = load ptr, ptr %11, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %31

21:                                               ; preds = %4
  %22 = load ptr, ptr %11, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.serialise_t, ptr %22, i32 0, i32 3
  %24 = load i32, ptr %23, align 8, !tbaa !16
  %25 = icmp ne i32 %24, 2
  br i1 %25, label %29, label %26

26:                                               ; preds = %21
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = icmp eq i32 %27, 2
  br i1 %28, label %29, label %30

29:                                               ; preds = %26, %21
  store i32 1, ptr %12, align 4
  br label %87

30:                                               ; preds = %26
  br label %74

31:                                               ; preds = %4
  %32 = call noalias ptr @ponyint_pool_alloc(i64 noundef 0)
  store ptr %32, ptr %11, align 8, !tbaa !5
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = ptrtoint ptr %33 to i64
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.serialise_t, ptr %35, i32 0, i32 0
  store i64 %34, ptr %36, align 8, !tbaa !11
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.pony_ctx_t, ptr %37, i32 0, i32 7
  %39 = load i64, ptr %38, align 8, !tbaa !17
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.serialise_t, ptr %40, i32 0, i32 1
  store i64 %39, ptr %41, align 8, !tbaa !22
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.serialise_t, ptr %43, i32 0, i32 2
  store ptr %42, ptr %44, align 8, !tbaa !23
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.serialise_t, ptr %45, i32 0, i32 4
  store i8 0, ptr %46, align 4, !tbaa !24
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.pony_ctx_t, ptr %47, i32 0, i32 8
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = load i64, ptr %10, align 8, !tbaa !15
  call void @ponyint_serialise_putindex(ptr noundef %48, ptr noundef %49, i64 noundef %50)
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._pony_type_t, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !25
  %54 = zext i32 %53 to i64
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.pony_ctx_t, ptr %55, i32 0, i32 7
  %57 = load i64, ptr %56, align 8, !tbaa !17
  %58 = add i64 %57, %54
  store i64 %58, ptr %56, align 8, !tbaa !17
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._pony_type_t, ptr %59, i32 0, i32 10
  %61 = load ptr, ptr %60, align 8, !tbaa !27
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %73

63:                                               ; preds = %31
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._pony_type_t, ptr %64, i32 0, i32 10
  %66 = load ptr, ptr %65, align 8, !tbaa !27
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = call i64 %66(ptr noundef %67)
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.pony_ctx_t, ptr %69, i32 0, i32 7
  %71 = load i64, ptr %70, align 8, !tbaa !17
  %72 = add i64 %71, %68
  store i64 %72, ptr %70, align 8, !tbaa !17
  br label %73

73:                                               ; preds = %63, %31
  br label %74

74:                                               ; preds = %73, %30
  %75 = load i32, ptr %8, align 4, !tbaa !9
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.serialise_t, ptr %76, i32 0, i32 3
  store i32 %75, ptr %77, align 8, !tbaa !16
  %78 = load i32, ptr %8, align 4, !tbaa !9
  %79 = icmp ne i32 %78, 2
  br i1 %79, label %80, label %86

80:                                               ; preds = %74
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct._pony_type_t, ptr %83, i32 0, i32 7
  %85 = load ptr, ptr %84, align 8, !tbaa !28
  call void @recurse(ptr noundef %81, ptr noundef %82, ptr noundef %85)
  br label %86

86:                                               ; preds = %80, %74
  store i32 0, ptr %12, align 4
  br label %87

87:                                               ; preds = %86, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #3
  %88 = load i32, ptr %12, align 4
  switch i32 %88, label %90 [
    i32 0, label %89
    i32 1, label %89
  ]

89:                                               ; preds = %87, %87
  ret void

90:                                               ; preds = %87
  unreachable
}

declare noalias ptr @ponyint_pool_alloc(i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @recurse(ptr noundef, ptr noundef, ptr noundef) #1

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"serialise_t", !13, i64 0, !13, i64 8, !6, i64 16, !10, i64 24, !14, i64 28}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{!12, !10, i64 24}
!17 = !{!18, !13, i64 80}
!18 = !{!"pony_ctx_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !19, i64 40, !6, i64 72, !13, i64 80, !21, i64 88, !6, i64 120, !6, i64 128, !6, i64 136}
!19 = !{!"actormap_t", !20, i64 0}
!20 = !{!"hashmap_t", !13, i64 0, !13, i64 8, !6, i64 16, !6, i64 24}
!21 = !{!"ponyint_serialise_t", !20, i64 0}
!22 = !{!12, !13, i64 8}
!23 = !{!12, !6, i64 16}
!24 = !{!12, !14, i64 28}
!25 = !{!26, !10, i64 4}
!26 = !{!"_pony_type_t", !10, i64 0, !10, i64 4, !13, 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, !14, i64 100, !6, i64 104, !6, i64 112, !6, i64 120}
!27 = !{!26, !6, i64 64}
!28 = !{!26, !6, i64 40}


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

%struct.serialise_t = type { i64, i64, ptr, i32, i8 }

; 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

; Function Attrs: nounwind uwtable
declare dso_local ptr @ponyint_serialise_get(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @ponyint_serialise_putindex(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @ponyint_serialise_object(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca %struct.serialise_t, align 8
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #3
  %7 = ptrtoint ptr %1 to i64
  store i64 %7, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  store i64 -1, ptr %6, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %0, i64 88
  %9 = call ptr @ponyint_serialise_get(ptr noundef nonnull %8, ptr noundef nonnull %5, ptr noundef nonnull %6)
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %15, label %10

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %9, i64 24
  %12 = load i32, ptr %11, align 8, !tbaa !14
  %13 = icmp ne i32 %12, 2
  %14 = icmp eq i32 %3, 2
  %or.cond = or i1 %14, %13
  br i1 %or.cond, label %39, label %.thread

.thread:                                          ; preds = %10
  store i32 %3, ptr %11, align 8, !tbaa !14
  br label %36

15:                                               ; preds = %4
  %16 = call noalias ptr @ponyint_pool_alloc(i64 noundef 0) #3
  store i64 %7, ptr %16, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 80
  %18 = load i64, ptr %17, align 8, !tbaa !15
  %19 = getelementptr inbounds i8, ptr %16, i64 8
  store i64 %18, ptr %19, align 8, !tbaa !20
  %20 = getelementptr inbounds i8, ptr %16, i64 16
  store ptr %2, ptr %20, align 8, !tbaa !21
  %21 = getelementptr inbounds i8, ptr %16, i64 28
  store i8 0, ptr %21, align 4, !tbaa !22
  %22 = load i64, ptr %6, align 8, !tbaa !13
  call void @ponyint_serialise_putindex(ptr noundef nonnull %8, ptr noundef nonnull %16, i64 noundef %22)
  %23 = getelementptr inbounds i8, ptr %2, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !23
  %25 = zext i32 %24 to i64
  %26 = load i64, ptr %17, align 8, !tbaa !15
  %27 = add i64 %26, %25
  store i64 %27, ptr %17, align 8, !tbaa !15
  %28 = getelementptr inbounds i8, ptr %2, i64 64
  %29 = load ptr, ptr %28, align 8, !tbaa !25
  %.not28 = icmp eq ptr %29, null
  br i1 %.not28, label %34, label %30

30:                                               ; preds = %15
  %31 = call i64 %29(ptr noundef %1) #3
  %32 = load i64, ptr %17, align 8, !tbaa !15
  %33 = add i64 %32, %31
  store i64 %33, ptr %17, align 8, !tbaa !15
  br label %34

34:                                               ; preds = %15, %30
  %35 = getelementptr inbounds i8, ptr %16, i64 24
  store i32 %3, ptr %35, align 8, !tbaa !14
  %.not29 = icmp eq i32 %3, 2
  br i1 %.not29, label %39, label %36

36:                                               ; preds = %.thread, %34
  %37 = getelementptr inbounds i8, ptr %2, i64 40
  %38 = load ptr, ptr %37, align 8, !tbaa !26
  call void @recurse(ptr noundef %0, ptr noundef %1, ptr noundef %38)
  br label %39

39:                                               ; preds = %34, %36, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #3
  ret void
}

declare noalias ptr @ponyint_pool_alloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @recurse(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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, !7, i64 0}
!6 = !{!"serialise_t", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24, !12, i64 28}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!6, !11, i64 24}
!15 = !{!16, !7, i64 80}
!16 = !{!"pony_ctx_t", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !17, i64 40, !10, i64 72, !7, i64 80, !19, i64 88, !10, i64 120, !10, i64 128, !10, i64 136}
!17 = !{!"actormap_t", !18, i64 0}
!18 = !{!"hashmap_t", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24}
!19 = !{!"ponyint_serialise_t", !18, i64 0}
!20 = !{!6, !7, i64 8}
!21 = !{!6, !10, i64 16}
!22 = !{!6, !12, i64 28}
!23 = !{!24, !11, i64 4}
!24 = !{!"_pony_type_t", !11, i64 0, !11, i64 4, !7, i64 8, !11, i64 16, !11, i64 20, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !11, i64 96, !12, i64 100, !10, i64 104, !10, i64 112, !10, i64 120}
!25 = !{!24, !10, i64 64}
!26 = !{!24, !10, i64 40}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass