; 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_closure_s = type { ptr, %struct.gravity_gc_s, ptr, ptr, ptr, ptr, i32 }
%struct.gravity_gc_s = type { i8, i8, ptr, ptr, ptr, ptr }
%struct.gravity_function_t = type { ptr, %struct.gravity_gc_s, ptr, ptr, i16, i16, i16, i16, i32, %union.anon.0 }
%union.anon.0 = type { %struct.anon }
%struct.anon = 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.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 }

@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @gravity_vm_loadclosure(ptr noundef %0, ptr noundef %1) #0 {
  %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 = getelementptr inbounds %struct.gravity_closure_s, ptr %5, i32 0, i32 3
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = getelementptr inbounds %struct.gravity_function_t, ptr %7, i32 0, i32 3
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  %10 = call i32 @string_cmp(ptr noundef %9, ptr noundef @.str.1)
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  br label %20

13:                                               ; preds = %2
  %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 !17
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  call void @gravity_fiber_reassign(ptr noundef %16, ptr noundef %17, i16 noundef zeroext 0)
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = call zeroext i1 @gravity_vm_exec(ptr noundef %18)
  br label %20

20:                                               ; preds = %13, %12
  ret void
}

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

declare void @gravity_fiber_reassign(ptr noundef, ptr noundef, i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @gravity_vm_exec(ptr noundef) #0

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

!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 56}
!10 = !{!"gravity_closure_s", !6, i64 0, !11, i64 8, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !13, i64 80}
!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 = !{!15, !6, i64 56}
!15 = !{!"", !6, i64 0, !11, i64 8, !6, i64 48, !6, i64 56, !16, i64 64, !16, i64 66, !16, i64 68, !16, i64 70, !13, i64 72, !7, i64 80}
!16 = !{!"short", !7, i64 0}
!17 = !{!18, !6, i64 16}
!18 = !{!"gravity_vm", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !19, i64 40, !12, i64 48, !13, i64 52, !13, i64 56, !20, i64 64, !20, i64 72, !13, i64 80, !7, i64 84, !6, i64 152, !6, i64 160, !6, i64 168, !13, i64 176, !20, i64 184, !20, i64 192, !6, i64 200, !20, i64 208, !20, i64 216, !20, i64 224, !19, i64 232, !20, i64 240, !21, i64 248, !21, i64 272}
!19 = !{!"double", !7, i64 0}
!20 = !{!"long", !7, i64 0}
!21 = !{!"", !20, i64 0, !20, i64 8, !6, i64 16}


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

@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @gravity_vm_loadclosure(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 56
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 56
  %6 = load ptr, ptr %5, align 8, !tbaa !13
  %7 = tail call i32 @string_cmp(ptr noundef %6, ptr noundef nonnull @.str.1) #2
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %12

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !16
  tail call void @gravity_fiber_reassign(ptr noundef %10, ptr noundef nonnull %1, i16 noundef zeroext 0) #2
  %11 = tail call zeroext i1 @gravity_vm_exec(ptr noundef %0)
  br label %12

12:                                               ; preds = %2, %8
  ret void
}

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

declare void @gravity_fiber_reassign(ptr noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @gravity_vm_exec(ptr noundef) local_unnamed_addr #0

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 = { 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 56}
!6 = !{!"gravity_closure_s", !7, i64 0, !10, i64 8, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !12, i64 80}
!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 = !{!14, !7, i64 56}
!14 = !{!"", !7, i64 0, !10, i64 8, !7, i64 48, !7, i64 56, !15, i64 64, !15, i64 66, !15, i64 68, !15, i64 70, !12, i64 72, !8, i64 80}
!15 = !{!"short", !8, i64 0}
!16 = !{!17, !7, i64 16}
!17 = !{!"gravity_vm", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !12, i64 32, !18, i64 40, !11, i64 48, !12, i64 52, !12, i64 56, !19, i64 64, !19, i64 72, !12, i64 80, !8, i64 84, !7, i64 152, !7, i64 160, !7, i64 168, !12, i64 176, !19, i64 184, !19, i64 192, !7, 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", !8, i64 0}
!19 = !{!"long", !8, i64 0}
!20 = !{!"", !19, i64 0, !19, i64 8, !7, i64 16}


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