; 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.SWPArray = type { i32, i32, i64, i64, ptr }
%struct.SWPHeap_s = type { ptr, ptr, i64, i64, i32, ptr, ptr, ptr, i8, i64 }
%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
define dso_local void @swp_mark(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %57, %2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.SWPArray, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = icmp eq i32 %12, 0
  %14 = xor i1 %13, true
  br i1 %14, label %15, label %59

15:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call ptr @SWPArray_pop(ptr noundef %16)
  store ptr %17, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %18 = call ptr @SWPArray_create(i64 noundef 8, i64 noundef 100)
  store ptr %18, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.SWPHeap_s, ptr %19, i32 0, i32 7
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  call void %21(ptr noundef %22, ptr noundef %23)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !15
  br label %24

24:                                               ; preds = %54, %15
  %25 = load i32, ptr %7, align 4, !tbaa !15
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.SWPArray, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !9
  %29 = icmp slt i32 %25, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %57

31:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.SWPArray, ptr %32, i32 0, i32 4
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = load i32, ptr %7, align 4, !tbaa !15
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds ptr, ptr %34, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  store ptr %38, ptr %8, align 8, !tbaa !5
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %53

41:                                               ; preds = %31
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.SWPHeader_s, ptr %42, i32 0, i32 0
  %44 = load i8, ptr %43, align 1, !tbaa !17
  %45 = sext i8 %44 to i32
  %46 = icmp eq i32 %45, 1
  br i1 %46, label %53, label %47

47:                                               ; preds = %41
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.SWPHeader_s, ptr %48, i32 0, i32 0
  store i8 1, ptr %49, align 1, !tbaa !17
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = call i32 @SWPArray_push(ptr noundef %50, ptr noundef %51)
  br label %53

53:                                               ; preds = %47, %41, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %7, align 4, !tbaa !15
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %7, align 4, !tbaa !15
  br label %24, !llvm.loop !19

57:                                               ; preds = %30
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  call void @SWPArray_destroy(ptr noundef %58)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %9, !llvm.loop !21

59:                                               ; preds = %9
  ret void
}

declare ptr @SWPArray_pop(ptr noundef) #2

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

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, !11, i64 0}
!10 = !{!"SWPArray", !11, i64 0, !11, i64 4, !12, i64 8, !12, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 56}
!14 = !{!"SWPHeap_s", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 24, !11, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !7, i64 64, !12, i64 72}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !6, i64 24}
!17 = !{!18, !7, i64 0}
!18 = !{!"SWPHeader_s", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !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: nounwind uwtable
define dso_local void @swp_mark(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %1, align 8, !tbaa !5
  %.not18 = icmp eq i32 %3, 0
  br i1 %.not18, label %._crit_edge21, label %.lr.ph20

.lr.ph20:                                         ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 56
  br label %5

5:                                                ; preds = %.lr.ph20, %._crit_edge
  %6 = tail call ptr @SWPArray_pop(ptr noundef nonnull %1) #2
  %7 = tail call ptr @SWPArray_create(i64 noundef 8, i64 noundef 100) #2
  %8 = load ptr, ptr %4, align 8, !tbaa !12
  tail call void %8(ptr noundef %6, ptr noundef %7) #2
  %9 = load i32, ptr %7, align 8, !tbaa !5
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5
  %11 = getelementptr inbounds i8, ptr %7, i64 24
  br label %13

._crit_edge:                                      ; preds = %23, %5
  tail call void @SWPArray_destroy(ptr noundef nonnull %7) #2
  %12 = load i32, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %._crit_edge21, label %5, !llvm.loop !14

13:                                               ; preds = %.lr.ph, %23
  %14 = phi i32 [ %9, %.lr.ph ], [ %24, %23 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %23 ]
  %15 = load ptr, ptr %11, align 8, !tbaa !16
  %16 = getelementptr inbounds ptr, ptr %15, i64 %indvars.iv
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  %.not16 = icmp eq ptr %17, null
  br i1 %.not16, label %23, label %18

18:                                               ; preds = %13
  %19 = load i8, ptr %17, align 1, !tbaa !18
  %20 = icmp eq i8 %19, 1
  br i1 %20, label %23, label %21

21:                                               ; preds = %18
  store i8 1, ptr %17, align 1, !tbaa !18
  %22 = tail call i32 @SWPArray_push(ptr noundef nonnull %1, ptr noundef nonnull %17) #2
  %.pre = load i32, ptr %7, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %21, %18, %13
  %24 = phi i32 [ %.pre, %21 ], [ %14, %18 ], [ %14, %13 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = sext i32 %24 to i64
  %26 = icmp slt i64 %indvars.iv.next, %25
  br i1 %26, label %13, label %._crit_edge, !llvm.loop !20

._crit_edge21:                                    ; preds = %._crit_edge, %2
  ret void
}

declare ptr @SWPArray_pop(ptr noundef) local_unnamed_addr #1

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

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


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