; LLVM IR from marcobambini/gravity :: src/shared (gravity_value)

; 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.gravity_instance_t = type { ptr, %struct.gravity_gc_s, ptr, ptr, ptr }
%struct.gravity_gc_s = type { i8, i8, ptr, ptr, ptr, ptr }
%struct.gravity_delegate_t = type { ptr, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.gravity_class_s = type { ptr, %struct.gravity_gc_s, ptr, ptr, i8, i8, i8, i8, ptr, ptr, ptr, ptr, i32, ptr }
%struct.gravity_value_t = type { ptr, %union.anon }
%union.anon = type { i64 }

@gravity_class_instance = external global ptr, align 8

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

declare ptr @gravity_calloc(ptr noundef, i64 noundef, i64 noundef) #1

declare void @gravity_vm_transfer(ptr noundef, ptr noundef) #1

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

; 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) #2

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @gravity_class_is_anon(ptr noundef) #3

declare ptr @gravity_vm_delegate(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @gravity_instance_clone(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  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) #4
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.gravity_instance_t, ptr %9, i32 0, i32 2
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %11, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %12 = call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 72)
  store ptr %12, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr @gravity_class_instance, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.gravity_instance_t, ptr %14, i32 0, i32 0
  store ptr %13, ptr %15, align 8, !tbaa !13
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.gravity_instance_t, ptr %17, i32 0, i32 2
  store ptr %16, ptr %18, align 8, !tbaa !9
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call zeroext i1 @gravity_class_is_anon(ptr noundef %19)
  br i1 %20, label %21, label %22

21:                                               ; preds = %2
  br label %22

22:                                               ; preds = %21, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = call ptr @gravity_vm_delegate(ptr noundef %23)
  store ptr %24, ptr %7, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.gravity_instance_t, ptr %25, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %43

29:                                               ; preds = %22
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.gravity_delegate_t, ptr %30, i32 0, i32 22
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %43

34:                                               ; preds = %29
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.gravity_delegate_t, ptr %35, i32 0, i32 22
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.gravity_instance_t, ptr %39, i32 0, i32 3
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = call ptr %37(ptr noundef %38, ptr noundef %41)
  br label %44

43:                                               ; preds = %29, %22
  br label %44

44:                                               ; preds = %43, %34
  %45 = phi ptr [ %42, %34 ], [ null, %43 ]
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.gravity_instance_t, ptr %46, i32 0, i32 3
  store ptr %45, ptr %47, align 8, !tbaa !14
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.gravity_class_s, ptr %48, i32 0, i32 12
  %50 = load i32, ptr %49, align 8, !tbaa !17
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %61

52:                                               ; preds = %44
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.gravity_class_s, ptr %53, i32 0, i32 12
  %55 = load i32, ptr %54, align 8, !tbaa !17
  %56 = zext i32 %55 to i64
  %57 = mul i64 %56, 16
  %58 = call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef %57)
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.gravity_instance_t, ptr %59, i32 0, i32 4
  store ptr %58, ptr %60, align 8, !tbaa !20
  br label %61

61:                                               ; preds = %52, %44
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !21
  br label %62

62:                                               ; preds = %82, %61
  %63 = load i32, ptr %8, align 4, !tbaa !21
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.gravity_class_s, ptr %64, i32 0, i32 12
  %66 = load i32, ptr %65, align 8, !tbaa !17
  %67 = icmp ult i32 %63, %66
  br i1 %67, label %69, label %68

68:                                               ; preds = %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %85

69:                                               ; preds = %62
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.gravity_instance_t, ptr %70, i32 0, i32 4
  %72 = load ptr, ptr %71, align 8, !tbaa !20
  %73 = load i32, ptr %8, align 4, !tbaa !21
  %74 = zext i32 %73 to i64
  %75 = getelementptr inbounds %struct.gravity_value_t, ptr %72, i64 %74
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.gravity_instance_t, ptr %76, i32 0, i32 4
  %78 = load ptr, ptr %77, align 8, !tbaa !20
  %79 = load i32, ptr %8, align 4, !tbaa !21
  %80 = zext i32 %79 to i64
  %81 = getelementptr inbounds %struct.gravity_value_t, ptr %78, i64 %80
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %75, ptr align 8 %81, i64 16, i1 false), !tbaa.struct !22
  br label %82

82:                                               ; preds = %69
  %83 = load i32, ptr %8, align 4, !tbaa !21
  %84 = add i32 %83, 1
  store i32 %84, ptr %8, align 4, !tbaa !21
  br label %62, !llvm.loop !24

85:                                               ; preds = %68
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = icmp ne ptr %86, null
  br i1 %87, label %88, label %91

88:                                               ; preds = %85
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  call void @gravity_vm_transfer(ptr noundef %89, ptr noundef %90)
  br label %91

91:                                               ; preds = %88, %85
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret ptr %92
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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, !6, i64 48}
!10 = !{!"", !6, i64 0, !11, i64 8, !6, i64 48, !6, i64 56, !6, i64 64}
!11 = !{!"gravity_gc_s", !12, i64 0, !12, i64 1, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!10, !6, i64 0}
!14 = !{!10, !6, i64 56}
!15 = !{!16, !6, i64 168}
!16 = !{!"", !6, i64 0, !12, i64 8, !12, i64 9, !6, i64 16, !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, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184}
!17 = !{!18, !19, i64 104}
!18 = !{!"gravity_class_s", !6, i64 0, !11, i64 8, !6, i64 48, !6, i64 56, !12, i64 64, !12, i64 65, !12, i64 66, !12, i64 67, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !19, i64 104, !6, i64 112}
!19 = !{!"int", !7, i64 0}
!20 = !{!10, !6, i64 64}
!21 = !{!19, !19, i64 0}
!22 = !{i64 0, i64 8, !5, i64 8, i64 8, !23}
!23 = !{!7, !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


; 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.gravity_value_t = type { ptr, %union.anon }
%union.anon = type { i64 }

@gravity_class_instance = external local_unnamed_addr global ptr, align 8

declare ptr @gravity_calloc(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

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

; 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) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @gravity_class_is_anon(ptr noundef) local_unnamed_addr #2

declare ptr @gravity_vm_delegate(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @gravity_instance_clone(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 48
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = tail call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 72) #3
  %6 = load ptr, ptr @gravity_class_instance, align 8, !tbaa !12
  store ptr %6, ptr %5, align 8, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %5, i64 48
  store ptr %4, ptr %7, align 8, !tbaa !5
  %8 = tail call zeroext i1 @gravity_class_is_anon(ptr noundef %4)
  %9 = tail call ptr @gravity_vm_delegate(ptr noundef %0) #3
  %10 = getelementptr inbounds i8, ptr %1, i64 56
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %17, label %12

12:                                               ; preds = %2
  %13 = getelementptr inbounds i8, ptr %9, i64 168
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %.not29 = icmp eq ptr %14, null
  br i1 %.not29, label %17, label %15

15:                                               ; preds = %12
  %16 = tail call ptr %14(ptr noundef %0, ptr noundef nonnull %11) #3
  br label %17

17:                                               ; preds = %2, %12, %15
  %18 = phi ptr [ %16, %15 ], [ null, %12 ], [ null, %2 ]
  %19 = getelementptr inbounds i8, ptr %5, i64 56
  store ptr %18, ptr %19, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %4, i64 104
  %21 = load i32, ptr %20, align 8, !tbaa !17
  %.not30 = icmp eq i32 %21, 0
  br i1 %.not30, label %._crit_edge, label %22

22:                                               ; preds = %17
  %23 = zext i32 %21 to i64
  %24 = shl nuw nsw i64 %23, 4
  %25 = tail call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef %24) #3
  %26 = getelementptr inbounds i8, ptr %5, i64 64
  store ptr %25, ptr %26, align 8, !tbaa !20
  %.pre = load i32, ptr %20, align 8, !tbaa !17
  %27 = icmp eq i32 %.pre, 0
  br i1 %27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %22
  %28 = getelementptr inbounds i8, ptr %5, i64 64
  %29 = getelementptr inbounds i8, ptr %1, i64 64
  br label %30

._crit_edge:                                      ; preds = %30, %17, %22
  %.not31 = icmp eq ptr %0, null
  br i1 %.not31, label %39, label %38

30:                                               ; preds = %.lr.ph, %30
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %30 ]
  %31 = load ptr, ptr %28, align 8, !tbaa !20
  %32 = getelementptr inbounds %struct.gravity_value_t, ptr %31, i64 %indvars.iv
  %33 = load ptr, ptr %29, align 8, !tbaa !20
  %34 = getelementptr inbounds %struct.gravity_value_t, ptr %33, i64 %indvars.iv
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %32, ptr noundef nonnull align 8 dereferenceable(16) %34, i64 16, i1 false), !tbaa.struct !21
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %35 = load i32, ptr %20, align 8, !tbaa !17
  %36 = zext i32 %35 to i64
  %37 = icmp ult i64 %indvars.iv.next, %36
  br i1 %37, label %30, label %._crit_edge, !llvm.loop !23

38:                                               ; preds = %._crit_edge
  tail call void @gravity_vm_transfer(ptr noundef nonnull %0, ptr noundef nonnull %5) #3
  br label %39

39:                                               ; preds = %38, %._crit_edge
  ret ptr %5
}

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 = { mustprogress nocallback nofree 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 = { 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 48}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 48, !7, i64 56, !7, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"gravity_gc_s", !11, i64 0, !11, i64 1, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !7, i64 56}
!15 = !{!16, !7, i64 168}
!16 = !{!"", !7, i64 0, !11, i64 8, !11, i64 9, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !7, i64 160, !7, i64 168, !7, i64 176, !7, i64 184}
!17 = !{!18, !19, i64 104}
!18 = !{!"gravity_class_s", !7, i64 0, !10, i64 8, !7, i64 48, !7, i64 56, !11, i64 64, !11, i64 65, !11, i64 66, !11, i64 67, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !19, i64 104, !7, i64 112}
!19 = !{!"int", !8, i64 0}
!20 = !{!6, !7, i64 64}
!21 = !{i64 0, i64 8, !12, i64 8, i64 8, !22}
!22 = !{!8, !8, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass