; 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_list_t = type { ptr, %struct.gravity_gc_s, %struct.gravity_value_r }
%struct.gravity_gc_s = type { i8, i8, ptr, ptr, ptr, ptr }
%struct.gravity_value_r = type { i64, i64, ptr }
%struct.gravity_value_t = type { ptr, %union.anon }
%union.anon = type { i64 }

@gravity_class_list = external global ptr, align 8

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare ptr @gravity_calloc(ptr noundef, i64 noundef, i64 noundef) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; 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

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local ptr @gravity_list_from_array(ptr noundef %0, i32 noundef %1, ptr noundef %2) #4 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %9 = call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 72)
  store ptr %9, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr @gravity_class_list, align 8, !tbaa !5
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.gravity_list_t, ptr %11, i32 0, i32 0
  store ptr %10, ptr %12, align 8, !tbaa !11
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.gravity_list_t, ptr %13, i32 0, i32 2
  %15 = getelementptr inbounds %struct.gravity_value_r, ptr %14, i32 0, i32 1
  store i64 0, ptr %15, align 8, !tbaa !17
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.gravity_list_t, ptr %16, i32 0, i32 2
  %18 = getelementptr inbounds %struct.gravity_value_r, ptr %17, i32 0, i32 0
  store i64 0, ptr %18, align 8, !tbaa !18
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.gravity_list_t, ptr %19, i32 0, i32 2
  %21 = getelementptr inbounds %struct.gravity_value_r, ptr %20, i32 0, i32 2
  store ptr null, ptr %21, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store i64 0, ptr %8, align 8, !tbaa !20
  br label %22

22:                                               ; preds = %83, %3
  %23 = load i64, ptr %8, align 8, !tbaa !20
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = icmp ult i64 %23, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %86

28:                                               ; preds = %22
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.gravity_list_t, ptr %29, i32 0, i32 2
  %31 = getelementptr inbounds %struct.gravity_value_r, ptr %30, i32 0, i32 0
  %32 = load i64, ptr %31, align 8, !tbaa !18
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.gravity_list_t, ptr %33, i32 0, i32 2
  %35 = getelementptr inbounds %struct.gravity_value_r, ptr %34, i32 0, i32 1
  %36 = load i64, ptr %35, align 8, !tbaa !17
  %37 = icmp eq i64 %32, %36
  br i1 %37, label %38, label %69

38:                                               ; preds = %28
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.gravity_list_t, ptr %39, i32 0, i32 2
  %41 = getelementptr inbounds %struct.gravity_value_r, ptr %40, i32 0, i32 1
  %42 = load i64, ptr %41, align 8, !tbaa !17
  %43 = icmp ne i64 %42, 0
  br i1 %43, label %44, label %50

44:                                               ; preds = %38
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.gravity_list_t, ptr %45, i32 0, i32 2
  %47 = getelementptr inbounds %struct.gravity_value_r, ptr %46, i32 0, i32 1
  %48 = load i64, ptr %47, align 8, !tbaa !17
  %49 = shl i64 %48, 1
  br label %51

50:                                               ; preds = %38
  br label %51

51:                                               ; preds = %50, %44
  %52 = phi i64 [ %49, %44 ], [ 8, %50 ]
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.gravity_list_t, ptr %53, i32 0, i32 2
  %55 = getelementptr inbounds %struct.gravity_value_r, ptr %54, i32 0, i32 1
  store i64 %52, ptr %55, align 8, !tbaa !17
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.gravity_list_t, ptr %56, i32 0, i32 2
  %58 = getelementptr inbounds %struct.gravity_value_r, ptr %57, i32 0, i32 2
  %59 = load ptr, ptr %58, align 8, !tbaa !19
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.gravity_list_t, ptr %60, i32 0, i32 2
  %62 = getelementptr inbounds %struct.gravity_value_r, ptr %61, i32 0, i32 1
  %63 = load i64, ptr %62, align 8, !tbaa !17
  %64 = mul i64 16, %63
  %65 = call ptr @realloc(ptr noundef %59, i64 noundef %64) #6
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.gravity_list_t, ptr %66, i32 0, i32 2
  %68 = getelementptr inbounds %struct.gravity_value_r, ptr %67, i32 0, i32 2
  store ptr %65, ptr %68, align 8, !tbaa !19
  br label %69

