; 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_value_t = type { ptr, %union.anon }
%union.anon = type { i64 }
%struct.gravity_function_t = type { ptr, %struct.gravity_gc_s, ptr, ptr, i16, i16, i16, i16, i32, %union.anon.4 }
%struct.gravity_gc_s = type { i8, i8, ptr, ptr, ptr, ptr }
%union.anon.4 = type { %struct.anon.5 }
%struct.anon.5 = type { %struct.gravity_value_r, %struct.gravity_value_r, %struct.gravity_value_r, i32, ptr, ptr, float, i8 }
%struct.gravity_value_r = type { i64, i64, ptr }
%struct.anon.6 = type { i16, [2 x 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

; 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) #2

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_function_size(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @gravity_function_blacken(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca %struct.gravity_value_t, 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_function_size(ptr noundef %9, ptr noundef %10)
  %12 = zext i32 %11 to i64
  call void @gravity_vm_memupdate(ptr noundef %8, i64 noundef %12)
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.gravity_function_t, ptr %13, i32 0, i32 8
  %15 = load i32, ptr %14, align 8, !tbaa !9
  %16 = icmp eq i32 %15, 3
  br i1 %16, label %17, label %46

17:                                               ; preds = %2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.gravity_function_t, ptr %18, i32 0, i32 9
  %20 = getelementptr inbounds %struct.anon.6, ptr %19, i32 0, i32 1
  %21 = getelementptr inbounds [2 x ptr], ptr %20, i64 0, i64 0
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %31

24:                                               ; preds = %17
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.gravity_function_t, ptr %26, i32 0, i32 9
  %28 = getelementptr inbounds %struct.anon.6, ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds [2 x ptr], ptr %28, i64 0, i64 0
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  call void @gravity_gray_object(ptr noundef %25, ptr noundef %30)
  br label %31

31:                                               ; preds = %24, %17
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.gravity_function_t, ptr %32, i32 0, i32 9
  %34 = getelementptr inbounds %struct.anon.6, ptr %33, i32 0, i32 1
  %35 = getelementptr inbounds [2 x ptr], ptr %34, i64 0, i64 1
  %36 = load ptr, ptr %35, align 8, !tbaa !15
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %45

38:                                               ; preds = %31
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.gravity_function_t, ptr %40, i32 0, i32 9
  %42 = getelementptr inbounds %struct.anon.6, ptr %41, i32 0, i32 1
  %43 = getelementptr inbounds [2 x ptr], ptr %42, i64 0, i64 1
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  call void @gravity_gray_object(ptr noundef %39, ptr noundef %44)
  br label %45

45:                                               ; preds = %38, %31
  br label %46

46:                                               ; preds = %45, %2
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.gravity_function_t, ptr %47, i32 0, i32 8
  %49 = load i32, ptr %48, align 8, !tbaa !9
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %51, label %79

51:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.gravity_function_t, ptr %52, i32 0, i32 9
  %54 = getelementptr inbounds %struct.anon.5, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds %struct.gravity_value_r, ptr %54, i32 0, i32 0
  %56 = load i64, ptr %55, align 8, !tbaa !15
  store i64 %56, ptr %5, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 0, ptr %6, align 8, !tbaa !16
  br label %57

57:                                               ; preds = %75, %51
  %58 = load i64, ptr %6, align 8, !tbaa !16
  %59 = load i64, ptr %5, align 8, !tbaa !16
  %60 = icmp ult i64 %58, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %78

62:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.gravity_function_t, ptr %63, i32 0, i32 9
  %65 = getelementptr inbounds %struct.anon.5, ptr %64, i32 0, i32 0
  %66 = getelementptr inbounds %struct.gravity_value_r, ptr %65, i32 0, i32 2
  %67 = load ptr, ptr %66, align 8, !tbaa !15
  %68 = load i64, ptr %6, align 8, !tbaa !16
  %69 = getelementptr inbounds %struct.gravity_value_t, ptr %67, i64 %68
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %69, i64 16, i1 false), !tbaa.struct !18
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8
  %73 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 1
  %74 = load i64, ptr %73, align 8
  call void @gravity_gray_value(ptr noundef %70, ptr %72, i64 %74)
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  br label %75

75:                                               ; preds = %62
  %76 = load i64, ptr %6, align 8, !tbaa !16
  %77 = add i64 %76, 1
  store i64 %77, ptr %6, align 8, !tbaa !16
  br label %57, !llvm.loop !19

78:                                               ; preds = %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %79

79:                                               ; preds = %78, %46
  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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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, !14, i64 72}
!10 = !{!"", !6, i64 0, !11, i64 8, !6, i64 48, !6, i64 56, !13, i64 64, !13, i64 66, !13, i64 68, !13, i64 70, !14, i64 72, !7, i64 80}
!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 = !{!"short", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{i64 0, i64 8, !5, i64 8, i64 8, !15}
!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_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_function_size(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @gravity_function_blacken(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call i32 @gravity_function_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 72
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i32 %6, 3
  br i1 %7, label %8, label %16

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %1, i64 88
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %12, label %11

11:                                               ; preds = %8
  tail call void @gravity_gray_object(ptr noundef %0, ptr noundef nonnull %10) #2
  br label %12

12:                                               ; preds = %11, %8
  %13 = getelementptr inbounds i8, ptr %1, i64 96
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %.not19 = icmp eq ptr %14, null
  br i1 %.not19, label %thread-pre-split, label %15

15:                                               ; preds = %12
  tail call void @gravity_gray_object(ptr noundef %0, ptr noundef nonnull %14) #2
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %15, %12
  %.pr = load i32, ptr %5, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %thread-pre-split, %2
  %17 = phi i32 [ %.pr, %thread-pre-split ], [ %6, %2 ]
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %.loopexit

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %1, i64 80
  %21 = load i64, ptr %20, align 8, !tbaa !14
  %.not21 = icmp eq i64 %21, 0
  br i1 %.not21, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %19
  %22 = getelementptr inbounds i8, ptr %1, i64 96
  br label %23

23:                                               ; preds = %.lr.ph, %23
  %.020 = phi i64 [ 0, %.lr.ph ], [ %26, %23 ]
  %24 = load ptr, ptr %22, align 8, !tbaa !14
  %25 = getelementptr inbounds %struct.gravity_value_t, ptr %24, i64 %.020
  %.sroa.0.0.copyload = load ptr, ptr %25, align 8, !tbaa !15
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %25, i64 8
  %.sroa.4.0.copyload = load i64, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !14
  tail call void @gravity_gray_value(ptr noundef %0, ptr %.sroa.0.0.copyload, i64 %.sroa.4.0.copyload) #2
  %26 = add nuw i64 %.020, 1
  %exitcond.not = icmp eq i64 %26, %21
  br i1 %exitcond.not, label %.loopexit, label %23, !llvm.loop !16

.loopexit:                                        ; preds = %23, %19, %16
  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, !13, i64 72}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 48, !7, i64 56, !12, i64 64, !12, i64 66, !12, i64 68, !12, i64 70, !13, i64 72, !8, i64 80}
!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 = !{!"short", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!8, !8, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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