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

@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: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @gravity_list_new(ptr noundef %0, i32 noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %7 = load i32, ptr %5, align 4, !tbaa !9
  %8 = icmp ugt i32 %7, 4194304
  br i1 %8, label %9, label %10

9:                                                ; preds = %2
  store ptr null, ptr %3, align 8
  br label %52

10:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %11 = call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 72)
  store ptr %11, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr @gravity_class_list, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.gravity_list_t, ptr %13, i32 0, i32 0
  store ptr %12, ptr %14, align 8, !tbaa !11
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.gravity_list_t, ptr %15, i32 0, i32 2
  %17 = getelementptr inbounds %struct.gravity_value_r, ptr %16, i32 0, i32 1
  store i64 0, ptr %17, align 8, !tbaa !17
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.gravity_list_t, ptr %18, i32 0, i32 2
  %20 = getelementptr inbounds %struct.gravity_value_r, ptr %19, i32 0, i32 0
  store i64 0, ptr %20, align 8, !tbaa !18
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.gravity_list_t, ptr %21, i32 0, i32 2
  %23 = getelementptr inbounds %struct.gravity_value_r, ptr %22, i32 0, i32 2
  store ptr null, ptr %23, align 8, !tbaa !19
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = add i32 %24, 8
  %26 = zext i32 %25 to i64
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.gravity_list_t, ptr %27, i32 0, i32 2
  %29 = getelementptr inbounds %struct.gravity_value_r, ptr %28, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !17
  %31 = add i64 %30, %26
  store i64 %31, ptr %29, align 8, !tbaa !17
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.gravity_list_t, ptr %32, i32 0, i32 2
  %34 = getelementptr inbounds %struct.gravity_value_r, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !19
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.gravity_list_t, ptr %36, i32 0, i32 2
  %38 = getelementptr inbounds %struct.gravity_value_r, ptr %37, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !17
  %40 = mul i64 16, %39
  %41 = call ptr @realloc(ptr noundef %35, i64 noundef %40) #5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.gravity_list_t, ptr %42, i32 0, i32 2
  %44 = getelementptr inbounds %struct.gravity_value_r, ptr %43, i32 0, i32 2
  store ptr %41, ptr %44, align 8, !tbaa !19
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %50

47:                                               ; preds = %10
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  call void @gravity_vm_transfer(ptr noundef %48, ptr noundef %49)
  br label %50

50:                                               ; preds = %47, %10
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %51, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %52

52:                                               ; preds = %50, %9
  %53 = load ptr, ptr %3, align 8
  ret ptr %53
}

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 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 #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 }
attributes #5 = { 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}


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

@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: nounwind uwtable
define dso_local noundef ptr @gravity_list_new(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = icmp ugt i32 %1, 4194304
  br i1 %3, label %14, label %4

4:                                                ; preds = %2
  %5 = tail call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 72) #3
  %6 = load ptr, ptr @gravity_class_list, align 8, !tbaa !5
  store ptr %6, ptr %5, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %5, i64 48
  %8 = getelementptr inbounds i8, ptr %5, i64 56
  %9 = getelementptr inbounds i8, ptr %5, i64 64
  %10 = add nuw nsw i32 %1, 8
  %11 = zext nneg i32 %10 to i64
  store i64 0, ptr %7, align 8
  store i64 %11, ptr %8, align 8, !tbaa !15
  %12 = shl nuw nsw i64 %11, 4
  %malloc = tail call ptr @malloc(i64 %12)
  store ptr %malloc, ptr %9, align 8, !tbaa !16
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %14, label %13

13:                                               ; preds = %4
  tail call void @gravity_vm_transfer(ptr noundef nonnull %0, ptr noundef nonnull %5) #3
  br label %14

14:                                               ; preds = %4, %13, %2
  %.0 = phi ptr [ null, %2 ], [ %5, %13 ], [ %5, %4 ]
  ret ptr %.0
}

; Function Attrs: nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

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 = { nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
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 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 56}
!16 = !{!10, !6, i64 64}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass