; LLVM IR from marcobambini/gravity :: src/runtime (gravity_vm)

; 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_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 }
%struct.gravity_vm = type { ptr, ptr, ptr, ptr, i32, double, i8, i32, i32, i64, i64, i32, [64 x i8], ptr, ptr, ptr, i32, i64, i64, ptr, i64, i64, i64, double, i64, %struct.gravity_object_r, %struct.gravity_object_r }
%struct.gravity_object_r = type { i64, i64, ptr }

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @gravity_gray_object(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp ne ptr %5, null
  br i1 %6, label %8, label %7

7:                                                ; preds = %2
  br label %71

8:                                                ; preds = %2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.gravity_class_s, ptr %9, i32 0, i32 1
  %11 = getelementptr inbounds %struct.gravity_gc_s, ptr %10, i32 0, i32 0
  %12 = load i8, ptr %11, align 8, !tbaa !9, !range !14, !noundef !15
  %13 = trunc i8 %12 to i1
  br i1 %13, label %14, label %15

14:                                               ; preds = %8
  br label %71

15:                                               ; preds = %8
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.gravity_class_s, ptr %16, i32 0, i32 1
  %18 = getelementptr inbounds %struct.gravity_gc_s, ptr %17, i32 0, i32 0
  store i8 1, ptr %18, align 8, !tbaa !9
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.gravity_vm, ptr %19, i32 0, i32 25
  %21 = getelementptr inbounds %struct.gravity_object_r, ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !16
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.gravity_vm, ptr %23, i32 0, i32 25
  %25 = getelementptr inbounds %struct.gravity_object_r, ptr %24, i32 0, i32 1
  %26 = load i64, ptr %25, align 8, !tbaa !21
  %27 = icmp eq i64 %22, %26
  br i1 %27, label %28, label %59

28:                                               ; preds = %15
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.gravity_vm, ptr %29, i32 0, i32 25
  %31 = getelementptr inbounds %struct.gravity_object_r, ptr %30, i32 0, i32 1
  %32 = load i64, ptr %31, align 8, !tbaa !21
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %34, label %40

34:                                               ; preds = %28
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.gravity_vm, ptr %35, i32 0, i32 25
  %37 = getelementptr inbounds %struct.gravity_object_r, ptr %36, i32 0, i32 1
  %38 = load i64, ptr %37, align 8, !tbaa !21
  %39 = shl i64 %38, 1
  br label %41

40:                                               ; preds = %28
  br label %41

41:                                               ; preds = %40, %34
  %42 = phi i64 [ %39, %34 ], [ 8, %40 ]
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.gravity_vm, ptr %43, i32 0, i32 25
  %45 = getelementptr inbounds %struct.gravity_object_r, ptr %44, i32 0, i32 1
  store i64 %42, ptr %45, align 8, !tbaa !21
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.gravity_vm, ptr %46, i32 0, i32 25
  %48 = getelementptr inbounds %struct.gravity_object_r, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !22
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.gravity_vm, ptr %50, i32 0, i32 25
  %52 = getelementptr inbounds %struct.gravity_object_r, ptr %51, i32 0, i32 1
  %53 = load i64, ptr %52, align 8, !tbaa !21
  %54 = mul i64 8, %53
  %55 = call ptr @realloc(ptr noundef %49, i64 noundef %54) #2
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.gravity_vm, ptr %56, i32 0, i32 25
  %58 = getelementptr inbounds %struct.gravity_object_r, ptr %57, i32 0, i32 2
  store ptr %55, ptr %58, align 8, !tbaa !22
  br label %59

59:                                               ; preds = %41, %15
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.gravity_vm, ptr %61, i32 0, i32 25
  %63 = getelementptr inbounds %struct.gravity_object_r, ptr %62, i32 0, i32 2
  %64 = load ptr, ptr %63, align 8, !tbaa !22
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.gravity_vm, ptr %65, i32 0, i32 25
  %67 = getelementptr inbounds %struct.gravity_object_r, ptr %66, i32 0, i32 0
  %68 = load i64, ptr %67, align 8, !tbaa !16
  %69 = add i64 %68, 1
  store i64 %69, ptr %67, align 8, !tbaa !16
  %70 = getelementptr inbounds ptr, ptr %64, i64 %68
  store ptr %60, ptr %70, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %59, %14, %7
  ret void
}

