; LLVM IR from buzz-lang/Buzz :: src/buzz (buzzheap)

; 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.anon = type { i16, i16 }
%struct.buzzvm_s = type { ptr, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i16, ptr, ptr, ptr, ptr, i32, i32, ptr, i16, ptr, i32 }
%struct.buzzheap_s = type { ptr, i32, i16 }
%struct.buzztable_t = type { i16, i16, ptr }
%struct.buzzclosure_t = type { i16, i16, %struct.anon.1 }
%struct.anon.1 = type { i32, ptr, i8 }
%struct.buzzstring_t = type { i16, i16, %struct.anon.0 }
%struct.anon.0 = type { i16, ptr }

declare void @buzzdict_foreach(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @buzzheap_obj_mark(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.anon, ptr %5, i32 0, i32 1
  %7 = load i16, ptr %6, align 2, !tbaa !9
  %8 = zext i16 %7 to i32
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.buzzvm_s, ptr %9, i32 0, i32 10
  %11 = load ptr, ptr %10, align 8, !tbaa !10
  %12 = getelementptr inbounds %struct.buzzheap_s, ptr %11, i32 0, i32 2
  %13 = load i16, ptr %12, align 4, !tbaa !14
  %14 = zext i16 %13 to i32
  %15 = icmp eq i32 %8, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  br label %63

17:                                               ; preds = %2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.buzzvm_s, ptr %18, i32 0, i32 10
  %20 = load ptr, ptr %19, align 8, !tbaa !10
  %21 = getelementptr inbounds %struct.buzzheap_s, ptr %20, i32 0, i32 2
  %22 = load i16, ptr %21, align 4, !tbaa !14
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.anon, ptr %23, i32 0, i32 1
  store i16 %22, ptr %24, align 2, !tbaa !9
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.anon, ptr %25, i32 0, i32 0
  %27 = load i16, ptr %26, align 8, !tbaa !9
  %28 = zext i16 %27 to i32
  %29 = icmp eq i32 %28, 4
  br i1 %29, label %30, label %35

30:                                               ; preds = %17
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.buzztable_t, ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  call void @buzzdict_foreach(ptr noundef %33, ptr noundef @buzzheap_dictobj_mark, ptr noundef %34)
  br label %63

35:                                               ; preds = %17
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.anon, ptr %36, i32 0, i32 0
  %38 = load i16, ptr %37, align 8, !tbaa !9
  %39 = zext i16 %38 to i32
  %40 = icmp eq i32 %39, 5
  br i1 %40, label %41, label %47

41:                                               ; preds = %35
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.buzzclosure_t, ptr %42, i32 0, i32 2
  %44 = getelementptr inbounds %struct.anon.1, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !9
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  call void @buzzdarray_foreach(ptr noundef %45, ptr noundef @buzzheap_darrayobj_mark, ptr noundef %46)
  br label %62

47:                                               ; preds = %35
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.anon, ptr %48, i32 0, i32 0
  %50 = load i16, ptr %49, align 8, !tbaa !9
  %51 = zext i16 %50 to i32
  %52 = icmp eq i32 %51, 3
  br i1 %52, label %53, label %61

53:                                               ; preds = %47
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.buzzvm_s, ptr %54, i32 0, i32 9
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.buzzstring_t, ptr %57, i32 0, i32 2
  %59 = getelementptr inbounds %struct.anon.0, ptr %58, i32 0, i32 0
  %60 = load i16, ptr %59, align 8, !tbaa !9
  call void @buzzstrman_gc_mark(ptr noundef %56, i16 noundef zeroext %60)
  br label %61

61:                                               ; preds = %53, %47
  br label %62

62:                                               ; preds = %61, %41
  br label %63

63:                                               ; preds = %62, %30, %16
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @buzzheap_dictobj_mark(ptr noundef, ptr noundef, ptr noundef) #1

declare void @buzzdarray_foreach(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @buzzheap_darrayobj_mark(i32 noundef, ptr noundef, ptr noundef) #1

declare void @buzzstrman_gc_mark(ptr noundef, i16 noundef zeroext) #0

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

!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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 72}
!11 = !{!"buzzvm_s", !6, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !13, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !12, i64 152, !12, i64 156, !6, i64 160, !13, i64 168, !6, i64 176, !12, i64 184}
!12 = !{!"int", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !13, i64 12}
!15 = !{!"buzzheap_s", !6, i64 0, !12, i64 8, !13, i64 12}
!16 = !{!11, !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"

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

; Function Attrs: nounwind uwtable
define dso_local void @buzzheap_obj_mark(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 2
  %4 = load i16, ptr %3, align 2, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 72
  %6 = load ptr, ptr %5, align 8, !tbaa !8
  %7 = getelementptr inbounds i8, ptr %6, i64 12
  %8 = load i16, ptr %7, align 4, !tbaa !13
  %9 = icmp eq i16 %4, %8
  br i1 %9, label %23, label %10

10:                                               ; preds = %2
  store i16 %8, ptr %3, align 2, !tbaa !5
  %11 = load i16, ptr %0, align 8, !tbaa !5
  switch i16 %11, label %23 [
    i16 4, label %12
    i16 5, label %15
    i16 3, label %18
  ]

12:                                               ; preds = %10
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  tail call void @buzzdict_foreach(ptr noundef %14, ptr noundef nonnull @buzzheap_dictobj_mark, ptr noundef nonnull %1) #2
  br label %23

15:                                               ; preds = %10
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  tail call void @buzzdarray_foreach(ptr noundef %17, ptr noundef nonnull @buzzheap_darrayobj_mark, ptr noundef nonnull %1) #2
  br label %23

18:                                               ; preds = %10
  %19 = getelementptr inbounds i8, ptr %1, i64 64
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  %22 = load i16, ptr %21, align 8, !tbaa !5
  tail call void @buzzstrman_gc_mark(ptr noundef %20, i16 noundef zeroext %22) #2
  br label %23

23:                                               ; preds = %10, %15, %18, %2, %12
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @buzzheap_dictobj_mark(ptr noundef, ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @buzzheap_darrayobj_mark(i32 noundef, ptr noundef, ptr noundef) #1

declare void @buzzstrman_gc_mark(ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 72}
!9 = !{!"buzzvm_s", !10, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !12, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !11, i64 152, !11, i64 156, !10, i64 160, !12, i64 168, !10, i64 176, !11, i64 184}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"short", !6, i64 0}
!13 = !{!14, !12, i64 12}
!14 = !{!"buzzheap_s", !10, i64 0, !11, i64 8, !12, i64 12}
!15 = !{!9, !10, i64 64}


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