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

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

; Function Attrs: nounwind uwtable
define dso_local void @markObject(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %6

5:                                                ; preds = %1
  br label %44

6:                                                ; preds = %1
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.sObj, ptr %7, i32 0, i32 1
  %9 = load i8, ptr %8, align 4, !tbaa !9, !range !13, !noundef !14
  %10 = trunc i8 %9 to i1
  br i1 %10, label %11, label %12

11:                                               ; preds = %6
  br label %44

12:                                               ; preds = %6
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.sObj, ptr %13, i32 0, i32 1
  store i8 1, ptr %14, align 4, !tbaa !9
  %15 = load i32, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 12), align 4, !tbaa !15
  %16 = load i32, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 11), align 8, !tbaa !19
  %17 = add nsw i32 %16, 1
  %18 = icmp slt i32 %15, %17
  br i1 %18, label %19, label %37

19:                                               ; preds = %12
  %20 = load i32, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 12), align 4, !tbaa !15
  %21 = icmp slt i32 %20, 8
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  br label %26

23:                                               ; preds = %19
  %24 = load i32, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 12), align 4, !tbaa !15
  %25 = mul nsw i32 %24, 2
  br label %26

26:                                               ; preds = %23, %22
  %27 = phi i32 [ 8, %22 ], [ %25, %23 ]
  store i32 %27, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 12), align 4, !tbaa !15
  %28 = load ptr, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 13), align 8, !tbaa !20
  %29 = load i32, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 12), align 4, !tbaa !15
  %30 = sext i32 %29 to i64
  %31 = mul i64 8, %30
  %32 = call ptr @realloc(ptr noundef %28, i64 noundef %31) #3
  store ptr %32, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 13), align 8, !tbaa !20
  %33 = load ptr, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 13), align 8, !tbaa !20
  %34 = icmp eq ptr %33, null
  br i1 %34, label %35, label %36

35:                                               ; preds = %26
  call void @exit(i32 noundef 1) #4
  unreachable

36:                                               ; preds = %26
  br label %37

37:                                               ; preds = %36, %12
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = load ptr, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 13), align 8, !tbaa !20
  %40 = load i32, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 11), align 8, !tbaa !19
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr getelementptr inbounds (%struct.VM, ptr @vm, i32 0, i32 11), align 8, !tbaa !19
  %42 = sext i32 %40 to i64
  %43 = getelementptr inbounds ptr, ptr %39, i64 %42
  store ptr %38, ptr %43, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %37, %11, %5
  ret void
}

attributes #0 = { 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 #1 = { 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 #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 allocsize(1) }
attributes #4 = { 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, !12, i64 4}
!10 = !{!"sObj", !11, i64 0, !12, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !11, i64 263772}
!16 = !{!"", !7, i64 0, !11, i64 1536, !7, i64 1544, !6, i64 263688, !17, i64 263696, !17, i64 263712, !6, i64 263728, !6, i64 263736, !18, i64 263744, !18, i64 263752, !6, i64 263760, !11, i64 263768, !11, i64 263772, !6, i64 263776}
!17 = !{!"", !11, i64 0, !11, i64 4, !6, i64 8}
!18 = !{!"long", !7, i64 0}
!19 = !{!16, !11, i64 263768}
!20 = !{!16, !6, 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("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @markObject(ptr noundef %0) local_unnamed_addr #2 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %25, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load i8, ptr %4, align 4, !tbaa !5, !range !12, !noundef !13
  %6 = trunc nuw i8 %5 to i1
  br i1 %6, label %25, label %7

7:                                                ; preds = %3
  store i8 1, ptr %4, align 4, !tbaa !5
  %8 = load i32, ptr getelementptr inbounds (i8, ptr @vm, i64 263772), align 4
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @vm, i64 263768), align 8, !tbaa !14
  %.not = icmp sgt i32 %8, %9
  %.pre = load ptr, ptr getelementptr inbounds (i8, ptr @vm, i64 263776), align 8, !tbaa !18
  br i1 %.not, label %19, label %10

10:                                               ; preds = %7
  %11 = icmp slt i32 %8, 8
  %12 = shl nsw i32 %8, 1
  %13 = select i1 %11, i32 8, i32 %12
  store i32 %13, ptr getelementptr inbounds (i8, ptr @vm, i64 263772), align 4, !tbaa !19
  %14 = sext i32 %13 to i64
  %15 = shl nsw i64 %14, 3
  %16 = tail call ptr @realloc(ptr noundef %.pre, i64 noundef %15) #3
  store ptr %16, ptr getelementptr inbounds (i8, ptr @vm, i64 263776), align 8, !tbaa !18
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %._crit_edge

._crit_edge:                                      ; preds = %10
  %.pre5 = load i32, ptr getelementptr inbounds (i8, ptr @vm, i64 263768), align 8, !tbaa !14
  br label %19

18:                                               ; preds = %10
  tail call void @exit(i32 noundef 1) #4
  unreachable

19:                                               ; preds = %._crit_edge, %7
  %20 = phi i32 [ %.pre5, %._crit_edge ], [ %9, %7 ]
  %21 = phi ptr [ %16, %._crit_edge ], [ %.pre, %7 ]
  %22 = add nsw i32 %20, 1
  store i32 %22, ptr getelementptr inbounds (i8, ptr @vm, i64 263768), align 8, !tbaa !14
  %23 = sext i32 %20 to i64
  %24 = getelementptr inbounds ptr, ptr %21, i64 %23
  store ptr %0, ptr %24, align 8, !tbaa !20
  br label %25

25:                                               ; preds = %3, %1, %19
  ret void
}

attributes #0 = { 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 #1 = { 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 #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 allocsize(1) }
attributes #4 = { 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, !10, i64 4}
!6 = !{!"sObj", !7, i64 0, !10, i64 4, !11, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!15, !7, i64 263768}
!15 = !{!"", !8, i64 0, !7, i64 1536, !8, i64 1544, !11, i64 263688, !16, i64 263696, !16, i64 263712, !11, i64 263728, !11, i64 263736, !17, i64 263744, !17, i64 263752, !11, i64 263760, !7, i64 263768, !7, i64 263772, !11, i64 263776}
!16 = !{!"", !7, i64 0, !7, i64 4, !11, i64 8}
!17 = !{!"long", !8, i64 0}
!18 = !{!15, !11, i64 263776}
!19 = !{!15, !7, i64 263772}
!20 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass