; LLVM IR from txus/libsweeper :: src/sweeper (sweeper)

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

; 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 @swp_mark(ptr noundef, ptr noundef) #1

declare ptr @SWPArray_create(i64 noundef, i64 noundef) #2

declare i32 @SWPArray_push(ptr noundef, ptr noundef) #2

declare void @SWPArray_destroy(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @swp_mark_from_roots(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %7 = call ptr @SWPArray_create(i64 noundef 8, i64 noundef 100)
  store ptr %7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %8 = call ptr @SWPArray_create(i64 noundef 8, i64 noundef 100)
  store ptr %8, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.SWPHeap_s, ptr %9, i32 0, i32 6
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.SWPHeap_s, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  call void %11(ptr noundef %14, ptr noundef %15)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %16

16:                                               ; preds = %48, %1
  %17 = load i32, ptr %5, align 4, !tbaa !14
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.SWPArray, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !15
  %21 = icmp slt i32 %17, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %51

23:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.SWPArray, ptr %24, i32 0, i32 4
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %27 = load i32, ptr %5, align 4, !tbaa !14
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds ptr, ptr %26, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  store ptr %30, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %47

33:                                               ; preds = %23
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.SWPHeader_s, ptr %34, i32 0, i32 0
  %36 = load i8, ptr %35, align 1, !tbaa !18
  %37 = sext i8 %36 to i32
  %38 = icmp eq i32 %37, 1
  br i1 %38, label %47, label %39

39:                                               ; preds = %33
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.SWPHeader_s, ptr %40, i32 0, i32 0
  store i8 1, ptr %41, align 1, !tbaa !18
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = call i32 @SWPArray_push(ptr noundef %42, ptr noundef %43)
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  call void @swp_mark(ptr noundef %45, ptr noundef %46)
  br label %47

47:                                               ; preds = %39, %33, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %5, align 4, !tbaa !14
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %5, align 4, !tbaa !14
  br label %16, !llvm.loop !20

51:                                               ; preds = %22
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  call void @SWPArray_destroy(ptr noundef %52)
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  call void @SWPArray_destroy(ptr noundef %53)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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, !6, i64 48}
!10 = !{!"SWPHeap_s", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !7, i64 64, !11, i64 72}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!16, !12, i64 0}
!16 = !{!"SWPArray", !12, i64 0, !12, i64 4, !11, i64 8, !11, i64 16, !6, i64 24}
!17 = !{!16, !6, i64 24}
!18 = !{!19, !7, i64 0}
!19 = !{!"SWPHeader_s", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; 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: nounwind uwtable
declare dso_local void @swp_mark(ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @SWPArray_create(i64 noundef, i64 noundef) local_unnamed_addr #1

declare i32 @SWPArray_push(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @SWPArray_destroy(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @swp_mark_from_roots(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @SWPArray_create(i64 noundef 8, i64 noundef 100) #2
  %3 = tail call ptr @SWPArray_create(i64 noundef 8, i64 noundef 100) #2
  %4 = getelementptr inbounds i8, ptr %0, i64 48
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %0, align 8, !tbaa !12
  tail call void %5(ptr noundef %6, ptr noundef %3) #2
  %7 = load i32, ptr %3, align 8, !tbaa !13
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %9 = getelementptr inbounds i8, ptr %3, i64 24
  br label %10

._crit_edge:                                      ; preds = %20, %1
  tail call void @SWPArray_destroy(ptr noundef %2) #2
  tail call void @SWPArray_destroy(ptr noundef nonnull %3) #2
  ret void

10:                                               ; preds = %.lr.ph, %20
  %11 = phi i32 [ %7, %.lr.ph ], [ %21, %20 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %20 ]
  %12 = load ptr, ptr %9, align 8, !tbaa !15
  %13 = getelementptr inbounds ptr, ptr %12, i64 %indvars.iv
  %14 = load ptr, ptr %13, align 8, !tbaa !16
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %20, label %15

15:                                               ; preds = %10
  %16 = load i8, ptr %14, align 1, !tbaa !17
  %17 = icmp eq i8 %16, 1
  br i1 %17, label %20, label %18

18:                                               ; preds = %15
  store i8 1, ptr %14, align 1, !tbaa !17
  %19 = tail call i32 @SWPArray_push(ptr noundef %2, ptr noundef nonnull %14) #2
  tail call void @swp_mark(ptr noundef nonnull %0, ptr noundef %2)
  %.pre = load i32, ptr %3, align 8, !tbaa !13
  br label %20

20:                                               ; preds = %18, %15, %10
  %21 = phi i32 [ %.pre, %18 ], [ %11, %15 ], [ %11, %10 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %22 = sext i32 %21 to i64
  %23 = icmp slt i64 %indvars.iv.next, %22
  br i1 %23, label %10, label %._crit_edge, !llvm.loop !19
}

attributes #0 = { 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 #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 #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, !7, i64 48}
!6 = !{!"SWPHeap_s", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !11, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !8, i64 64, !10, i64 72}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!14, !11, i64 0}
!14 = !{!"SWPArray", !11, i64 0, !11, i64 4, !10, i64 8, !10, i64 16, !7, i64 24}
!15 = !{!14, !7, i64 24}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !8, i64 0}
!18 = !{!"SWPHeader_s", !8, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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