; 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_closure_s = type { ptr, %struct.gravity_gc_s, ptr, ptr, ptr, ptr, i32 }
%struct.gravity_function_t = type { ptr, %struct.gravity_gc_s, ptr, ptr, i16, i16, i16, i16, i32, %union.anon.4 }
%union.anon.4 = type { %struct.anon.5 }
%struct.anon.5 = type { %struct.gravity_value_r, %struct.gravity_value_r, %struct.gravity_value_r, i32, ptr, ptr, float, i8 }
%struct.gravity_value_r = type { i64, i64, ptr }
%struct.anon.6 = type { i16, [2 x ptr] }

@gravity_class_null = 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: 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: inlinehint nounwind uwtable
declare dso_local ptr @gravity_class_lookup_closure(ptr noundef, ptr, i64) #2

declare zeroext i1 @gravity_vm_runclosure(ptr noundef, ptr noundef, ptr, i64, ptr noundef, i16 noundef zeroext) #3

; Function Attrs: nounwind uwtable
define dso_local { ptr, i64 } @gravity_instance_lookup_property(ptr noundef %0, ptr noundef %1, ptr %2, i64 %3) #4 {
  %5 = alloca %struct.gravity_value_t, align 8
  %6 = alloca %struct.gravity_value_t, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca %struct.gravity_value_t, align 8
  %14 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 0
  store ptr %2, ptr %14, align 8
  %15 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 1
  store i64 %3, ptr %15, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.gravity_instance_t, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8
  %21 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 1
  %22 = load i64, ptr %21, align 8
  %23 = call ptr @gravity_class_lookup_closure(ptr noundef %18, ptr %20, i64 %22)
  store ptr %23, ptr %9, align 8, !tbaa !5
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %29, label %26

26:                                               ; preds = %4
  %27 = getelementptr inbounds %struct.gravity_value_t, ptr %5, i32 0, i32 0
  store ptr null, ptr %27, align 8, !tbaa !13
  %28 = getelementptr inbounds %struct.gravity_value_t, ptr %5, i32 0, i32 1
  store ptr null, ptr %28, align 8, !tbaa !15
  store i32 1, ptr %10, align 4
  br label %88

29:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.gravity_closure_s, ptr %30, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  store ptr %32, ptr %11, align 8, !tbaa !5
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %40

35:                                               ; preds = %29
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.gravity_function_t, ptr %36, i32 0, i32 8
  %38 = load i32, ptr %37, align 8, !tbaa !19
  %39 = icmp ne i32 %38, 3
  br i1 %39, label %40, label %43

40:                                               ; preds = %35, %29
  %41 = getelementptr inbounds %struct.gravity_value_t, ptr %5, i32 0, i32 0
  store ptr null, ptr %41, align 8, !tbaa !13
  %42 = getelementptr inbounds %struct.gravity_value_t, ptr %5, i32 0, i32 1
  store ptr null, ptr %42, align 8, !tbaa !15
  store i32 1, ptr %10, align 4
  br label %87

43:                                               ; preds = %35
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.gravity_function_t, ptr %44, i32 0, i32 9
  %46 = getelementptr inbounds %struct.anon.6, ptr %45, i32 0, i32 1
  %47 = getelementptr inbounds [2 x ptr], ptr %46, i64 0, i64 0
  %48 = load ptr, ptr %47, align 8, !tbaa !15
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %77

50:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.gravity_function_t, ptr %51, i32 0, i32 9
  %53 = getelementptr inbounds %struct.anon.6, ptr %52, i32 0, i32 1
  %54 = getelementptr inbounds [2 x ptr], ptr %53, i64 0, i64 0
  %55 = load ptr, ptr %54, align 8, !tbaa !15
  store ptr %55, ptr %12, align 8, !tbaa !5
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load ptr, ptr %12, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.gravity_value_t, ptr %13, i32 0, i32 0
  %59 = load ptr, ptr @gravity_class_null, align 8, !tbaa !5
  store ptr %59, ptr %58, align 8, !tbaa !13
  %60 = getelementptr inbounds %struct.gravity_value_t, ptr %13, i32 0, i32 1
  store i64 0, ptr %60, align 8, !tbaa !15
  %61 = getelementptr inbounds { ptr, i64 }, ptr %13, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8
  %63 = getelementptr inbounds { ptr, i64 }, ptr %13, i32 0, i32 1
  %64 = load i64, ptr %63, align 8
  %65 = call zeroext i1 @gravity_vm_runclosure(ptr noundef %56, ptr noundef %57, ptr %62, i64 %64, ptr noundef null, i16 noundef zeroext 0)
  br i1 %65, label %66, label %73

66:                                               ; preds = %50
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = call { ptr, i64 } @gravity_vm_result(ptr noundef %67)
  %69 = getelementptr inbounds { ptr, i64 }, ptr %5, i32 0, i32 0
  %70 = extractvalue { ptr, i64 } %68, 0
  store ptr %70, ptr %69, align 8
  %71 = getelementptr inbounds { ptr, i64 }, ptr %5, i32 0, i32 1
  %72 = extractvalue { ptr, i64 } %68, 1
  store i64 %72, ptr %71, align 8
  store i32 1, ptr %10, align 4
  br label %74

73:                                               ; preds = %50
  store i32 0, ptr %10, align 4
  br label %74

74:                                               ; preds = %73, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %75 = load i32, ptr %10, align 4
  switch i32 %75, label %87 [
    i32 0, label %76
  ]

76:                                               ; preds = %74
  br label %77

77:                                               ; preds = %76, %43
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.gravity_instance_t, ptr %78, i32 0, i32 4
  %80 = load ptr, ptr %79, align 8, !tbaa !22
  %81 = load ptr, ptr %11, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.gravity_function_t, ptr %81, i32 0, i32 9
  %83 = getelementptr inbounds %struct.anon.6, ptr %82, i32 0, i32 0
  %84 = load i16, ptr %83, align 8, !tbaa !15
  %85 = zext i16 %84 to i64
  %86 = getelementptr inbounds %struct.gravity_value_t, ptr %80, i64 %85
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %86, i64 16, i1 false), !tbaa.struct !23
  store i32 1, ptr %10, align 4
  br label %87

87:                                               ; preds = %77, %74, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %88

88:                                               ; preds = %87, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  %89 = load { ptr, i64 }, ptr %5, align 8
  ret { ptr, i64 } %89
}

declare { ptr, i64 } @gravity_vm_result(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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" }
attributes #3 = { "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 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 #5 = { 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 = !{!14, !6, i64 0}
!14 = !{!"", !6, i64 0, !7, i64 8}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !6, i64 56}
!17 = !{!"gravity_closure_s", !6, i64 0, !11, i64 8, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !18, i64 80}
!18 = !{!"int", !7, i64 0}
!19 = !{!20, !18, i64 72}
!20 = !{!"", !6, i64 0, !11, i64 8, !6, i64 48, !6, i64 56, !21, i64 64, !21, i64 66, !21, i64 68, !21, i64 70, !18, i64 72, !7, i64 80}
!21 = !{!"short", !7, i64 0}
!22 = !{!10, !6, i64 64}
!23 = !{i64 0, i64 8, !5, i64 8, i64 8, !15}


; 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_null = external local_unnamed_addr global ptr, align 8

; Function Attrs: inlinehint nounwind uwtable
declare dso_local ptr @gravity_class_lookup_closure(ptr noundef, ptr, i64) local_unnamed_addr #0

declare zeroext i1 @gravity_vm_runclosure(ptr noundef, ptr noundef, ptr, i64, ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local { ptr, i64 } @gravity_instance_lookup_property(ptr noundef %0, ptr nocapture noundef readonly %1, ptr %2, i64 %3) local_unnamed_addr #2 {
  %5 = getelementptr inbounds i8, ptr %1, i64 48
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = tail call ptr @gravity_class_lookup_closure(ptr noundef %6, ptr %2, i64 %3)
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %30, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %7, i64 56
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %.not18 = icmp eq ptr %10, null
  br i1 %.not18, label %30, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %10, i64 72
  %13 = load i32, ptr %12, align 8, !tbaa !15
  %.not19 = icmp eq i32 %13, 3
  br i1 %.not19, label %14, label %30

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %10, i64 80
  %16 = getelementptr inbounds i8, ptr %10, i64 88
  %17 = load ptr, ptr %16, align 8, !tbaa !18
  %.not20 = icmp eq ptr %17, null
  br i1 %.not20, label %24, label %18

18:                                               ; preds = %14
  %19 = load ptr, ptr @gravity_class_null, align 8, !tbaa !19
  %20 = tail call zeroext i1 @gravity_vm_runclosure(ptr noundef %0, ptr noundef nonnull %17, ptr %19, i64 0, ptr noundef null, i16 noundef zeroext 0) #3
  br i1 %20, label %.thread, label %24

.thread:                                          ; preds = %18
  %21 = tail call { ptr, i64 } @gravity_vm_result(ptr noundef %0) #3
  %22 = extractvalue { ptr, i64 } %21, 0
  %23 = extractvalue { ptr, i64 } %21, 1
  br label %30

24:                                               ; preds = %18, %14
  %25 = getelementptr inbounds i8, ptr %1, i64 64
  %26 = load ptr, ptr %25, align 8, !tbaa !20
  %27 = load i16, ptr %15, align 8, !tbaa !18
  %28 = zext i16 %27 to i64
  %29 = getelementptr inbounds %struct.gravity_value_t, ptr %26, i64 %28
  %.sroa.014.0.copyload = load ptr, ptr %29, align 8, !tbaa !19
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %29, i64 8
  %.sroa.5.0.copyload = load i64, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !18
  br label %30

30:                                               ; preds = %.thread, %24, %11, %8, %4
  %.sroa.014.2 = phi ptr [ null, %4 ], [ %.sroa.014.0.copyload, %24 ], [ null, %11 ], [ null, %8 ], [ %22, %.thread ]
  %.sroa.5.2 = phi i64 [ 0, %4 ], [ %.sroa.5.0.copyload, %24 ], [ 0, %11 ], [ 0, %8 ], [ %23, %.thread ]
  %.fca.0.insert = insertvalue { ptr, i64 } poison, ptr %.sroa.014.2, 0
  %.fca.1.insert = insertvalue { ptr, i64 } %.fca.0.insert, i64 %.sroa.5.2, 1
  ret { ptr, i64 } %.fca.1.insert
}

declare { ptr, i64 } @gravity_vm_result(ptr noundef) local_unnamed_addr #1

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" }
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 = { 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 = !{!13, !7, i64 56}
!13 = !{!"gravity_closure_s", !7, i64 0, !10, i64 8, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !14, i64 80}
!14 = !{!"int", !8, i64 0}
!15 = !{!16, !14, i64 72}
!16 = !{!"", !7, i64 0, !10, i64 8, !7, i64 48, !7, i64 56, !17, i64 64, !17, i64 66, !17, i64 68, !17, i64 70, !14, i64 72, !8, i64 80}
!17 = !{!"short", !8, i64 0}
!18 = !{!8, !8, i64 0}
!19 = !{!7, !7, i64 0}
!20 = !{!6, !7, i64 64}


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