; 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_value_t = type { ptr, %union.anon }
%union.anon = type { i64 }
%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_callframe_t = type { ptr, i32, i16, ptr, ptr, ptr, i8 }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @gravity_vm_setslot(ptr noundef %0, ptr %1, i64 %2, i32 noundef %3) #2 {
  %5 = alloca %struct.gravity_value_t, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = getelementptr inbounds { ptr, i64 }, ptr %5, i32 0, i32 0
  store ptr %1, ptr %9, align 8
  %10 = getelementptr inbounds { ptr, i64 }, ptr %5, i32 0, i32 1
  store i64 %2, ptr %10, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %3, ptr %7, align 4, !tbaa !9
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.gravity_vm, ptr %11, i32 0, i32 6
  %13 = load i8, ptr %12, align 8, !tbaa !11, !range !17, !noundef !18
  %14 = trunc i8 %13 to i1
  br i1 %14, label %15, label %16

15:                                               ; preds = %4
  br label %44

16:                                               ; preds = %4
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = icmp eq i32 %17, -2
  br i1 %18, label %19, label %24

19:                                               ; preds = %16
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.gravity_vm, ptr %20, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !19
  %23 = getelementptr inbounds %struct.fiber_s, ptr %22, i32 0, i32 12
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %23, ptr align 8 %5, i64 16, i1 false), !tbaa.struct !20
  br label %44

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

44:                                               ; preds = %24, %19, %15
  ret void
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !14, i64 48}
!12 = !{!"gravity_vm", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !13, i64 40, !14, i64 48, !10, i64 52, !10, i64 56, !15, i64 64, !15, i64 72, !10, i64 80, !7, i64 84, !6, i64 152, !6, i64 160, !6, i64 168, !10, i64 176, !15, i64 184, !15, i64 192, !6, i64 200, !15, i64 208, !15, i64 216, !15, i64 224, !13, i64 232, !15, i64 240, !16, i64 248, !16, i64 272}
!13 = !{!"double", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"", !15, i64 0, !15, i64 8, !6, i64 16}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!12, !6, i64 16}
!20 = !{i64 0, i64 8, !5, i64 8, i64 8, !21}
!21 = !{!7, !7, i64 0}
!22 = !{!23, !6, i64 72}
!23 = !{!"fiber_s", !6, i64 0, !24, i64 8, !6, i64 48, !6, i64 56, !10, i64 64, !6, i64 72, !10, i64 80, !10, i64 84, !6, i64 88, !6, i64 96, !14, i64 104, !6, i64 112, !25, i64 120, !10, i64 136, !15, i64 144, !13, i64 152, !13, i64 160}
!24 = !{!"gravity_gc_s", !14, i64 0, !14, i64 1, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!25 = !{!"", !6, i64 0, !7, i64 8}
!26 = !{!23, !10, i64 80}
!27 = !{!28, !6, i64 32}
!28 = !{!"", !6, i64 0, !10, i64 8, !29, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !14, i64 40}
!29 = !{!"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 }
%struct.gravity_value_t = type { ptr, %union.anon }
%union.anon = type { i64 }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @gravity_vm_setslot(ptr nocapture noundef readonly %0, ptr %1, i64 %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = load i8, ptr %5, align 8, !tbaa !5, !range !15, !noundef !16
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %25, label %8

8:                                                ; preds = %4
  %9 = icmp eq i32 %3, -2
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !17
  br i1 %9, label %12, label %14

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %11, i64 120
  store ptr %1, ptr %13, align 8, !tbaa !18
  %.sroa.3.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 128
  br label %.sink.split

14:                                               ; preds = %8
  %15 = getelementptr inbounds i8, ptr %11, i64 72
  %16 = load ptr, ptr %15, align 8, !tbaa !19
  %17 = getelementptr inbounds i8, ptr %11, i64 80
  %18 = load i32, ptr %17, align 8, !tbaa !23
  %19 = add i32 %18, -1
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds %struct.gravity_callframe_t, ptr %16, i64 %20, i32 5
  %22 = load ptr, ptr %21, align 8, !tbaa !24
  %23 = zext i32 %3 to i64
  %24 = getelementptr inbounds %struct.gravity_value_t, ptr %22, i64 %23
  store ptr %1, ptr %24, align 8, !tbaa !18
  %.sroa.3.0..sroa_idx7 = getelementptr inbounds i8, ptr %24, i64 8
  br label %.sink.split

.sink.split:                                      ; preds = %12, %14
  %.sroa.3.0..sroa_idx7.sink = phi ptr [ %.sroa.3.0..sroa_idx7, %14 ], [ %.sroa.3.0..sroa_idx, %12 ]
  store i64 %2, ptr %.sroa.3.0..sroa_idx7.sink, align 8, !tbaa !27
  br label %25

25:                                               ; preds = %.sink.split, %4
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, 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, !12, i64 48}
!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 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!6, !7, i64 16}
!18 = !{!7, !7, i64 0}
!19 = !{!20, !7, i64 72}
!20 = !{!"fiber_s", !7, i64 0, !21, 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, !22, i64 120, !10, i64 136, !13, i64 144, !11, i64 152, !11, i64 160}
!21 = !{!"gravity_gc_s", !12, i64 0, !12, i64 1, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!22 = !{!"", !7, i64 0, !8, i64 8}
!23 = !{!20, !10, i64 80}
!24 = !{!25, !7, i64 32}
!25 = !{!"", !7, i64 0, !10, i64 8, !26, i64 12, !7, i64 16, !7, i64 24, !7, i64 32, !12, i64 40}
!26 = !{!"short", !8, i64 0}
!27 = !{!8, !8, i64 0}


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