; LLVM IR from evanxg852000/rockstartdev :: clox (memory)

; 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.VM = type { [64 x %struct.CallFrame], i32, [16384 x %struct.Value], ptr, %struct.Table, %struct.Table, ptr, ptr, i64, i64, ptr, i32, i32, ptr }
%struct.CallFrame = type { ptr, ptr, ptr }
%struct.Value = type { i32, %union.anon }
%union.anon = type { double }
%struct.Table = type { i32, i32, ptr }

@vm = external global %struct.VM, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @reallocate(ptr noundef %0, i64 noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  %9 = load i64, ptr %7, align 8, !tbaa !9
  %10 = load i64, ptr %6, align 8, !tbaa !9
  %11 = sub i64 %9, %10
  %12 = load i64, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 8), align 8, !tbaa !11
  %13 = add i64 %12, %11
  store i64 %13, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 8), align 8, !tbaa !11
  %14 = load i64, ptr %7, align 8, !tbaa !9
  %15 = load i64, ptr %6, align 8, !tbaa !9
  %16 = icmp ugt i64 %14, %15
  br i1 %16, label %17, label %23

17:                                               ; preds = %3
  %18 = load i64, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 8), align 8, !tbaa !11
  %19 = load i64, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 9), align 8, !tbaa !15
  %20 = icmp ugt i64 %18, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %17
  call void @collectGarbage()
  br label %22

22:                                               ; preds = %21, %17
  br label %23

23:                                               ; preds = %22, %3
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = icmp eq i64 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %23
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %27) #5
  store ptr null, ptr %4, align 8
  br label %37

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i64, ptr %7, align 8, !tbaa !9
  %31 = call ptr @realloc(ptr noundef %29, i64 noundef %30) #6
  store ptr %31, ptr %8, align 8, !tbaa !5
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = icmp eq ptr %32, null
  br i1 %33, label %34, label %35

34:                                               ; preds = %28
  call void @exit(i32 noundef 1) #7
  unreachable

35:                                               ; preds = %28
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %36, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %37

37:                                               ; preds = %35, %26
  %38 = load ptr, ptr %4, align 8
  ret ptr %38
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

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

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

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

; Function Attrs: nounwind uwtable
declare dso_local void @collectGarbage() #0

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" }
attributes #1 = { nounwind "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 nosync 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 = { noreturn nounwind "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) }
attributes #7 = { noreturn 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 263744}
!12 = !{!"", !7, i64 0, !13, i64 1536, !7, i64 1544, !6, i64 263688, !14, i64 263696, !14, i64 263712, !6, i64 263728, !6, i64 263736, !10, i64 263744, !10, i64 263752, !6, i64 263760, !13, i64 263768, !13, i64 263772, !6, i64 263776}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !13, i64 0, !13, i64 4, !6, i64 8}
!15 = !{!12, !10, i64 263752}


; 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.VM = type { [64 x %struct.CallFrame], i32, [16384 x %struct.Value], ptr, %struct.Table, %struct.Table, ptr, ptr, i64, i64, ptr, i32, i32, ptr }
%struct.CallFrame = type { ptr, ptr, ptr }
%struct.Value = type { i32, %union.anon }
%union.anon = type { double }
%struct.Table = type { i32, i32, ptr }

@vm = external local_unnamed_addr global %struct.VM, align 8

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @reallocate(ptr nocapture noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = sub i64 %2, %1
  %5 = load i64, ptr getelementptr inbounds (i8, ptr @vm, i64 263744), align 8, !tbaa !5
  %6 = add i64 %5, %4
  store i64 %6, ptr getelementptr inbounds (i8, ptr @vm, i64 263744), align 8, !tbaa !5
  %7 = icmp ugt i64 %2, %1
  %8 = load i64, ptr getelementptr inbounds (i8, ptr @vm, i64 263752), align 8
  %9 = icmp ugt i64 %6, %8
  %or.cond = select i1 %7, i1 %9, i1 false
  br i1 %or.cond, label %.thread, label %10

.thread:                                          ; preds = %3
  tail call void @collectGarbage()
  br label %13

10:                                               ; preds = %3
  %11 = icmp eq i64 %2, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %10
  tail call void @free(ptr noundef %0) #4
  br label %17

13:                                               ; preds = %.thread, %10
  %14 = tail call ptr @realloc(ptr noundef %0, i64 noundef %2) #5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  tail call void @exit(i32 noundef 1) #6
  unreachable

17:                                               ; preds = %13, %12
  %.0 = phi ptr [ null, %12 ], [ %14, %13 ]
  ret ptr %.0
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #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: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @collectGarbage() local_unnamed_addr #0

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" }
attributes #1 = { mustprogress nounwind willreturn allockind("free") 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 #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 = { noreturn nounwind "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) }
attributes #6 = { noreturn 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, !12, i64 263744}
!6 = !{!"", !7, i64 0, !9, i64 1536, !7, i64 1544, !10, i64 263688, !11, i64 263696, !11, i64 263712, !10, i64 263728, !10, i64 263736, !12, i64 263744, !12, i64 263752, !10, i64 263760, !9, i64 263768, !9, i64 263772, !10, i64 263776}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!"", !9, i64 0, !9, i64 4, !10, i64 8}
!12 = !{!"long", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass