; 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_delegate_t = type { ptr, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, 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 }

@empty_delegate = external hidden global %struct.gravity_delegate_t, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @gravity_vm_new(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @gravity_core_init()
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %6 = call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 296)
  store ptr %6, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %10, label %9

9:                                                ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %63

10:                                               ; preds = %1
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.gravity_vm, ptr %11, i32 0, i32 13
  store ptr @gravity_gc_transfer, ptr %12, align 8, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.gravity_vm, ptr %13, i32 0, i32 14
  store ptr @gravity_gc_cleanup, ptr %14, align 8, !tbaa !16
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = call ptr @gravity_fiber_new(ptr noundef %15, ptr noundef null, i32 noundef 0, i32 noundef 0)
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.gravity_vm, ptr %17, i32 0, i32 2
  store ptr %16, ptr %18, align 8, !tbaa !17
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.gravity_vm, ptr %19, i32 0, i32 7
  store i32 100, ptr %20, align 4, !tbaa !18
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.gravity_vm, ptr %21, i32 0, i32 9
  store i64 0, ptr %22, align 8, !tbaa !19
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.gravity_vm, ptr %23, i32 0, i32 4
  store i32 0, ptr %24, align 8, !tbaa !20
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %29

27:                                               ; preds = %10
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  br label %30

29:                                               ; preds = %10
  br label %30

30:                                               ; preds = %29, %27
  %31 = phi ptr [ %28, %27 ], [ @empty_delegate, %29 ]
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.gravity_vm, ptr %32, i32 0, i32 1
  store ptr %31, ptr %33, align 8, !tbaa !21
  %34 = call ptr @gravity_hash_create(i32 noundef 256, ptr noundef @gravity_value_hash, ptr noundef @gravity_value_equals, ptr noundef null, ptr noundef null)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.gravity_vm, ptr %35, i32 0, i32 0
  store ptr %34, ptr %36, align 8, !tbaa !22
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  call void @gravity_gc_setenabled(ptr noundef %37, i1 noundef zeroext true)
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  call void @gravity_gc_setvalues(ptr noundef %38, i64 noundef 5242880, i64 noundef 1048576, double noundef 5.000000e-01)
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.gravity_vm, ptr %39, i32 0, i32 17
  store i64 0, ptr %40, align 8, !tbaa !23
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.gravity_vm, ptr %41, i32 0, i32 18
  store i64 157286400, ptr %42, align 8, !tbaa !24
  %43 = load ptr, ptr %4, 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 0, ptr %45, align 8, !tbaa !25
  %46 = load ptr, ptr %4, 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 0
  store i64 0, ptr %48, align 8, !tbaa !26
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.gravity_vm, ptr %49, i32 0, i32 25
  %51 = getelementptr inbounds %struct.gravity_object_r, ptr %50, i32 0, i32 2
  store ptr null, ptr %51, align 8, !tbaa !27
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.gravity_vm, ptr %52, i32 0, i32 26
  %54 = getelementptr inbounds %struct.gravity_object_r, ptr %53, i32 0, i32 1
  store i64 0, ptr %54, align 8, !tbaa !28
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.gravity_vm, ptr %55, i32 0, i32 26
  %57 = getelementptr inbounds %struct.gravity_object_r, ptr %56, i32 0, i32 0
  store i64 0, ptr %57, align 8, !tbaa !29
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.gravity_vm, ptr %58, i32 0, i32 26
  %60 = getelementptr inbounds %struct.gravity_object_r, ptr %59, i32 0, i32 2
  store ptr null, ptr %60, align 8, !tbaa !30
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  call void @gravity_core_register(ptr noundef %61)
  call void @gravity_cache_setup()
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %62, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %63

63:                                               ; preds = %30, %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %64 = load ptr, ptr %2, align 8
  ret ptr %64
}

declare void @gravity_core_init() #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

declare ptr @gravity_calloc(ptr noundef, i64 noundef, i64 noundef) #1

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

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