69:                                               ; preds = %51, %28
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.gravity_list_t, ptr %70, i32 0, i32 2
  %72 = getelementptr inbounds %struct.gravity_value_r, ptr %71, i32 0, i32 2
  %73 = load ptr, ptr %72, align 8, !tbaa !19
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.gravity_list_t, ptr %74, i32 0, i32 2
  %76 = getelementptr inbounds %struct.gravity_value_r, ptr %75, i32 0, i32 0
  %77 = load i64, ptr %76, align 8, !tbaa !18
  %78 = add i64 %77, 1
  store i64 %78, ptr %76, align 8, !tbaa !18
  %79 = getelementptr inbounds %struct.gravity_value_t, ptr %73, i64 %77
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = load i64, ptr %8, align 8, !tbaa !20
  %82 = getelementptr inbounds %struct.gravity_value_t, ptr %80, i64 %81
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %79, ptr align 8 %82, i64 16, i1 false), !tbaa.struct !21
  br label %83

83:                                               ; preds = %69
  %84 = load i64, ptr %8, align 8, !tbaa !20
  %85 = add i64 %84, 1
  store i64 %85, ptr %8, align 8, !tbaa !20
  br label %22, !llvm.loop !23

86:                                               ; preds = %27
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = icmp ne ptr %87, null
  br i1 %88, label %89, label %92

89:                                               ; preds = %86
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  call void @gravity_vm_transfer(ptr noundef %90, ptr noundef %91)
  br label %92

92:                                               ; preds = %89, %86
  %93 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret ptr %93
}

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 allocsize(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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(1) }

!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, !6, i64 0}
!12 = !{!"", !6, i64 0, !13, i64 8, !15, i64 48}
!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 = !{!"", !16, i64 0, !16, i64 8, !6, i64 16}
!16 = !{!"long", !7, i64 0}
!17 = !{!12, !16, i64 56}
!18 = !{!12, !16, i64 48}
!19 = !{!12, !6, i64 64}
!20 = !{!16, !16, i64 0}
!21 = !{i64 0, i64 8, !5, i64 8, i64 8, !22}
!22 = !{!7, !7, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"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 }

@gravity_class_list = external local_unnamed_addr global ptr, align 8

declare ptr @gravity_calloc(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress 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) #1

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @gravity_list_from_array(ptr noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #3 {
  %4 = tail call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 72) #5
  %5 = load ptr, ptr @gravity_class_list, align 8, !tbaa !5
  store ptr %5, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %4, i64 48
  %7 = getelementptr inbounds i8, ptr %4, i64 56
  %8 = getelementptr inbounds i8, ptr %4, i64 64
  %9 = zext i32 %1 to i64
  %.not26 = icmp eq i32 %1, 0
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %6, i8 0, i64 24, i1 false)
  br i1 %.not26, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %17, %3
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %25, label %24

.lr.ph:                                           ; preds = %3, %17
  %.025 = phi i64 [ %23, %17 ], [ 0, %3 ]
  %10 = load i64, ptr %6, align 8, !tbaa !15
  %11 = load i64, ptr %7, align 8, !tbaa !16
  %12 = icmp eq i64 %10, %11
  %.pre = load ptr, ptr %8, align 8, !tbaa !17
  br i1 %12, label %13, label %17

13:                                               ; preds = %.lr.ph
  %.not24 = icmp eq i64 %10, 0
  %14 = shl i64 %10, 1
  %spec.select = select i1 %.not24, i64 8, i64 %14
  store i64 %spec.select, ptr %7, align 8, !tbaa !16
  %15 = shl i64 %spec.select, 4
  %16 = tail call ptr @realloc(ptr noundef %.pre, i64 noundef %15) #6
  store ptr %16, ptr %8, align 8, !tbaa !17
  %.pre27 = load i64, ptr %6, align 8, !tbaa !15
  br label %17

17:                                               ; preds = %13, %.lr.ph
  %18 = phi i64 [ %.pre27, %13 ], [ %10, %.lr.ph ]
  %19 = phi ptr [ %16, %13 ], [ %.pre, %.lr.ph ]
  %20 = add i64 %18, 1
  store i64 %20, ptr %6, align 8, !tbaa !15
  %21 = getelementptr inbounds %struct.gravity_value_t, ptr %19, i64 %18
  %22 = getelementptr inbounds %struct.gravity_value_t, ptr %2, i64 %.025
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %21, ptr noundef nonnull align 8 dereferenceable(16) %22, i64 16, i1 false), !tbaa.struct !18
  %23 = add nuw nsw i64 %.025, 1
  %exitcond.not = icmp eq i64 %23, %9
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !20

24:                                               ; preds = %._crit_edge
  tail call void @gravity_vm_transfer(ptr noundef nonnull %0, ptr noundef nonnull %4) #5
  br label %25

25:                                               ; preds = %24, %._crit_edge
  ret ptr %4
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(1) }

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


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