; 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_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 void @gravity_vm_memupdate(ptr noundef, i64 noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden void @gravity_hash_gray(ptr noundef, ptr, i64, ptr, i64, ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @gravity_class_blacken(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call i32 @gravity_class_size(ptr noundef %7, ptr noundef %8)
  %10 = zext i32 %9 to i64
  call void @gravity_vm_memupdate(ptr noundef %6, i64 noundef %10)
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.gravity_class_s, ptr %12, i32 0, i32 2
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  call void @gravity_gray_object(ptr noundef %11, ptr noundef %14)
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.gravity_class_s, ptr %16, i32 0, i32 9
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  call void @gravity_gray_object(ptr noundef %15, ptr noundef %18)
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.gravity_class_s, ptr %19, i32 0, i32 11
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  call void @gravity_hash_iterate(ptr noundef %21, ptr noundef @gravity_hash_gray, ptr noundef %22)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !16
  br label %23

23:                                               ; preds = %42, %2
  %24 = load i32, ptr %5, align 4, !tbaa !16
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.gravity_class_s, ptr %25, i32 0, i32 12
  %27 = load i32, ptr %26, align 8, !tbaa !17
  %28 = icmp ult i32 %24, %27
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %23
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.gravity_class_s, ptr %32, i32 0, i32 13
  %34 = load ptr, ptr %33, align 8, !tbaa !18
  %35 = load i32, ptr %5, align 4, !tbaa !16
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds %struct.gravity_value_t, ptr %34, i64 %36
  %38 = getelementptr inbounds { ptr, i64 }, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8
  %40 = getelementptr inbounds { ptr, i64 }, ptr %37, i32 0, i32 1
  %41 = load i64, ptr %40, align 8
  call void @gravity_gray_value(ptr noundef %31, ptr %39, i64 %41)
  br label %42

42:                                               ; preds = %30
  %43 = load i32, ptr %5, align 4, !tbaa !16
  %44 = add i32 %43, 1
  store i32 %44, ptr %5, align 4, !tbaa !16
  br label %23, !llvm.loop !19

45:                                               ; preds = %29
  ret void
}

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

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

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, !6, i64 48}
!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 = !{!10, !6, i64 80}
!15 = !{!10, !6, i64 96}
!16 = !{!13, !13, i64 0}
!17 = !{!10, !13, i64 104}
!18 = !{!10, !6, i64 112}
!19 = distinct !{!19, !20}
!20 = !{!"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 }

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

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

; Function Attrs: nounwind uwtable
declare hidden void @gravity_hash_gray(ptr noundef, ptr, i64, ptr, i64, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @gravity_class_blacken(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call i32 @gravity_class_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 48
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  tail call void @gravity_gray_object(ptr noundef %0, ptr noundef %6) #2
  %7 = getelementptr inbounds i8, ptr %1, i64 80
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  tail call void @gravity_gray_object(ptr noundef %0, ptr noundef %8) #2
  %9 = getelementptr inbounds i8, ptr %1, i64 96
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  tail call void @gravity_hash_iterate(ptr noundef %10, ptr noundef nonnull @gravity_hash_gray, ptr noundef %0) #2
  %11 = getelementptr inbounds i8, ptr %1, i64 104
  %12 = load i32, ptr %11, align 8, !tbaa !15
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

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

._crit_edge:                                      ; preds = %14, %2
  ret void

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

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

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, !7, i64 48}
!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 = !{!6, !7, i64 80}
!14 = !{!6, !7, i64 96}
!15 = !{!6, !12, i64 104}
!16 = !{!6, !7, i64 112}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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