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

; 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

declare noalias ptr @ponyint_pool_alloc(i64 noundef) #2

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

; Function Attrs: noreturn nounwind
declare void @abort() #3

; Function Attrs: nounwind uwtable
define dso_local ptr @pony_deserialise_raw(ptr noundef %0, i64 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.serialise_t, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = icmp eq i64 %13, -1
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  br label %68

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #4
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.serialise_t, ptr %8, i32 0, i32 0
  store i64 %17, ptr %18, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 -1, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.pony_ctx_t, ptr %19, i32 0, i32 8
  %21 = call ptr @ponyint_serialise_get(ptr noundef %20, ptr noundef %8, ptr noundef %9)
  store ptr %21, ptr %10, align 8, !tbaa !5
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %29

24:                                               ; preds = %16
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.serialise_t, ptr %25, i32 0, i32 1
  %27 = load i64, ptr %26, align 8, !tbaa !15
  %28 = inttoptr i64 %27 to ptr
  store ptr %28, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %67

29:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.pony_ctx_t, ptr %31, i32 0, i32 6
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  %34 = ptrtoint ptr %33 to i64
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = add i64 %34, %35
  %37 = inttoptr i64 %36 to ptr
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.pony_ctx_t, ptr %38, i32 0, i32 7
  %40 = load i64, ptr %39, align 8, !tbaa !21
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = sub i64 %40, %41
  %43 = call ptr %30(ptr noundef %37, i64 noundef %42)
  store ptr %43, ptr %12, align 8, !tbaa !5
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  %45 = icmp eq ptr %44, null
  br i1 %45, label %46, label %51

46:                                               ; preds = %29
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  call void @serialise_cleanup(ptr noundef %47)
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.pony_ctx_t, ptr %48, i32 0, i32 11
  %50 = load ptr, ptr %49, align 8, !tbaa !22
  call void (...) %50()
  call void @abort() #5
  unreachable

51:                                               ; preds = %29
  %52 = call noalias ptr @ponyint_pool_alloc(i64 noundef 0)
  store ptr %52, ptr %10, align 8, !tbaa !5
  %53 = load i64, ptr %6, align 8, !tbaa !9
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.serialise_t, ptr %54, i32 0, i32 0
  store i64 %53, ptr %55, align 8, !tbaa !11
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = ptrtoint ptr %56 to i64
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.serialise_t, ptr %58, i32 0, i32 1
  store i64 %57, ptr %59, align 8, !tbaa !15
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.serialise_t, ptr %60, i32 0, i32 2
  store ptr null, ptr %61, align 8, !tbaa !23
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.pony_ctx_t, ptr %62, i32 0, i32 8
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = load i64, ptr %9, align 8, !tbaa !9
  call void @ponyint_serialise_putindex(ptr noundef %63, ptr noundef %64, i64 noundef %65)
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %66, ptr %4, align 8
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %67

67:                                               ; preds = %51, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #4
  br label %68

68:                                               ; preds = %67, %15
  %69 = load ptr, ptr %4, align 8
  ret ptr %69
}

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 = { noreturn nounwind "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 #4 = { nounwind }
attributes #5 = { noreturn 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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"serialise_t", !10, i64 0, !10, i64 8, !6, i64 16, !13, i64 24, !14, i64 28}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!12, !10, i64 8}
!16 = !{!17, !6, i64 72}
!17 = !{!"pony_ctx_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !18, i64 40, !6, i64 72, !10, i64 80, !20, i64 88, !6, i64 120, !6, i64 128, !6, i64 136}
!18 = !{!"actormap_t", !19, i64 0}
!19 = !{!"hashmap_t", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 24}
!20 = !{!"ponyint_serialise_t", !19, i64 0}
!21 = !{!17, !10, i64 80}
!22 = !{!17, !6, i64 136}
!23 = !{!12, !6, i64 16}


; 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

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

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

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local ptr @pony_deserialise_raw(ptr noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %4 = alloca %struct.serialise_t, align 8
  %5 = alloca i64, align 8
  %6 = icmp eq i64 %1, -1
  br i1 %6, label %35, label %7

7:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  store i64 %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  store i64 -1, ptr %5, 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 %4, ptr noundef nonnull %5)
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %14, label %10

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %9, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !14
  %13 = inttoptr i64 %12 to ptr
  br label %34

14:                                               ; preds = %7
  %15 = getelementptr inbounds i8, ptr %0, i64 72
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  %17 = ptrtoint ptr %16 to i64
  %18 = add i64 %17, %1
  %19 = inttoptr i64 %18 to ptr
  %20 = getelementptr inbounds i8, ptr %0, i64 80
  %21 = load i64, ptr %20, align 8, !tbaa !20
  %22 = sub i64 %21, %1
  %23 = call ptr %2(ptr noundef %19, i64 noundef %22) #4
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %28

25:                                               ; preds = %14
  call void @serialise_cleanup(ptr noundef nonnull %0)
  %26 = getelementptr inbounds i8, ptr %0, i64 136
  %27 = load ptr, ptr %26, align 8, !tbaa !21
  call void (...) %27() #4
  call void @abort() #5
  unreachable

28:                                               ; preds = %14
  %29 = call noalias ptr @ponyint_pool_alloc(i64 noundef 0) #4
  store i64 %1, ptr %29, align 8, !tbaa !5
  %30 = ptrtoint ptr %23 to i64
  %31 = getelementptr inbounds i8, ptr %29, i64 8
  store i64 %30, ptr %31, align 8, !tbaa !14
  %32 = getelementptr inbounds i8, ptr %29, i64 16
  store ptr null, ptr %32, align 8, !tbaa !22
  %33 = load i64, ptr %5, align 8, !tbaa !13
  call void @ponyint_serialise_putindex(ptr noundef nonnull %8, ptr noundef nonnull %29, i64 noundef %33)
  br label %34

34:                                               ; preds = %28, %10
  %.0 = phi ptr [ %13, %10 ], [ %23, %28 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  br label %35

35:                                               ; preds = %3, %34
  %.1 = phi ptr [ %.0, %34 ], [ null, %3 ]
  ret ptr %.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 = { noreturn nounwind "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 #4 = { nounwind }
attributes #5 = { noreturn 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, !7, i64 8}
!15 = !{!16, !10, i64 72}
!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 = !{!16, !7, i64 80}
!21 = !{!16, !10, i64 136}
!22 = !{!6, !10, i64 16}


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