; LLVM IR from brewlin/garbage-collect :: compact-lisp2 (compact)

; 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.gc_heap = type { ptr, i64 }
%struct.header = type { i64, i64, i64, i64, ptr, ptr }

@gc_heaps_used = external global i64, align 8
@gc_heaps = external global [100000 x %struct.gc_heap], align 16
@free_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

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

; Function Attrs: nounwind uwtable
define dso_local void @move_obj() #1 {
  %1 = alloca i64, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %89, %0
  %9 = load i64, ptr %7, align 8, !tbaa !5
  %10 = load i64, ptr @gc_heaps_used, align 8, !tbaa !5
  %11 = icmp ult i64 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %92

13:                                               ; preds = %8
  %14 = load i64, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds [100000 x %struct.gc_heap], ptr @gc_heaps, i64 0, i64 %14
  %16 = getelementptr inbounds %struct.gc_heap, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 16, !tbaa !9
  %18 = ptrtoint ptr %17 to i64
  %19 = load i64, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds [100000 x %struct.gc_heap], ptr @gc_heaps, i64 0, i64 %19
  %21 = getelementptr inbounds %struct.gc_heap, ptr %20, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !12
  %23 = add i64 %18, %22
  %24 = inttoptr i64 %23 to ptr
  store ptr %24, ptr %3, align 8, !tbaa !13
  %25 = load i64, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds [100000 x %struct.gc_heap], ptr @gc_heaps, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.gc_heap, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 16, !tbaa !9
  store ptr %28, ptr %6, align 8, !tbaa !13
  %29 = load i64, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds [100000 x %struct.gc_heap], ptr @gc_heaps, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.gc_heap, ptr %30, i32 0, i32 1
  %32 = load i64, ptr %31, align 8, !tbaa !12
  store i64 %32, ptr %1, align 8, !tbaa !5
  %33 = load i64, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds [100000 x %struct.gc_heap], ptr @gc_heaps, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.gc_heap, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 16, !tbaa !9
  store ptr %36, ptr %2, align 8, !tbaa !13
  br label %37

37:                                               ; preds = %78, %13
  %38 = load ptr, ptr %2, align 8, !tbaa !13
  %39 = load ptr, ptr %3, align 8, !tbaa !13
  %40 = icmp ult ptr %38, %39
  br i1 %40, label %41, label %88

41:                                               ; preds = %37
  %42 = load ptr, ptr %2, align 8, !tbaa !13
  %43 = getelementptr inbounds %struct.header, ptr %42, i32 0, i32 1
  %44 = load i64, ptr %43, align 8, !tbaa !14
  %45 = and i64 %44, 1
  %46 = icmp ne i64 %45, 0
  br i1 %46, label %47, label %77

47:                                               ; preds = %41
  %48 = load ptr, ptr %2, align 8, !tbaa !13
  %49 = getelementptr inbounds %struct.header, ptr %48, i32 0, i32 1
  %50 = load i64, ptr %49, align 8, !tbaa !14
  %51 = and i64 %50, 2
  %52 = icmp ne i64 %51, 0
  br i1 %52, label %53, label %76

53:                                               ; preds = %47
  %54 = load ptr, ptr %2, align 8, !tbaa !13
  %55 = getelementptr inbounds %struct.header, ptr %54, i32 0, i32 5
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  store ptr %56, ptr %5, align 8, !tbaa !13
  %57 = load ptr, ptr %5, align 8, !tbaa !13
  %58 = load ptr, ptr %2, align 8, !tbaa !13
  %59 = load ptr, ptr %2, align 8, !tbaa !13
  %60 = getelementptr inbounds %struct.header, ptr %59, i32 0, i32 2
  %61 = load i64, ptr %60, align 8, !tbaa !17
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %57, ptr align 8 %58, i64 %61, i1 false)
  %62 = load ptr, ptr %5, align 8, !tbaa !13
  %63 = getelementptr inbounds %struct.header, ptr %62, i32 0, i32 1
  %64 = load i64, ptr %63, align 8, !tbaa !14
  %65 = and i64 %64, -3
  store i64 %65, ptr %63, align 8, !tbaa !14
  %66 = load ptr, ptr %6, align 8, !tbaa !13
  %67 = load ptr, ptr %5, align 8, !tbaa !13
  %68 = getelementptr inbounds %struct.header, ptr %67, i32 0, i32 2
  %69 = load i64, ptr %68, align 8, !tbaa !17
  %70 = getelementptr inbounds i8, ptr %66, i64 %69
  store ptr %70, ptr %6, align 8, !tbaa !13
  %71 = load ptr, ptr %5, align 8, !tbaa !13
  %72 = getelementptr inbounds %struct.header, ptr %71, i32 0, i32 2
  %73 = load i64, ptr %72, align 8, !tbaa !17
  %74 = load i64, ptr %1, align 8, !tbaa !5
  %75 = sub i64 %74, %73
  store i64 %75, ptr %1, align 8, !tbaa !5
  br label %76

76:                                               ; preds = %53, %47
  br label %77

77:                                               ; preds = %76, %41
  br label %78

78:                                               ; preds = %77
  %79 = load ptr, ptr %2, align 8, !tbaa !13
  %80 = getelementptr inbounds %struct.header, ptr %79, i64 1
  %81 = ptrtoint ptr %80 to i64
  %82 = load ptr, ptr %2, align 8, !tbaa !13
  %83 = getelementptr inbounds %struct.header, ptr %82, i32 0, i32 2
  %84 = load i64, ptr %83, align 8, !tbaa !17
  %85 = sub i64 %84, 48
  %86 = add i64 %81, %85
  %87 = inttoptr i64 %86 to ptr
  store ptr %87, ptr %2, align 8, !tbaa !13
  br label %37, !llvm.loop !18

88:                                               ; preds = %37
  br label %89

89:                                               ; preds = %88
  %90 = load i64, ptr %7, align 8, !tbaa !5
  %91 = add i64 %90, 1
  store i64 %91, ptr %7, align 8, !tbaa !5
  br label %8, !llvm.loop !20

92:                                               ; preds = %12
  %93 = load ptr, ptr %6, align 8, !tbaa !13
  store ptr %93, ptr @free_list, align 8, !tbaa !13
  %94 = load i64, ptr %1, align 8, !tbaa !5
  %95 = load ptr, ptr @free_list, align 8, !tbaa !13
  %96 = getelementptr inbounds %struct.header, ptr %95, i32 0, i32 2
  store i64 %94, ptr %96, align 8, !tbaa !17
  %97 = load ptr, ptr @free_list, align 8, !tbaa !13
  %98 = getelementptr inbounds %struct.header, ptr %97, i32 0, i32 4
  store ptr null, ptr %98, align 8, !tbaa !21
  %99 = load ptr, ptr @free_list, align 8, !tbaa !13
  %100 = getelementptr inbounds %struct.header, ptr %99, i64 1
  %101 = load i64, ptr %1, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %100, i8 0, i64 %101, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"gc_heap", !11, i64 0, !6, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !6, i64 8}
!15 = !{!"header", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !11, i64 40}
!16 = !{!15, !11, i64 40}
!17 = !{!15, !6, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}
!21 = !{!15, !11, i64 32}


; 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.gc_heap = type { ptr, i64 }

@gc_heaps_used = external local_unnamed_addr global i64, align 8
@gc_heaps = external local_unnamed_addr global [100000 x %struct.gc_heap], align 16
@free_list = external local_unnamed_addr global ptr, align 8

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @move_obj() local_unnamed_addr #0 {
  %1 = load i64, ptr @gc_heaps_used, align 8, !tbaa !5
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %._crit_edge37, label %.lr.ph36

._crit_edge37:                                    ; preds = %._crit_edge, %0
  %.025.lcssa = phi i64 [ undef, %0 ], [ %.126.lcssa, %._crit_edge ]
  %.024.lcssa = phi ptr [ undef, %0 ], [ %.1.lcssa, %._crit_edge ]
  store ptr %.024.lcssa, ptr @free_list, align 8, !tbaa !9
  %2 = getelementptr inbounds i8, ptr %.024.lcssa, i64 16
  store i64 %.025.lcssa, ptr %2, align 8, !tbaa !11
  %3 = getelementptr inbounds i8, ptr %.024.lcssa, i64 32
  store ptr null, ptr %3, align 8, !tbaa !13
  %4 = getelementptr inbounds i8, ptr %.024.lcssa, i64 48
  tail call void @llvm.memset.p0.i64(ptr nonnull align 8 %4, i8 0, i64 %.025.lcssa, i1 false)
  ret void

.lr.ph36:                                         ; preds = %0, %._crit_edge
  %5 = phi i64 [ %38, %._crit_edge ], [ %1, %0 ]
  %.034 = phi i64 [ %39, %._crit_edge ], [ 0, %0 ]
  %6 = getelementptr inbounds [100000 x %struct.gc_heap], ptr @gc_heaps, i64 0, i64 %.034
  %7 = load ptr, ptr %6, align 16, !tbaa !14
  %8 = ptrtoint ptr %7 to i64
  %9 = getelementptr inbounds i8, ptr %6, i64 8
  %10 = load i64, ptr %9, align 8, !tbaa !16
  %11 = add i64 %10, %8
  %12 = inttoptr i64 %11 to ptr
  %13 = icmp ult ptr %7, %12
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph36, %29
  %.132 = phi ptr [ %.2, %29 ], [ %7, %.lr.ph36 ]
  %.12631 = phi i64 [ %.227, %29 ], [ %10, %.lr.ph36 ]
  %.02830 = phi ptr [ %36, %29 ], [ %7, %.lr.ph36 ]
  %14 = getelementptr inbounds i8, ptr %.02830, i64 8
  %15 = load i64, ptr %14, align 8, !tbaa !17
  %16 = and i64 %15, 3
  %or.cond.not = icmp eq i64 %16, 3
  br i1 %or.cond.not, label %17, label %29

17:                                               ; preds = %.lr.ph
  %18 = getelementptr inbounds i8, ptr %.02830, i64 40
  %19 = load ptr, ptr %18, align 8, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %.02830, i64 16
  %21 = load i64, ptr %20, align 8, !tbaa !11
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %19, ptr nonnull align 8 %.02830, i64 %21, i1 false)
  %22 = getelementptr inbounds i8, ptr %19, i64 8
  %23 = load i64, ptr %22, align 8, !tbaa !17
  %24 = and i64 %23, -3
  store i64 %24, ptr %22, align 8, !tbaa !17
  %25 = getelementptr inbounds i8, ptr %19, i64 16
  %26 = load i64, ptr %25, align 8, !tbaa !11
  %27 = getelementptr inbounds i8, ptr %.132, i64 %26
  %28 = sub i64 %.12631, %26
  br label %29

29:                                               ; preds = %.lr.ph, %17
  %.227 = phi i64 [ %28, %17 ], [ %.12631, %.lr.ph ]
  %.2 = phi ptr [ %27, %17 ], [ %.132, %.lr.ph ]
  %30 = getelementptr inbounds i8, ptr %.02830, i64 48
  %31 = ptrtoint ptr %30 to i64
  %32 = getelementptr inbounds i8, ptr %.02830, i64 16
  %33 = load i64, ptr %32, align 8, !tbaa !11
  %34 = add i64 %31, -48
  %35 = add i64 %34, %33
  %36 = inttoptr i64 %35 to ptr
  %37 = icmp ult ptr %36, %12
  br i1 %37, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !19

._crit_edge.loopexit:                             ; preds = %29
  %.pre = load i64, ptr @gc_heaps_used, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph36
  %38 = phi i64 [ %5, %.lr.ph36 ], [ %.pre, %._crit_edge.loopexit ]
  %.126.lcssa = phi i64 [ %10, %.lr.ph36 ], [ %.227, %._crit_edge.loopexit ]
  %.1.lcssa = phi ptr [ %7, %.lr.ph36 ], [ %.2, %._crit_edge.loopexit ]
  %39 = add nuw i64 %.034, 1
  %40 = icmp ult i64 %39, %38
  br i1 %40, label %.lr.ph36, label %._crit_edge37, !llvm.loop !21
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"header", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 40}
!13 = !{!12, !10, i64 32}
!14 = !{!15, !10, i64 0}
!15 = !{!"gc_heap", !10, i64 0, !6, i64 8}
!16 = !{!15, !6, i64 8}
!17 = !{!12, !6, i64 8}
!18 = !{!12, !10, i64 40}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass