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

@gravity_class_class = external global ptr, align 8
@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

; 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
define dso_local ptr @gravity_value_xdata(ptr %0, i64 %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca %struct.gravity_value_t, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = getelementptr inbounds { ptr, i64 }, ptr %4, i32 0, i32 0
  store ptr %0, ptr %7, align 8
  %8 = getelementptr inbounds { ptr, i64 }, ptr %4, i32 0, i32 1
  store i64 %1, ptr %8, align 8
  %9 = getelementptr inbounds %struct.gravity_value_t, ptr %4, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = load ptr, ptr @gravity_class_instance, align 8, !tbaa !10
  %12 = icmp eq ptr %10, %11
  br i1 %12, label %13, label %19

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %14 = getelementptr inbounds %struct.gravity_value_t, ptr %4, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  store ptr %15, ptr %5, align 8, !tbaa !10
  %16 = load ptr, ptr %5, align 8, !tbaa !10
  %17 = getelementptr inbounds %struct.gravity_instance_t, ptr %16, i32 0, i32 3
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  store ptr %18, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %32

19:                                               ; preds = %2
  %20 = getelementptr inbounds %struct.gravity_value_t, ptr %4, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = load ptr, ptr @gravity_class_class, align 8, !tbaa !10
  %23 = icmp eq ptr %21, %22
  br i1 %23, label %24, label %30

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %25 = getelementptr inbounds %struct.gravity_value_t, ptr %4, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  store ptr %26, ptr %6, align 8, !tbaa !10
  %27 = load ptr, ptr %6, align 8, !tbaa !10
  %28 = getelementptr inbounds %struct.gravity_class_s, ptr %27, i32 0, i32 8
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  store ptr %29, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %32

30:                                               ; preds = %19
  br label %31

31:                                               ; preds = %30
  store ptr null, ptr %3, align 8
  br label %32

32:                                               ; preds = %31, %24, %13
  %33 = load ptr, ptr %3, align 8
  ret ptr %33
}

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 = { 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 = !{!"", !7, i64 0, !8, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!8, !8, i64 0}
!12 = !{!13, !7, i64 56}
!13 = !{!"", !7, i64 0, !14, i64 8, !7, i64 48, !7, i64 56, !7, i64 64}
!14 = !{!"gravity_gc_s", !15, i64 0, !15, i64 1, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!15 = !{!"_Bool", !8, i64 0}
!16 = !{!17, !7, i64 72}
!17 = !{!"gravity_class_s", !7, i64 0, !14, i64 8, !7, i64 48, !7, i64 56, !15, i64 64, !15, i64 65, !15, i64 66, !15, i64 67, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !18, i64 104, !7, i64 112}
!18 = !{!"int", !8, i64 0}


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

@gravity_class_class = external local_unnamed_addr global ptr, align 8
@gravity_class_instance = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @gravity_value_xdata(ptr readnone %0, i64 %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @gravity_class_instance, align 8, !tbaa !5
  %4 = icmp eq ptr %3, %0
  br i1 %4, label %.sink.split, label %5

5:                                                ; preds = %2
  %6 = load ptr, ptr @gravity_class_class, align 8, !tbaa !5
  %7 = icmp eq ptr %6, %0
  br i1 %7, label %.sink.split, label %11

.sink.split:                                      ; preds = %5, %2
  %.sink7 = phi i64 [ 56, %2 ], [ 72, %5 ]
  %8 = inttoptr i64 %1 to ptr
  %9 = getelementptr inbounds i8, ptr %8, i64 %.sink7
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %.sink.split, %5
  %.0 = phi ptr [ null, %5 ], [ %10, %.sink.split ]
  ret ptr %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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" }

!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"}


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