attributes #0 = { nounwind allocsize(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 #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 allocsize(1) }

!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, !12, i64 8}
!10 = !{!"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, !13, i64 104, !6, i64 112}
!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 = !{!"int", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!17, !19, i64 248}
!17 = !{!"gravity_vm", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !18, i64 40, !12, i64 48, !13, i64 52, !13, i64 56, !19, i64 64, !19, i64 72, !13, i64 80, !7, i64 84, !6, i64 152, !6, i64 160, !6, i64 168, !13, i64 176, !19, i64 184, !19, i64 192, !6, i64 200, !19, i64 208, !19, i64 216, !19, i64 224, !18, i64 232, !19, i64 240, !20, i64 248, !20, i64 272}
!18 = !{!"double", !7, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!"", !19, i64 0, !19, i64 8, !6, i64 16}
!21 = !{!17, !19, i64 256}
!22 = !{!17, !6, i64 264}


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

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn uwtable
define dso_local void @gravity_gray_object(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %24, label %3

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = load i8, ptr %4, align 8, !tbaa !5, !range !13, !noundef !14
  %6 = trunc nuw i8 %5 to i1
  br i1 %6, label %24, label %7

7:                                                ; preds = %3
  store i8 1, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 248
  %9 = load i64, ptr %8, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %0, i64 256
  %11 = load i64, ptr %10, align 8, !tbaa !20
  %12 = icmp eq i64 %9, %11
  br i1 %12, label %13, label %._crit_edge

._crit_edge:                                      ; preds = %7
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 264
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !21
  br label %19

13:                                               ; preds = %7
  %.not15 = icmp eq i64 %9, 0
  %14 = shl i64 %9, 1
  %spec.select = select i1 %.not15, i64 8, i64 %14
  store i64 %spec.select, ptr %10, align 8, !tbaa !20
  %15 = getelementptr inbounds i8, ptr %0, i64 264
  %16 = load ptr, ptr %15, align 8, !tbaa !21
  %17 = shl i64 %spec.select, 3
  %18 = tail call ptr @realloc(ptr noundef %16, i64 noundef %17) #2
  store ptr %18, ptr %15, align 8, !tbaa !21
  %.pre16 = load i64, ptr %8, align 8, !tbaa !15
  br label %19

19:                                               ; preds = %._crit_edge, %13
  %20 = phi i64 [ %9, %._crit_edge ], [ %.pre16, %13 ]
  %21 = phi ptr [ %.pre, %._crit_edge ], [ %18, %13 ]
  %22 = add i64 %20, 1
  store i64 %22, ptr %8, align 8, !tbaa !15
  %23 = getelementptr inbounds ptr, ptr %21, i64 %20
  store ptr %1, ptr %23, align 8, !tbaa !22
  br label %24

24:                                               ; preds = %3, %2, %19
  ret void
}

attributes #0 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nounwind willreturn 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 allocsize(1) }

!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, !11, i64 8}
!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 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !18, i64 248}
!16 = !{!"gravity_vm", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !12, i64 32, !17, i64 40, !11, i64 48, !12, i64 52, !12, i64 56, !18, i64 64, !18, i64 72, !12, i64 80, !8, i64 84, !7, i64 152, !7, i64 160, !7, i64 168, !12, i64 176, !18, i64 184, !18, i64 192, !7, i64 200, !18, i64 208, !18, i64 216, !18, i64 224, !17, i64 232, !18, i64 240, !19, i64 248, !19, i64 272}
!17 = !{!"double", !8, i64 0}
!18 = !{!"long", !8, i64 0}
!19 = !{!"", !18, i64 0, !18, i64 8, !7, i64 16}
!20 = !{!16, !18, i64 256}
!21 = !{!16, !7, i64 264}
!22 = !{!7, !7, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass