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

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

; Function Attrs: inlinehint nounwind uwtable
define dso_local ptr @gravity_value_getclass(ptr %0, i64 %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca %struct.gravity_value_t, align 8
  %5 = getelementptr inbounds { ptr, i64 }, ptr %4, i32 0, i32 0
  store ptr %0, ptr %5, align 8
  %6 = getelementptr inbounds { ptr, i64 }, ptr %4, i32 0, i32 1
  store i64 %1, ptr %6, align 8
  %7 = getelementptr inbounds %struct.gravity_value_t, ptr %4, i32 0, i32 0
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = load ptr, ptr @gravity_class_class, align 8, !tbaa !10
  %10 = icmp eq ptr %8, %9
  br i1 %10, label %11, label %21

11:                                               ; preds = %2
  %12 = getelementptr inbounds %struct.gravity_value_t, ptr %4, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds %struct.gravity_class_s, ptr %13, i32 0, i32 2
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = load ptr, ptr @gravity_class_object, align 8, !tbaa !10
  %17 = icmp eq ptr %15, %16
  br i1 %17, label %18, label %21

18:                                               ; preds = %11
  %19 = getelementptr inbounds %struct.gravity_value_t, ptr %4, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  store ptr %20, ptr %3, align 8
  br label %46

21:                                               ; preds = %11, %2
  %22 = getelementptr inbounds %struct.gravity_value_t, ptr %4, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = load ptr, ptr @gravity_class_instance, align 8, !tbaa !10
  %25 = icmp eq ptr %23, %24
  br i1 %25, label %31, label %26

26:                                               ; preds = %21
  %27 = getelementptr inbounds %struct.gravity_value_t, ptr %4, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = load ptr, ptr @gravity_class_class, align 8, !tbaa !10
  %30 = icmp eq ptr %28, %29
  br i1 %30, label %31, label %43

31:                                               ; preds = %26, %21
  %32 = getelementptr inbounds %struct.gravity_value_t, ptr %4, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %40

35:                                               ; preds = %31
  %36 = getelementptr inbounds %struct.gravity_value_t, ptr %4, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  %38 = getelementptr inbounds %struct.gravity_class_s, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !12
  br label %41

40:                                               ; preds = %31
  br label %41

41:                                               ; preds = %40, %35
  %42 = phi ptr [ %39, %35 ], [ null, %40 ]
  store ptr %42, ptr %3, align 8
  br label %46

43:                                               ; preds = %26
  %44 = getelementptr inbounds %struct.gravity_value_t, ptr %4, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  store ptr %45, ptr %3, align 8
  br label %46

46:                                               ; preds = %43, %41, %18
  %47 = load ptr, ptr %3, align 8
  ret ptr %47
}

attributes #0 = { inlinehint 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" }

!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 48}
!13 = !{!"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, !16, i64 104, !7, i64 112}
!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 = !{!"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_object = external local_unnamed_addr global ptr, align 8
@gravity_class_instance = external local_unnamed_addr global ptr, align 8

; Function Attrs: inlinehint mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @gravity_value_getclass(ptr readnone %0, i64 %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @gravity_class_class, align 8
  %4 = icmp eq ptr %3, %0
  br i1 %4, label %5, label %11

5:                                                ; preds = %2
  %6 = inttoptr i64 %1 to ptr
  %7 = getelementptr inbounds i8, ptr %6, i64 48
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = load ptr, ptr @gravity_class_object, align 8, !tbaa !13
  %10 = icmp eq ptr %8, %9
  br i1 %10, label %18, label %.thread

11:                                               ; preds = %2
  %12 = load ptr, ptr @gravity_class_instance, align 8, !tbaa !13
  %13 = icmp eq ptr %12, %0
  br i1 %13, label %.thread, label %18

.thread:                                          ; preds = %5, %11
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %18, label %14

14:                                               ; preds = %.thread
  %15 = inttoptr i64 %1 to ptr
  %16 = getelementptr inbounds i8, ptr %15, i64 48
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %11, %14, %.thread, %5
  %.0 = phi ptr [ %6, %5 ], [ %17, %14 ], [ null, %.thread ], [ %0, %11 ]
  ret ptr %.0
}

attributes #0 = { inlinehint 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, !7, i64 48}
!6 = !{!"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, !12, i64 104, !7, i64 112}
!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 = !{!"int", !8, i64 0}
!13 = !{!7, !7, i64 0}


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