declare ptr @gravity_fiber_new(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #1

declare ptr @gravity_hash_create(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @gravity_value_hash(ptr, i64) #1

declare zeroext i1 @gravity_value_equals(ptr, i64, ptr, i64) #1

; Function Attrs: nounwind uwtable
declare dso_local void @gravity_gc_setenabled(ptr noundef, i1 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare dso_local void @gravity_gc_setvalues(ptr noundef, i64 noundef, i64 noundef, double noundef) #0

declare void @gravity_core_register(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @gravity_cache_setup() #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
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 152}
!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, !6, i64 160}
!17 = !{!10, !6, i64 16}
!18 = !{!10, !11, i64 52}
!19 = !{!10, !14, i64 64}
!20 = !{!10, !11, i64 32}
!21 = !{!10, !6, i64 8}
!22 = !{!10, !6, i64 0}
!23 = !{!10, !14, i64 184}
!24 = !{!10, !14, i64 192}
!25 = !{!10, !14, i64 256}
!26 = !{!10, !14, i64 248}
!27 = !{!10, !6, i64 264}
!28 = !{!10, !14, i64 280}
!29 = !{!10, !14, i64 272}
!30 = !{!10, !6, i64 288}


; 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_delegate_t = type { ptr, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@empty_delegate = external hidden global %struct.gravity_delegate_t, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @gravity_vm_new(ptr noundef %0) local_unnamed_addr #0 {
  tail call void @gravity_core_init() #3
  %2 = tail call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 296) #3
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %17, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %2, i64 152
  store ptr @gravity_gc_transfer, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %2, i64 160
  store ptr @gravity_gc_cleanup, ptr %5, align 8, !tbaa !15
  %6 = tail call ptr @gravity_fiber_new(ptr noundef nonnull %2, ptr noundef null, i32 noundef 0, i32 noundef 0) #3
  %7 = getelementptr inbounds i8, ptr %2, i64 16
  store ptr %6, ptr %7, align 8, !tbaa !16
  %8 = getelementptr inbounds i8, ptr %2, i64 52
  store i32 100, ptr %8, align 4, !tbaa !17
  %9 = getelementptr inbounds i8, ptr %2, i64 64
  store i64 0, ptr %9, align 8, !tbaa !18
  %10 = getelementptr inbounds i8, ptr %2, i64 32
  store i32 0, ptr %10, align 8, !tbaa !19
  %.not26 = icmp eq ptr %0, null
  %11 = select i1 %.not26, ptr @empty_delegate, ptr %0
  %12 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %11, ptr %12, align 8, !tbaa !20
  %13 = tail call ptr @gravity_hash_create(i32 noundef 256, ptr noundef nonnull @gravity_value_hash, ptr noundef nonnull @gravity_value_equals, ptr noundef null, ptr noundef null) #3
  store ptr %13, ptr %2, align 8, !tbaa !21
  tail call void @gravity_gc_setenabled(ptr noundef nonnull %2, i1 noundef zeroext true)
  tail call void @gravity_gc_setvalues(ptr noundef nonnull %2, i64 noundef 5242880, i64 noundef 1048576, double noundef 5.000000e-01)
  %14 = getelementptr inbounds i8, ptr %2, i64 184
  store i64 0, ptr %14, align 8, !tbaa !22
  %15 = getelementptr inbounds i8, ptr %2, i64 192
  store i64 157286400, ptr %15, align 8, !tbaa !23
  %16 = getelementptr inbounds i8, ptr %2, i64 248
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %16, i8 0, i64 48, i1 false)
  tail call void @gravity_core_register(ptr noundef nonnull %2) #3
  tail call void @gravity_cache_setup()
  br label %17

17:                                               ; preds = %1, %3
  ret ptr %2
}

declare void @gravity_core_init() local_unnamed_addr #1

declare ptr @gravity_calloc(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

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

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

declare ptr @gravity_fiber_new(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare ptr @gravity_hash_create(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @gravity_value_hash(ptr, i64) #1

declare zeroext i1 @gravity_value_equals(ptr, i64, ptr, i64) #1

; Function Attrs: nounwind uwtable
declare dso_local void @gravity_gc_setenabled(ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @gravity_gc_setvalues(ptr noundef, i64 noundef, i64 noundef, double noundef) local_unnamed_addr #0

declare void @gravity_core_register(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @gravity_cache_setup() local_unnamed_addr #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }
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 152}
!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, !7, i64 160}
!16 = !{!6, !7, i64 16}
!17 = !{!6, !10, i64 52}
!18 = !{!6, !13, i64 64}
!19 = !{!6, !10, i64 32}
!20 = !{!6, !7, i64 8}
!21 = !{!6, !7, i64 0}
!22 = !{!6, !13, i64 184}
!23 = !{!6, !13, i64 192}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass