; LLVM IR from ponylang/ponyc :: src/libponyrt/gc (objectmap)

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

; 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
declare dso_local void @ponyint_objectmap_optimize(ptr noundef) #1

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

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

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

8:                                                ; preds = %29, %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = call ptr @ponyint_objectmap_next(ptr noundef %9, ptr noundef %3)
  store ptr %10, ptr %4, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %30

12:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.object_t, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  store ptr %15, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.object_t, ptr %16, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !16
  %19 = icmp ugt i64 %18, 0
  br i1 %19, label %20, label %25

20:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = call ptr @ponyint_pagemap_get_chunk(ptr noundef %21)
  store ptr %22, ptr %7, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  call void @ponyint_heap_mark_shallow(ptr noundef %23, ptr noundef %24)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %29

25:                                               ; preds = %12
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = load i64, ptr %3, align 8, !tbaa !9
  call void @ponyint_objectmap_clearindex(ptr noundef %26, i64 noundef %27)
  store i8 1, ptr %5, align 1, !tbaa !11
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  call void @object_free(ptr noundef %28)
  br label %29

29:                                               ; preds = %25, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %8, !llvm.loop !17

30:                                               ; preds = %8
  %31 = load i8, ptr %5, align 1, !tbaa !11, !range !19, !noundef !20
  %32 = trunc i8 %31 to i1
  br i1 %32, label %33, label %35

33:                                               ; preds = %30
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  call void @ponyint_objectmap_optimize(ptr noundef %34)
  br label %35

35:                                               ; preds = %33, %30
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

declare ptr @ponyint_pagemap_get_chunk(ptr noundef) #2

declare void @ponyint_heap_mark_shallow(ptr noundef, ptr noundef) #2

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

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 = { "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, !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, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"object_t", !6, i64 0, !10, i64 8, !15, i64 16, !12, i64 20, !6, i64 24}
!15 = !{!"int", !7, i64 0}
!16 = !{!14, !10, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{i8 0, i8 2}
!20 = !{}


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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @ponyint_objectmap_sweep(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  store i64 -1, ptr %2, align 8, !tbaa !5
  %3 = call ptr @ponyint_objectmap_next(ptr noundef %0, ptr noundef nonnull %2)
  %.not11 = icmp eq ptr %3, null
  br i1 %.not11, label %.critedge, label %.lr.ph.outer

.lr.ph.outer:                                     ; preds = %1, %.thread
  %.ph = phi ptr [ %12, %.thread ], [ %3, %1 ]
  %.012.ph = phi i1 [ true, %.thread ], [ false, %1 ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.outer, %7
  %4 = phi ptr [ %10, %7 ], [ %.ph, %.lr.ph.outer ]
  %5 = getelementptr inbounds i8, ptr %4, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !9
  %.not10 = icmp eq i64 %6, 0
  br i1 %.not10, label %.thread, label %7

7:                                                ; preds = %.lr.ph
  %8 = load ptr, ptr %4, align 8, !tbaa !14
  %9 = call ptr @ponyint_pagemap_get_chunk(ptr noundef %8) #3
  call void @ponyint_heap_mark_shallow(ptr noundef %9, ptr noundef %8) #3
  %10 = call ptr @ponyint_objectmap_next(ptr noundef %0, ptr noundef nonnull %2)
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

.thread:                                          ; preds = %.lr.ph
  %11 = load i64, ptr %2, align 8, !tbaa !5
  call void @ponyint_objectmap_clearindex(ptr noundef %0, i64 noundef %11)
  call void @object_free(ptr noundef nonnull %4)
  %12 = call ptr @ponyint_objectmap_next(ptr noundef %0, ptr noundef nonnull %2)
  %.not14 = icmp eq ptr %12, null
  br i1 %.not14, label %._crit_edge.thread, label %.lr.ph.outer, !llvm.loop !15

._crit_edge:                                      ; preds = %7
  br i1 %.012.ph, label %._crit_edge.thread, label %.critedge

._crit_edge.thread:                               ; preds = %.thread, %._crit_edge
  call void @ponyint_objectmap_optimize(ptr noundef %0)
  br label %.critedge

.critedge:                                        ; preds = %1, %._crit_edge.thread, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  ret void
}

declare ptr @ponyint_pagemap_get_chunk(ptr noundef) local_unnamed_addr #2

declare void @ponyint_heap_mark_shallow(ptr noundef, ptr noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress 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 = { "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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"object_t", !11, i64 0, !6, i64 8, !12, i64 16, !13, i64 20, !11, i64 24}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!10, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: AggressiveInstCombinePass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass