; LLVM IR from marcobambini/gravity :: src/shared (gravity_value)

; 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.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 }
%struct.upvalue_s = type { ptr, %struct.gravity_gc_s, ptr, %struct.gravity_value_t, 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

declare void @gravity_vm_memupdate(ptr noundef, i64 noundef) #1

declare void @gravity_gray_object(ptr noundef, ptr noundef) #1

declare void @gravity_gray_value(ptr noundef, ptr, i64) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @gravity_fiber_size(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @gravity_fiber_blacken(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call i32 @gravity_fiber_size(ptr noundef %9, ptr noundef %10)
  %12 = zext i32 %11 to i64
  call void @gravity_vm_memupdate(ptr noundef %8, i64 noundef %12)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %39, %2
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.fiber_s, ptr %15, i32 0, i32 6
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = icmp ult i32 %14, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %42

20:                                               ; preds = %13
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.fiber_s, ptr %22, i32 0, i32 5
  %24 = load ptr, ptr %23, align 8, !tbaa !18
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds %struct.gravity_callframe_t, ptr %24, i64 %26
  %28 = getelementptr inbounds %struct.gravity_callframe_t, ptr %27, i32 0, i32 4
  %29 = load ptr, ptr %28, align 8, !tbaa !19
  call void @gravity_gray_object(ptr noundef %21, ptr noundef %29)
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.fiber_s, ptr %31, i32 0, i32 5
  %33 = load ptr, ptr %32, align 8, !tbaa !18
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds %struct.gravity_callframe_t, ptr %33, i64 %35
  %37 = getelementptr inbounds %struct.gravity_callframe_t, ptr %36, i32 0, i32 3
  %38 = load ptr, ptr %37, align 8, !tbaa !22
  call void @gravity_gray_object(ptr noundef %30, ptr noundef %38)
  br label %39

39:                                               ; preds = %20
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = add i32 %40, 1
  store i32 %41, ptr %5, align 4, !tbaa !9
  br label %13, !llvm.loop !23

42:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.fiber_s, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !25
  store ptr %45, ptr %6, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %60, %42
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.fiber_s, ptr %48, i32 0, i32 3
  %50 = load ptr, ptr %49, align 8, !tbaa !26
  %51 = icmp ult ptr %47, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %63

53:                                               ; preds = %46
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds { ptr, i64 }, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8
  %58 = getelementptr inbounds { ptr, i64 }, ptr %55, i32 0, i32 1
  %59 = load i64, ptr %58, align 8
  call void @gravity_gray_value(ptr noundef %54, ptr %57, i64 %59)
  br label %60

60:                                               ; preds = %53
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.gravity_value_t, ptr %61, i32 1
  store ptr %62, ptr %6, align 8, !tbaa !5
  br label %46, !llvm.loop !27

63:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.fiber_s, ptr %64, i32 0, i32 8
  %66 = load ptr, ptr %65, align 8, !tbaa !28
  store ptr %66, ptr %7, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %70, %63
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %76

70:                                               ; preds = %67
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  call void @gravity_gray_object(ptr noundef %71, ptr noundef %72)
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.upvalue_s, ptr %73, i32 0, i32 4
  %75 = load ptr, ptr %74, align 8, !tbaa !29
  store ptr %75, ptr %7, align 8, !tbaa !5
  br label %67, !llvm.loop !31

76:                                               ; preds = %67
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.fiber_s, ptr %78, i32 0, i32 11
  %80 = load ptr, ptr %79, align 8, !tbaa !32
  call void @gravity_gray_object(ptr noundef %77, ptr noundef %80)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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, !10, i64 80}
!12 = !{!"fiber_s", !6, i64 0, !13, 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, !15, i64 120, !10, i64 136, !16, i64 144, !17, i64 152, !17, i64 160}
!13 = !{!"gravity_gc_s", !14, i64 0, !14, i64 1, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!"", !6, i64 0, !7, i64 8}
!16 = !{!"long", !7, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = !{!12, !6, i64 72}
!19 = !{!20, !6, i64 24}
!20 = !{!"", !6, i64 0, !10, i64 8, !21, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !14, i64 40}
!21 = !{!"short", !7, i64 0}
!22 = !{!20, !6, i64 16}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!12, !6, i64 48}
!26 = !{!12, !6, i64 56}
!27 = distinct !{!27, !24}
!28 = !{!12, !6, i64 88}
!29 = !{!30, !6, i64 72}
!30 = !{!"upvalue_s", !6, i64 0, !13, i64 8, !6, i64 48, !15, i64 56, !6, i64 72}
!31 = distinct !{!31, !24}
!32 = !{!12, !6, i64 112}


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

declare void @gravity_vm_memupdate(ptr noundef, i64 noundef) local_unnamed_addr #0

declare void @gravity_gray_object(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @gravity_gray_value(ptr noundef, ptr, i64) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @gravity_fiber_size(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @gravity_fiber_blacken(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call i32 @gravity_fiber_size(ptr noundef %0, ptr noundef %1)
  %4 = zext i32 %3 to i64
  tail call void @gravity_vm_memupdate(ptr noundef %0, i64 noundef %4) #2
  %5 = getelementptr inbounds i8, ptr %1, i64 80
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %.not37 = icmp eq i32 %6, 0
  br i1 %.not37, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %7 = getelementptr inbounds i8, ptr %1, i64 72
  br label %13

._crit_edge:                                      ; preds = %13, %2
  %8 = getelementptr inbounds i8, ptr %1, i64 48
  %9 = load ptr, ptr %8, align 8, !tbaa !16
  %10 = getelementptr inbounds i8, ptr %1, i64 56
  %11 = load ptr, ptr %10, align 8, !tbaa !17
  %12 = icmp ult ptr %9, %11
  br i1 %12, label %.lr.ph29, label %._crit_edge30

13:                                               ; preds = %.lr.ph, %13
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %13 ]
  %14 = load ptr, ptr %7, align 8, !tbaa !18
  %15 = getelementptr inbounds %struct.gravity_callframe_t, ptr %14, i64 %indvars.iv, i32 4
  %16 = load ptr, ptr %15, align 8, !tbaa !19
  tail call void @gravity_gray_object(ptr noundef %0, ptr noundef %16) #2
  %17 = load ptr, ptr %7, align 8, !tbaa !18
  %18 = getelementptr inbounds %struct.gravity_callframe_t, ptr %17, i64 %indvars.iv, i32 3
  %19 = load ptr, ptr %18, align 8, !tbaa !22
  tail call void @gravity_gray_object(ptr noundef %0, ptr noundef %19) #2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = load i32, ptr %5, align 8, !tbaa !5
  %21 = zext i32 %20 to i64
  %22 = icmp ult i64 %indvars.iv.next, %21
  br i1 %22, label %13, label %._crit_edge, !llvm.loop !23

._crit_edge30:                                    ; preds = %.lr.ph29, %._crit_edge
  %23 = getelementptr inbounds i8, ptr %1, i64 88
  %.031 = load ptr, ptr %23, align 8, !tbaa !25
  %.not32 = icmp eq ptr %.031, null
  br i1 %.not32, label %._crit_edge36, label %.lr.ph35

.lr.ph29:                                         ; preds = %._crit_edge, %.lr.ph29
  %.02427 = phi ptr [ %27, %.lr.ph29 ], [ %9, %._crit_edge ]
  %24 = load ptr, ptr %.02427, align 8
  %25 = getelementptr inbounds i8, ptr %.02427, i64 8
  %26 = load i64, ptr %25, align 8
  tail call void @gravity_gray_value(ptr noundef %0, ptr %24, i64 %26) #2
  %27 = getelementptr inbounds i8, ptr %.02427, i64 16
  %28 = load ptr, ptr %10, align 8, !tbaa !17
  %29 = icmp ult ptr %27, %28
  br i1 %29, label %.lr.ph29, label %._crit_edge30, !llvm.loop !26

.lr.ph35:                                         ; preds = %._crit_edge30, %.lr.ph35
  %.033 = phi ptr [ %.0, %.lr.ph35 ], [ %.031, %._crit_edge30 ]
  tail call void @gravity_gray_object(ptr noundef %0, ptr noundef nonnull %.033) #2
  %30 = getelementptr inbounds i8, ptr %.033, i64 72
  %.0 = load ptr, ptr %30, align 8, !tbaa !25
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge36, label %.lr.ph35, !llvm.loop !27

._crit_edge36:                                    ; preds = %.lr.ph35, %._crit_edge30
  %31 = getelementptr inbounds i8, ptr %1, i64 112
  %32 = load ptr, ptr %31, align 8, !tbaa !28
  tail call void @gravity_gray_object(ptr noundef %0, ptr noundef %32) #2
  ret void
}

attributes #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 = { 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, !12, i64 80}
!6 = !{!"fiber_s", !7, i64 0, !10, i64 8, !7, i64 48, !7, i64 56, !12, i64 64, !7, i64 72, !12, i64 80, !12, i64 84, !7, i64 88, !7, i64 96, !11, i64 104, !7, i64 112, !13, i64 120, !12, i64 136, !14, i64 144, !15, i64 152, !15, i64 160}
!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 = !{!"", !7, i64 0, !8, i64 8}
!14 = !{!"long", !8, i64 0}
!15 = !{!"double", !8, i64 0}
!16 = !{!6, !7, i64 48}
!17 = !{!6, !7, i64 56}
!18 = !{!6, !7, i64 72}
!19 = !{!20, !7, i64 24}
!20 = !{!"", !7, i64 0, !12, i64 8, !21, i64 12, !7, i64 16, !7, i64 24, !7, i64 32, !11, i64 40}
!21 = !{!"short", !8, i64 0}
!22 = !{!20, !7, i64 16}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!7, !7, i64 0}
!26 = distinct !{!26, !24}
!27 = distinct !{!27, !24}
!28 = !{!6, !7, i64 112}


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