; 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.gravity_list_t = type { ptr, %struct.gravity_gc_s, %struct.gravity_value_r }
%struct.gravity_value_r = type { i64, i64, ptr }
%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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gravity_list_size(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.gravity_class_s, ptr %8, i32 0, i32 1
  %10 = getelementptr inbounds %struct.gravity_gc_s, ptr %9, i32 0, i32 1
  store i8 1, ptr %10, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.gravity_list_t, ptr %11, i32 0, i32 2
  %13 = getelementptr inbounds %struct.gravity_value_r, ptr %12, i32 0, i32 0
  %14 = load i64, ptr %13, align 8, !tbaa !15
  store i64 %14, ptr %6, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !19
  br label %15

15:                                               ; preds = %35, %2
  %16 = load i64, ptr %7, align 8, !tbaa !19
  %17 = load i64, ptr %6, align 8, !tbaa !19
  %18 = icmp ult i64 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %38

20:                                               ; preds = %15
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.gravity_list_t, ptr %22, i32 0, i32 2
  %24 = getelementptr inbounds %struct.gravity_value_r, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !20
  %26 = load i64, ptr %7, align 8, !tbaa !19
  %27 = getelementptr inbounds %struct.gravity_value_t, ptr %25, i64 %26
  %28 = getelementptr inbounds { ptr, i64 }, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8
  %30 = getelementptr inbounds { ptr, i64 }, ptr %27, i32 0, i32 1
  %31 = load i64, ptr %30, align 8
  %32 = call i32 @gravity_value_size(ptr noundef %21, ptr %29, i64 %31)
  %33 = load i32, ptr %5, align 4, !tbaa !14
  %34 = add i32 %33, %32
  store i32 %34, ptr %5, align 4, !tbaa !14
  br label %35

35:                                               ; preds = %20
  %36 = load i64, ptr %7, align 8, !tbaa !19
  %37 = add i64 %36, 1
  store i64 %37, ptr %7, align 8, !tbaa !19
  br label %15, !llvm.loop !21

38:                                               ; preds = %19
  %39 = load i32, ptr %5, align 4, !tbaa !14
  %40 = zext i32 %39 to i64
  %41 = add i64 %40, 72
  %42 = trunc i64 %41 to i32
  store i32 %42, ptr %5, align 4, !tbaa !14
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.gravity_class_s, ptr %43, i32 0, i32 1
  %45 = getelementptr inbounds %struct.gravity_gc_s, ptr %44, i32 0, i32 1
  store i8 0, ptr %45, align 1, !tbaa !9
  %46 = load i32, ptr %5, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %46
}

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, !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, !18, i64 48}
!16 = !{!"", !6, i64 0, !11, i64 8, !17, i64 48}
!17 = !{!"", !18, i64 0, !18, i64 8, !6, i64 16}
!18 = !{!"long", !7, i64 0}
!19 = !{!18, !18, i64 0}
!20 = !{!16, !6, i64 64}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gravity_list_size(ptr noundef %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 9
  store i8 1, ptr %3, align 1, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %1, i64 48
  %5 = load i64, ptr %4, align 8, !tbaa !13
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 64
  br label %8

._crit_edge.loopexit:                             ; preds = %8
  %7 = add i32 %15, 72
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %.011.lcssa = phi i32 [ 72, %2 ], [ %7, %._crit_edge.loopexit ]
  store i8 0, ptr %3, align 1, !tbaa !5
  ret i32 %.011.lcssa

8:                                                ; preds = %.lr.ph, %8
  %.013 = phi i64 [ 0, %.lr.ph ], [ %16, %8 ]
  %.01112 = phi i32 [ 0, %.lr.ph ], [ %15, %8 ]
  %9 = load ptr, ptr %6, align 8, !tbaa !17
  %10 = getelementptr inbounds %struct.gravity_value_t, ptr %9, i64 %.013
  %11 = load ptr, ptr %10, align 8
  %12 = getelementptr inbounds i8, ptr %10, i64 8
  %13 = load i64, ptr %12, align 8
  %14 = tail call i32 @gravity_value_size(ptr noundef %0, ptr %11, i64 %13)
  %15 = add i32 %14, %.01112
  %16 = add nuw i64 %.013, 1
  %exitcond.not = icmp eq i64 %16, %5
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %8, !llvm.loop !18
}

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

!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, !16, i64 48}
!14 = !{!"", !7, i64 0, !10, i64 8, !15, i64 48}
!15 = !{!"", !16, i64 0, !16, i64 8, !7, i64 16}
!16 = !{!"long", !8, i64 0}
!17 = !{!14, !7, i64 64}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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