; LLVM IR from ryanlayer/giggle :: src (leaf)

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

@LEAF_POINTERS_SIZE = external dso_local global i64, align 8
@LEAF_NUMS_SIZE = external dso_local global i64, align 8
@LEAF_LEADING_STARTS_ENDS_SIZE = external dso_local global i64, align 8
@ORDER = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [38 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @leaf_data_serialize(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %8, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %9 = load i32, ptr @ORDER, align 4, !tbaa !9
  %10 = mul i32 2, %9
  %11 = zext i32 %10 to i64
  %12 = load i64, ptr @LEAF_POINTERS_SIZE, align 8, !tbaa !11
  %13 = mul i64 %11, %12
  %14 = load i64, ptr @LEAF_NUMS_SIZE, align 8, !tbaa !11
  %15 = mul i64 3, %14
  %16 = add i64 %13, %15
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.leaf_data, ptr %17, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.leaf_data, ptr %20, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !15
  %23 = add i64 %19, %22
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.leaf_data, ptr %24, i32 0, i32 2
  %26 = load i64, ptr %25, align 8, !tbaa !16
  %27 = add i64 %23, %26
  %28 = load i64, ptr @LEAF_LEADING_STARTS_ENDS_SIZE, align 8, !tbaa !11
  %29 = mul i64 %27, %28
  %30 = add i64 %16, %29
  store i64 %30, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %31 = load i64, ptr %6, align 8, !tbaa !11
  %32 = call noalias ptr @malloc(i64 noundef %31) #7
  store ptr %32, ptr %7, align 8, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = icmp eq ptr %33, null
  br i1 %34, label %35, label %36

35:                                               ; preds = %2
  call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef @.str) #8
  unreachable

36:                                               ; preds = %2
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load i64, ptr %6, align 8, !tbaa !11
  call void @llvm.memset.p0.i64(ptr align 1 %37, i8 0, i64 %38, i1 false)
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.leaf_data, ptr %40, i32 0, i32 3
  %42 = load ptr, ptr %41, align 8, !tbaa !17
  %43 = load i32, ptr @ORDER, align 4, !tbaa !9
  %44 = zext i32 %43 to i64
  %45 = load i64, ptr @LEAF_POINTERS_SIZE, align 8, !tbaa !11
  %46 = mul i64 %44, %45
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %39, ptr align 4 %42, i64 %46, i1 false)
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = load i32, ptr @ORDER, align 4, !tbaa !9
  %49 = zext i32 %48 to i64
  %50 = load i64, ptr @LEAF_POINTERS_SIZE, align 8, !tbaa !11
  %51 = mul i64 %49, %50
  %52 = getelementptr inbounds i8, ptr %47, i64 %51
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.leaf_data, ptr %53, i32 0, i32 4
  %55 = load ptr, ptr %54, align 8, !tbaa !18
  %56 = load i32, ptr @ORDER, align 4, !tbaa !9
  %57 = zext i32 %56 to i64
  %58 = load i64, ptr @LEAF_POINTERS_SIZE, align 8, !tbaa !11
  %59 = mul i64 %57, %58
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %52, ptr align 4 %55, i64 %59, i1 false)
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = load i32, ptr @ORDER, align 4, !tbaa !9
  %62 = mul i32 2, %61
  %63 = zext i32 %62 to i64
  %64 = load i64, ptr @LEAF_POINTERS_SIZE, align 8, !tbaa !11
  %65 = mul i64 %63, %64
  %66 = getelementptr inbounds i8, ptr %60, i64 %65
  %67 = load i64, ptr @LEAF_NUMS_SIZE, align 8, !tbaa !11
  %68 = mul i64 0, %67
  %69 = getelementptr inbounds i8, ptr %66, i64 %68
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.leaf_data, ptr %70, i32 0, i32 0
  %72 = load i64, ptr @LEAF_NUMS_SIZE, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %69, ptr align 8 %71, i64 %72, i1 false)
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = load i32, ptr @ORDER, align 4, !tbaa !9
  %75 = mul i32 2, %74
  %76 = zext i32 %75 to i64
  %77 = load i64, ptr @LEAF_POINTERS_SIZE, align 8, !tbaa !11
  %78 = mul i64 %76, %77
  %79 = getelementptr inbounds i8, ptr %73, i64 %78
  %80 = load i64, ptr @LEAF_NUMS_SIZE, align 8, !tbaa !11
  %81 = mul i64 1, %80
  %82 = getelementptr inbounds i8, ptr %79, i64 %81
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.leaf_data, ptr %83, i32 0, i32 1
  %85 = load i64, ptr @LEAF_NUMS_SIZE, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %82, ptr align 8 %84, i64 %85, i1 false)
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = load i32, ptr @ORDER, align 4, !tbaa !9
  %88 = mul i32 2, %87
  %89 = zext i32 %88 to i64
  %90 = load i64, ptr @LEAF_POINTERS_SIZE, align 8, !tbaa !11
  %91 = mul i64 %89, %90
  %92 = getelementptr inbounds i8, ptr %86, i64 %91
  %93 = load i64, ptr @LEAF_NUMS_SIZE, align 8, !tbaa !11
  %94 = mul i64 2, %93
  %95 = getelementptr inbounds i8, ptr %92, i64 %94
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.leaf_data, ptr %96, i32 0, i32 2
  %98 = load i64, ptr @LEAF_NUMS_SIZE, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %95, ptr align 8 %97, i64 %98, i1 false)
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  %100 = load i32, ptr @ORDER, align 4, !tbaa !9
  %101 = mul i32 2, %100
  %102 = zext i32 %101 to i64
  %103 = load i64, ptr @LEAF_POINTERS_SIZE, align 8, !tbaa !11
  %104 = mul i64 %102, %103
  %105 = getelementptr inbounds i8, ptr %99, i64 %104
  %106 = load i64, ptr @LEAF_NUMS_SIZE, align 8, !tbaa !11
  %107 = mul i64 3, %106
  %108 = getelementptr inbounds i8, ptr %105, i64 %107
  %109 = load ptr, ptr %5, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.leaf_data, ptr %109, i32 0, i32 8
  %111 = load ptr, ptr %110, align 8, !tbaa !19
  %112 = load ptr, ptr %5, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.leaf_data, ptr %112, i32 0, i32 0
  %114 = load i64, ptr %113, align 8, !tbaa !13
  %115 = load ptr, ptr %5, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.leaf_data, ptr %115, i32 0, i32 1
  %117 = load i64, ptr %116, align 8, !tbaa !15
  %118 = add i64 %114, %117
  %119 = load ptr, ptr %5, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.leaf_data, ptr %119, i32 0, i32 2
  %121 = load i64, ptr %120, align 8, !tbaa !16
  %122 = add i64 %118, %121
  %123 = load i64, ptr @LEAF_LEADING_STARTS_ENDS_SIZE, align 8, !tbaa !11
  %124 = mul i64 %122, %123
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %108, ptr align 8 %111, i64 %124, i1 false)
  %125 = load ptr, ptr %7, align 8, !tbaa !5
  %126 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %125, ptr %126, align 8, !tbaa !5
  %127 = load i64, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  ret i64 %127
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: noreturn
declare void @err(i32 noundef, ptr noundef, ...) #3

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(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 = { noreturn "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { noreturn }

!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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"leaf_data", !12, i64 0, !12, i64 8, !12, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!15 = !{!14, !12, i64 8}
!16 = !{!14, !12, i64 16}
!17 = !{!14, !6, i64 24}
!18 = !{!14, !6, i64 32}
!19 = !{!14, !6, i64 64}


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

@LEAF_POINTERS_SIZE = external dso_local local_unnamed_addr global i64, align 8
@LEAF_NUMS_SIZE = external dso_local local_unnamed_addr global i64, align 8
@LEAF_LEADING_STARTS_ENDS_SIZE = external dso_local local_unnamed_addr global i64, align 8
@ORDER = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [38 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @leaf_data_serialize(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @ORDER, align 4, !tbaa !5
  %4 = shl i32 %3, 1
  %5 = zext i32 %4 to i64
  %6 = load i64, ptr @LEAF_POINTERS_SIZE, align 8, !tbaa !9
  %7 = mul i64 %6, %5
  %8 = load i64, ptr @LEAF_NUMS_SIZE, align 8, !tbaa !9
  %9 = mul i64 %8, 3
  %10 = add i64 %7, %9
  %11 = load i64, ptr %0, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load i64, ptr %12, align 8, !tbaa !14
  %14 = add i64 %13, %11
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load i64, ptr %15, align 8, !tbaa !15
  %17 = add i64 %14, %16
  %18 = load i64, ptr @LEAF_LEADING_STARTS_ENDS_SIZE, align 8, !tbaa !9
  %19 = mul i64 %17, %18
  %20 = add i64 %10, %19
  %calloc = tail call ptr @calloc(i64 1, i64 %20)
  %21 = icmp eq ptr %calloc, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %2
  tail call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef nonnull @.str) #4
  unreachable

23:                                               ; preds = %2
  %24 = getelementptr inbounds i8, ptr %0, i64 24
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = zext i32 %3 to i64
  %27 = mul i64 %6, %26
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %calloc, ptr align 4 %25, i64 %27, i1 false)
  %28 = getelementptr inbounds i8, ptr %calloc, i64 %27
  %29 = getelementptr inbounds i8, ptr %0, i64 32
  %30 = load ptr, ptr %29, align 8, !tbaa !17
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %28, ptr align 4 %30, i64 %27, i1 false)
  %31 = getelementptr inbounds i8, ptr %calloc, i64 %7
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %31, ptr nonnull align 8 %0, i64 %8, i1 false)
  %32 = getelementptr inbounds i8, ptr %31, i64 %8
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %32, ptr nonnull align 8 %12, i64 %8, i1 false)
  %33 = shl i64 %8, 1
  %34 = getelementptr inbounds i8, ptr %31, i64 %33
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %34, ptr nonnull align 8 %15, i64 %8, i1 false)
  %35 = getelementptr inbounds i8, ptr %31, i64 %9
  %36 = getelementptr inbounds i8, ptr %0, i64 64
  %37 = load ptr, ptr %36, align 8, !tbaa !18
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %35, ptr align 8 %37, i64 %19, i1 false)
  store ptr %calloc, ptr %1, align 8, !tbaa !19
  ret i64 %20
}

; Function Attrs: noreturn
declare void @err(i32 noundef, ptr noundef, ...) local_unnamed_addr #1

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

; Function Attrs: nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #3

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 = { noreturn "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: readwrite) }
attributes #3 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #4 = { 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 = !{!"int", !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 = !{!"leaf_data", !10, i64 0, !10, i64 8, !10, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !10, i64 16}
!16 = !{!12, !13, i64 24}
!17 = !{!12, !13, i64 32}
!18 = !{!12, !13, i64 64}
!19 = !{!13, !13, i64 0}


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