; 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 }
%struct.sObj = type { i32, i8, ptr }

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @freeObjects() #2 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  %3 = load ptr, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 10), align 8, !tbaa !5
  store ptr %3, ptr %1, align 8, !tbaa !13
  br label %4

4:                                                ; preds = %7, %0
  %5 = load ptr, ptr %1, align 8, !tbaa !13
  %6 = icmp ne ptr %5, null
  br i1 %6, label %7, label %13

7:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %8 = load ptr, ptr %1, align 8, !tbaa !13
  %9 = getelementptr inbounds %struct.sObj, ptr %8, i32 0, i32 2
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  store ptr %10, ptr %2, align 8, !tbaa !13
  %11 = load ptr, ptr %1, align 8, !tbaa !13
  call void @freeObject(ptr noundef %11)
  %12 = load ptr, ptr %2, align 8, !tbaa !13
  store ptr %12, ptr %1, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %4, !llvm.loop !17

13:                                               ; preds = %4
  %14 = load ptr, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 13), align 8, !tbaa !19
  call void @free(ptr noundef %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 263760}
!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}
!13 = !{!10, !10, i64 0}
!14 = !{!15, !10, i64 8}
!15 = !{!"sObj", !9, i64 0, !16, i64 4, !10, i64 8}
!16 = !{!"_Bool", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !10, i64 263776}


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

; Function Attrs: nounwind uwtable
define dso_local void @freeObjects() local_unnamed_addr #1 {
  %1 = load ptr, ptr getelementptr inbounds (i8, ptr @vm, i64 263760), align 8, !tbaa !5
  %.not4 = icmp eq ptr %1, null
  br i1 %.not4, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.05 = phi ptr [ %3, %.lr.ph ], [ %1, %0 ]
  %2 = getelementptr inbounds i8, ptr %.05, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !13
  tail call void @freeObject(ptr noundef nonnull %.05)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %0
  %4 = load ptr, ptr getelementptr inbounds (i8, ptr @vm, i64 263776), align 8, !tbaa !18
  tail call void @free(ptr noundef %4) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @freeObject(ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #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, !10, i64 263760}
!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}
!13 = !{!14, !10, i64 8}
!14 = !{!"sObj", !9, i64 0, !15, i64 4, !10, i64 8}
!15 = !{!"_Bool", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!6, !10, i64 263776}


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