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

; 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 i32 @string_size(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gravity_fiber_size(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
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.gravity_class_s, ptr %7, i32 0, i32 1
  %9 = getelementptr inbounds %struct.gravity_gc_s, ptr %8, i32 0, i32 1
  store i8 1, ptr %9, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 168, ptr %5, align 4, !tbaa !14
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.fiber_s, ptr %10, i32 0, i32 4
  %12 = load i32, ptr %11, align 8, !tbaa !15
  %13 = zext i32 %12 to i64
  %14 = mul i64 %13, 16
  %15 = load i32, ptr %5, align 4, !tbaa !14
  %16 = zext i32 %15 to i64
  %17 = add i64 %16, %14
  %18 = trunc i64 %17 to i32
  store i32 %18, ptr %5, align 4, !tbaa !14
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.fiber_s, ptr %19, i32 0, i32 7
  %21 = load i32, ptr %20, align 4, !tbaa !20
  %22 = zext i32 %21 to i64
  %23 = mul i64 %22, 48
  %24 = load i32, ptr %5, align 4, !tbaa !14
  %25 = zext i32 %24 to i64
  %26 = add i64 %25, %23
  %27 = trunc i64 %26 to i32
  store i32 %27, ptr %5, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.fiber_s, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !21
  store ptr %30, ptr %6, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %48, %2
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.fiber_s, ptr %33, i32 0, i32 3
  %35 = load ptr, ptr %34, align 8, !tbaa !22
  %36 = icmp ult ptr %32, %35
  br i1 %36, label %38, label %37

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

38:                                               ; preds = %31
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds { ptr, i64 }, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8
  %43 = getelementptr inbounds { ptr, i64 }, ptr %40, i32 0, i32 1
  %44 = load i64, ptr %43, align 8
  %45 = call i32 @gravity_value_size(ptr noundef %39, ptr %42, i64 %44)
  %46 = load i32, ptr %5, align 4, !tbaa !14
  %47 = add i32 %46, %45
  store i32 %47, ptr %5, align 4, !tbaa !14
  br label %48

48:                                               ; preds = %38
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.gravity_value_t, ptr %49, i32 1
  store ptr %50, ptr %6, align 8, !tbaa !5
  br label %31, !llvm.loop !23

51:                                               ; preds = %37
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.fiber_s, ptr %52, i32 0, i32 9
  %54 = load ptr, ptr %53, align 8, !tbaa !25
  %55 = call i32 @string_size(ptr noundef %54)
  %56 = load i32, ptr %5, align 4, !tbaa !14
  %57 = add i32 %56, %55
  store i32 %57, ptr %5, align 4, !tbaa !14
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.fiber_s, ptr %59, i32 0, i32 11
  %61 = load ptr, ptr %60, align 8, !tbaa !26
  %62 = call i32 @gravity_object_size(ptr noundef %58, ptr noundef %61)
  %63 = load i32, ptr %5, align 4, !tbaa !14
  %64 = add i32 %63, %62
  store i32 %64, ptr %5, align 4, !tbaa !14
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.gravity_class_s, ptr %65, i32 0, i32 1
  %67 = getelementptr inbounds %struct.gravity_gc_s, ptr %66, i32 0, i32 1
  store i8 0, ptr %67, align 1, !tbaa !9
  %68 = load i32, ptr %5, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %68
}

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

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

declare i32 @string_size(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gravity_fiber_size(ptr noundef %0, ptr nocapture noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %1, i64 9
  store i8 1, ptr %3, align 1, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %1, i64 64
  %5 = load i32, ptr %4, align 8, !tbaa !13
  %6 = shl i32 %5, 4
  %7 = add i32 %6, 168
  %8 = getelementptr inbounds i8, ptr %1, i64 84
  %9 = load i32, ptr %8, align 4, !tbaa !18
  %10 = mul i32 %9, 48
  %11 = add i32 %7, %10
  %12 = getelementptr inbounds i8, ptr %1, i64 48
  %13 = load ptr, ptr %12, align 8, !tbaa !19
  %14 = getelementptr inbounds i8, ptr %1, i64 56
  %15 = load ptr, ptr %14, align 8, !tbaa !20
  %16 = icmp ult ptr %13, %15
  br i1 %16, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.018.lcssa = phi i32 [ %11, %2 ], [ %29, %.lr.ph ]
  %17 = getelementptr inbounds i8, ptr %1, i64 96
  %18 = load ptr, ptr %17, align 8, !tbaa !21
  %19 = tail call i32 @string_size(ptr noundef %18) #2
  %20 = add i32 %19, %.018.lcssa
  %21 = getelementptr inbounds i8, ptr %1, i64 112
  %22 = load ptr, ptr %21, align 8, !tbaa !22
  %23 = tail call i32 @gravity_object_size(ptr noundef %0, ptr noundef %22)
  %24 = add i32 %20, %23
  store i8 0, ptr %3, align 1, !tbaa !5
  ret i32 %24

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.020 = phi ptr [ %30, %.lr.ph ], [ %13, %2 ]
  %.01819 = phi i32 [ %29, %.lr.ph ], [ %11, %2 ]
  %25 = load ptr, ptr %.020, align 8
  %26 = getelementptr inbounds i8, ptr %.020, i64 8
  %27 = load i64, ptr %26, align 8
  %28 = tail call i32 @gravity_value_size(ptr noundef %0, ptr %25, i64 %27)
  %29 = add i32 %28, %.01819
  %30 = getelementptr inbounds i8, ptr %.020, i64 16
  %31 = load ptr, ptr %14, align 8, !tbaa !20
  %32 = icmp ult ptr %30, %31
  br i1 %32, label %.lr.ph, label %._crit_edge, !llvm.loop !23
}

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

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, !11, i64 9}
!6 = !{!"gravity_class_s", !7, i64 0, !10, i64 8, !7, i64 48, !7, i64 56, !11, i64 64, !11, i64 65, !11, i64 66, !11, i64 67, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !12, i64 104, !7, i64 112}
!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, !12, i64 64}
!14 = !{!"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, !15, i64 120, !12, i64 136, !16, i64 144, !17, i64 152, !17, i64 160}
!15 = !{!"", !7, i64 0, !8, i64 8}
!16 = !{!"long", !8, i64 0}
!17 = !{!"double", !8, i64 0}
!18 = !{!14, !12, i64 84}
!19 = !{!14, !7, i64 48}
!20 = !{!14, !7, i64 56}
!21 = !{!14, !7, i64 96}
!22 = !{!14, !7, i64 112}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass