; 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_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: 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
declare dso_local void @gravity_gray_object(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @gravity_gc_start(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.gravity_vm, ptr %6, i32 0, i32 2
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp ne ptr %8, null
  br i1 %9, label %11, label %10

10:                                               ; preds = %1
  br label %112

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

14:                                               ; preds = %34, %11
  %15 = load i32, ptr %3, align 4, !tbaa !17
  %16 = zext i32 %15 to i64
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.gravity_vm, ptr %17, i32 0, i32 26
  %19 = getelementptr inbounds %struct.gravity_object_r, ptr %18, i32 0, i32 0
  %20 = load i64, ptr %19, align 8, !tbaa !18
  %21 = icmp ult i64 %16, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %37

23:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.gravity_vm, ptr %24, i32 0, i32 26
  %26 = getelementptr inbounds %struct.gravity_object_r, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !19
  %28 = load i32, ptr %3, align 4, !tbaa !17
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds ptr, ptr %27, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  store ptr %31, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  call void @gravity_gray_object(ptr noundef %32, ptr noundef %33)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %34

34:                                               ; preds = %23
  %35 = load i32, ptr %3, align 4, !tbaa !17
  %36 = add i32 %35, 1
  store i32 %36, ptr %3, align 4, !tbaa !17
  br label %14, !llvm.loop !20

37:                                               ; preds = %22
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.gravity_vm, ptr %39, i32 0, i32 2
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  call void @gravity_gray_object(ptr noundef %38, ptr noundef %41)
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.gravity_vm, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !22
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  call void @gravity_hash_iterate(ptr noundef %44, ptr noundef @gravity_gray_hash, ptr noundef %45)
  br label %46

46:                                               ; preds = %52, %37
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.gravity_vm, ptr %47, i32 0, i32 25
  %49 = getelementptr inbounds %struct.gravity_object_r, ptr %48, i32 0, i32 0
  %50 = load i64, ptr %49, align 8, !tbaa !23
  %51 = icmp ne i64 %50, 0
  br i1 %51, label %52, label %66

52:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.gravity_vm, ptr %53, i32 0, i32 25
  %55 = getelementptr inbounds %struct.gravity_object_r, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !24
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.gravity_vm, ptr %57, i32 0, i32 25
  %59 = getelementptr inbounds %struct.gravity_object_r, ptr %58, i32 0, i32 0
  %60 = load i64, ptr %59, align 8, !tbaa !23
  %61 = add i64 %60, -1
  store i64 %61, ptr %59, align 8, !tbaa !23
  %62 = getelementptr inbounds ptr, ptr %56, i64 %61
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  store ptr %63, ptr %5, align 8, !tbaa !5
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  call void @gravity_object_blacken(ptr noundef %64, ptr noundef %65)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %46, !llvm.loop !25

66:                                               ; preds = %46
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  call void @gravity_gc_sweep(ptr noundef %67)
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.gravity_vm, ptr %68, i32 0, i32 17
  %70 = load i64, ptr %69, align 8, !tbaa !16
  %71 = sitofp i64 %70 to double
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.gravity_vm, ptr %72, i32 0, i32 17
  %74 = load i64, ptr %73, align 8, !tbaa !16
  %75 = sitofp i64 %74 to double
  %76 = load ptr, ptr %2, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.gravity_vm, ptr %76, i32 0, i32 23
  %78 = load double, ptr %77, align 8, !tbaa !26
  %79 = fmul double %75, %78
  %80 = fdiv double %79, 1.000000e+02
  %81 = fadd double %71, %80
  %82 = fptosi double %81 to i64
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.gravity_vm, ptr %83, i32 0, i32 21
  store i64 %82, ptr %84, align 8, !tbaa !27
  %85 = load ptr, ptr %2, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.gravity_vm, ptr %85, i32 0, i32 21
  %87 = load i64, ptr %86, align 8, !tbaa !27
  %88 = load ptr, ptr %2, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.gravity_vm, ptr %88, i32 0, i32 20
  %90 = load i64, ptr %89, align 8, !tbaa !28
  %91 = icmp slt i64 %87, %90
  br i1 %91, label %92, label %98

92:                                               ; preds = %66
  %93 = load ptr, ptr %2, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.gravity_vm, ptr %93, i32 0, i32 20
  %95 = load i64, ptr %94, align 8, !tbaa !28
  %96 = load ptr, ptr %2, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.gravity_vm, ptr %96, i32 0, i32 21
  store i64 %95, ptr %97, align 8, !tbaa !27
  br label %98

98:                                               ; preds = %92, %66
  %99 = load ptr, ptr %2, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.gravity_vm, ptr %99, i32 0, i32 21
  %101 = load i64, ptr %100, align 8, !tbaa !27
  %102 = load ptr, ptr %2, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.gravity_vm, ptr %102, i32 0, i32 22
  %104 = load i64, ptr %103, align 8, !tbaa !29
  %105 = icmp slt i64 %101, %104
  br i1 %105, label %106, label %112

106:                                              ; preds = %98
  %107 = load ptr, ptr %2, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.gravity_vm, ptr %107, i32 0, i32 22
  %109 = load i64, ptr %108, align 8, !tbaa !29
  %110 = load ptr, ptr %2, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.gravity_vm, ptr %110, i32 0, i32 21
  store i64 %109, ptr %111, align 8, !tbaa !27
  br label %112

112:                                              ; preds = %106, %98, %10
  ret void
}

declare void @gravity_hash_iterate(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @gravity_gray_hash(ptr noundef, ptr, i64, ptr, i64, ptr noundef) #1

declare void @gravity_object_blacken(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @gravity_gc_sweep(ptr noundef) #1

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 = { "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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"gravity_vm", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !12, i64 40, !13, i64 48, !11, i64 52, !11, i64 56, !14, i64 64, !14, i64 72, !11, i64 80, !7, i64 84, !6, i64 152, !6, i64 160, !6, i64 168, !11, i64 176, !14, i64 184, !14, i64 192, !6, i64 200, !14, i64 208, !14, i64 216, !14, i64 224, !12, i64 232, !14, i64 240, !15, i64 248, !15, i64 272}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"", !14, i64 0, !14, i64 8, !6, i64 16}
!16 = !{!10, !14, i64 184}
!17 = !{!11, !11, i64 0}
!18 = !{!10, !14, i64 272}
!19 = !{!10, !6, i64 288}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!10, !6, i64 0}
!23 = !{!10, !14, i64 248}
!24 = !{!10, !6, i64 264}
!25 = distinct !{!25, !21}
!26 = !{!10, !12, i64 232}
!27 = !{!10, !14, i64 216}
!28 = !{!10, !14, i64 208}
!29 = !{!10, !14, i64 224}


; 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: nounwind uwtable
declare dso_local void @gravity_gray_object(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @gravity_gc_start(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %43, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 184
  store i64 0, ptr %5, align 8, !tbaa !15
  %6 = getelementptr inbounds i8, ptr %0, i64 272
  %7 = load i64, ptr %6, align 8, !tbaa !16
  %.not41 = icmp eq i64 %7, 0
  br i1 %.not41, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 288
  br label %14

._crit_edge.loopexit:                             ; preds = %14
  %.pre = load ptr, ptr %2, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %4
  %9 = phi ptr [ %.pre, %._crit_edge.loopexit ], [ %3, %4 ]
  tail call void @gravity_gray_object(ptr noundef nonnull %0, ptr noundef %9)
  %10 = load ptr, ptr %0, align 8, !tbaa !17
  tail call void @gravity_hash_iterate(ptr noundef %10, ptr noundef nonnull @gravity_gray_hash, ptr noundef nonnull %0) #3
  %11 = getelementptr inbounds i8, ptr %0, i64 248
  %12 = load i64, ptr %11, align 8, !tbaa !18
  %.not3437 = icmp eq i64 %12, 0
  br i1 %.not3437, label %._crit_edge40, label %.lr.ph39

.lr.ph39:                                         ; preds = %._crit_edge
  %13 = getelementptr inbounds i8, ptr %0, i64 264
  br label %23

14:                                               ; preds = %.lr.ph, %14
  %15 = phi i64 [ 0, %.lr.ph ], [ %20, %14 ]
  %.036 = phi i32 [ 0, %.lr.ph ], [ %19, %14 ]
  %16 = load ptr, ptr %8, align 8, !tbaa !19
  %17 = getelementptr inbounds ptr, ptr %16, i64 %15
  %18 = load ptr, ptr %17, align 8, !tbaa !20
  tail call void @gravity_gray_object(ptr noundef nonnull %0, ptr noundef %18)
  %19 = add i32 %.036, 1
  %20 = zext i32 %19 to i64
  %21 = load i64, ptr %6, align 8, !tbaa !16
  %22 = icmp ugt i64 %21, %20
  br i1 %22, label %14, label %._crit_edge.loopexit, !llvm.loop !21

23:                                               ; preds = %.lr.ph39, %23
  %24 = phi i64 [ %12, %.lr.ph39 ], [ %29, %23 ]
  %25 = load ptr, ptr %13, align 8, !tbaa !23
  %26 = add i64 %24, -1
  store i64 %26, ptr %11, align 8, !tbaa !18
  %27 = getelementptr inbounds ptr, ptr %25, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !20
  tail call void @gravity_object_blacken(ptr noundef nonnull %0, ptr noundef %28) #3
  %29 = load i64, ptr %11, align 8, !tbaa !18
  %.not34 = icmp eq i64 %29, 0
  br i1 %.not34, label %._crit_edge40, label %23, !llvm.loop !24

._crit_edge40:                                    ; preds = %23, %._crit_edge
  tail call void @gravity_gc_sweep(ptr noundef nonnull %0)
  %30 = load i64, ptr %5, align 8, !tbaa !15
  %31 = sitofp i64 %30 to double
  %32 = getelementptr inbounds i8, ptr %0, i64 232
  %33 = load double, ptr %32, align 8, !tbaa !25
  %34 = fmul double %33, %31
  %35 = fdiv double %34, 1.000000e+02
  %36 = fadd double %35, %31
  %37 = fptosi double %36 to i64
  %38 = getelementptr inbounds i8, ptr %0, i64 216
  %39 = getelementptr inbounds i8, ptr %0, i64 208
  %40 = load i64, ptr %39, align 8, !tbaa !26
  %spec.store.select = tail call i64 @llvm.smax.i64(i64 %40, i64 %37)
  %41 = getelementptr inbounds i8, ptr %0, i64 224
  %42 = load i64, ptr %41, align 8, !tbaa !27
  %spec.store.select35 = tail call i64 @llvm.smax.i64(i64 %spec.store.select, i64 %42)
  store i64 %spec.store.select35, ptr %38, align 8
  br label %43

43:                                               ; preds = %._crit_edge40, %1
  ret void
}

declare void @gravity_hash_iterate(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @gravity_gray_hash(ptr noundef, ptr, i64, ptr, i64, ptr noundef) #0

declare void @gravity_object_blacken(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @gravity_gc_sweep(ptr noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #2

attributes #0 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 16}
!6 = !{!"gravity_vm", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !11, i64 40, !12, i64 48, !10, i64 52, !10, i64 56, !13, i64 64, !13, i64 72, !10, i64 80, !8, i64 84, !7, i64 152, !7, i64 160, !7, i64 168, !10, i64 176, !13, i64 184, !13, i64 192, !7, i64 200, !13, i64 208, !13, i64 216, !13, i64 224, !11, i64 232, !13, i64 240, !14, i64 248, !14, i64 272}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!"", !13, i64 0, !13, i64 8, !7, i64 16}
!15 = !{!6, !13, i64 184}
!16 = !{!6, !13, i64 272}
!17 = !{!6, !7, i64 0}
!18 = !{!6, !13, i64 248}
!19 = !{!6, !7, i64 288}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!6, !7, i64 264}
!24 = distinct !{!24, !22}
!25 = !{!6, !11, i64 232}
!26 = !{!6, !13, i64 208}
!27 = !{!6, !13, i64 224}


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