; 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 }
%struct.fiber_s = type { ptr, %struct.gravity_gc_s, ptr, ptr, i32, ptr, i32, i32, ptr, ptr, i8, ptr, %struct.gravity_value_t, i32, i64, double, double }
%struct.gravity_gc_s = type { i8, i8, ptr, ptr, ptr, ptr }
%struct.gravity_value_t = type { ptr, %union.anon }
%union.anon = type { i64 }
%struct.gravity_callframe_t = type { ptr, i32, i16, ptr, ptr, ptr, i8 }

; 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
define dso_local ptr @gravity_vm_getclosure(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = icmp ne ptr %5, null
  br i1 %6, label %7, label %12

7:                                                ; preds = %1
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.gravity_vm, ptr %8, i32 0, i32 2
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = icmp ne ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %7, %1
  store ptr null, ptr %2, align 8
  br label %44

13:                                               ; preds = %7
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.gravity_vm, ptr %14, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.fiber_s, ptr %16, i32 0, i32 6
  %18 = load i32, ptr %17, align 8, !tbaa !16
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %21, label %20

20:                                               ; preds = %13
  store ptr null, ptr %2, align 8
  br label %44

21:                                               ; preds = %13
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.gravity_vm, ptr %22, i32 0, i32 6
  %24 = load i8, ptr %23, align 8, !tbaa !20, !range !21, !noundef !22
  %25 = trunc i8 %24 to i1
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  store ptr null, ptr %2, align 8
  br label %44

27:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.gravity_vm, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.fiber_s, ptr %30, i32 0, i32 5
  %32 = load ptr, ptr %31, align 8, !tbaa !23
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.gravity_vm, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.fiber_s, ptr %35, i32 0, i32 6
  %37 = load i32, ptr %36, align 8, !tbaa !16
  %38 = sub i32 %37, 1
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds %struct.gravity_callframe_t, ptr %32, i64 %39
  store ptr %40, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.gravity_callframe_t, ptr %41, i32 0, i32 4
  %43 = load ptr, ptr %42, align 8, !tbaa !24
  store ptr %43, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %44

44:                                               ; preds = %27, %26, %20, %12
  %45 = load ptr, ptr %2, align 8
  ret ptr %45
}

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 = { 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 = !{!17, !11, i64 80}
!17 = !{!"fiber_s", !6, i64 0, !18, i64 8, !6, i64 48, !6, i64 56, !11, i64 64, !6, i64 72, !11, i64 80, !11, i64 84, !6, i64 88, !6, i64 96, !13, i64 104, !6, i64 112, !19, i64 120, !11, i64 136, !14, i64 144, !12, i64 152, !12, i64 160}
!18 = !{!"gravity_gc_s", !13, i64 0, !13, i64 1, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!19 = !{!"", !6, i64 0, !7, i64 8}
!20 = !{!10, !13, i64 48}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!17, !6, i64 72}
!24 = !{!25, !6, i64 24}
!25 = !{!"", !6, i64 0, !11, i64 8, !26, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40}
!26 = !{!"short", !7, 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"

%struct.gravity_callframe_t = type { ptr, i32, i16, ptr, ptr, ptr, i8 }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @gravity_vm_getclosure(ptr noundef readonly %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %19, label %2

2:                                                ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not11 = icmp eq ptr %4, null
  br i1 %.not11, label %19, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %4, i64 80
  %7 = load i32, ptr %6, align 8, !tbaa !15
  %.not12 = icmp eq i32 %7, 0
  br i1 %.not12, label %19, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 48
  %10 = load i8, ptr %9, align 8, !tbaa !19, !range !20, !noundef !21
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %19, label %12

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %4, i64 72
  %14 = load ptr, ptr %13, align 8, !tbaa !22
  %15 = add i32 %7, -1
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds %struct.gravity_callframe_t, ptr %14, i64 %16, i32 4
  %18 = load ptr, ptr %17, align 8, !tbaa !23
  br label %19

19:                                               ; preds = %8, %5, %1, %2, %12
  %.0 = phi ptr [ %18, %12 ], [ null, %2 ], [ null, %1 ], [ null, %5 ], [ null, %8 ]
  ret ptr %.0
}

attributes #0 = { 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 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 = !{!16, !10, i64 80}
!16 = !{!"fiber_s", !7, i64 0, !17, i64 8, !7, i64 48, !7, i64 56, !10, i64 64, !7, i64 72, !10, i64 80, !10, i64 84, !7, i64 88, !7, i64 96, !12, i64 104, !7, i64 112, !18, i64 120, !10, i64 136, !13, i64 144, !11, i64 152, !11, i64 160}
!17 = !{!"gravity_gc_s", !12, i64 0, !12, i64 1, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!18 = !{!"", !7, i64 0, !8, i64 8}
!19 = !{!6, !12, i64 48}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!16, !7, i64 72}
!23 = !{!24, !7, i64 24}
!24 = !{!"", !7, i64 0, !10, i64 8, !25, i64 12, !7, i64 16, !7, i64 24, !7, i64 32, !12, i64 40}
!25 = !{!"short", !8, i64 0}


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