; LLVM IR from txus/libsweeper :: tests (sweeper_tests)

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

@foo = external hidden global ptr, align 8
@quux = external hidden global ptr, align 8
@bar = external hidden global ptr, align 8
@assertions = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [12 x i8], align 1
@stderr = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [11 x i8], align 1
@baz = external hidden global ptr, align 8
@.str.18 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nounwind
declare void @free(ptr noundef) #0

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

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

declare i32 @printf(ptr noundef, ...) #3

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #4

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #0

declare void @SWPHeap_destroy(ptr noundef) #3

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

declare ptr @swp_allocate(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local ptr @test_heap_collect() #1 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %5 = call ptr @new_heap(i32 noundef 4)
  store ptr %5, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = call ptr @swp_allocate(ptr noundef %6)
  store ptr %7, ptr @foo, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = call ptr @swp_allocate(ptr noundef %8)
  store ptr %9, ptr @bar, align 8, !tbaa !5
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call ptr @swp_allocate(ptr noundef %10)
  store ptr %11, ptr @baz, align 8, !tbaa !5
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = call ptr @swp_allocate(ptr noundef %12)
  store ptr %13, ptr @quux, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = call ptr @swp_allocate(ptr noundef %14)
  store ptr %15, ptr %3, align 8, !tbaa !5
  %16 = load i32, ptr @assertions, align 4, !tbaa !9
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @assertions, align 4, !tbaa !9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %34, label %20

20:                                               ; preds = %0
  %21 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %22 = load ptr, ptr @stderr, align 8, !tbaa !5
  %23 = call ptr @__errno_location() #6
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %20
  br label %31

27:                                               ; preds = %20
  %28 = call ptr @__errno_location() #6
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = call ptr @strerror(i32 noundef %29) #5
  br label %31

31:                                               ; preds = %27, %26
  %32 = phi ptr [ @.str.3, %26 ], [ %30, %27 ]
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef @.str.18, ptr noundef @.str.2, i32 noundef 105, ptr noundef %32) #5
  store ptr @.str.19, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %88

34:                                               ; preds = %0
  %35 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %36

36:                                               ; preds = %34
  %37 = load i32, ptr @assertions, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr @assertions, align 4, !tbaa !9
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.SWPHeap_s, ptr %39, i32 0, i32 4
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = icmp eq i32 %41, 1
  br i1 %42, label %57, label %43

43:                                               ; preds = %36
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %45 = load ptr, ptr @stderr, align 8, !tbaa !5
  %46 = call ptr @__errno_location() #6
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %43
  br label %54

50:                                               ; preds = %43
  %51 = call ptr @__errno_location() #6
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = call ptr @strerror(i32 noundef %52) #5
  br label %54

54:                                               ; preds = %50, %49
  %55 = phi ptr [ @.str.3, %49 ], [ %53, %50 ]
  %56 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.20, ptr noundef @.str.2, i32 noundef 107, ptr noundef %55) #5
  store ptr @.str.21, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %88

57:                                               ; preds = %36
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %59

59:                                               ; preds = %57
  %60 = load i32, ptr @assertions, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr @assertions, align 4, !tbaa !9
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.SWPHeap_s, ptr %62, i32 0, i32 2
  %64 = load i64, ptr %63, align 8, !tbaa !14
  %65 = icmp eq i64 %64, 12
  br i1 %65, label %80, label %66

66:                                               ; preds = %59
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %68 = load ptr, ptr @stderr, align 8, !tbaa !5
  %69 = call ptr @__errno_location() #6
  %70 = load i32, ptr %69, align 4, !tbaa !9
  %71 = icmp eq i32 %70, 0
  br i1 %71, label %72, label %73

72:                                               ; preds = %66
  br label %77

73:                                               ; preds = %66
  %74 = call ptr @__errno_location() #6
  %75 = load i32, ptr %74, align 4, !tbaa !9
  %76 = call ptr @strerror(i32 noundef %75) #5
  br label %77

77:                                               ; preds = %73, %72
  %78 = phi ptr [ @.str.3, %72 ], [ %76, %73 ]
  %79 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %68, ptr noundef @.str.22, ptr noundef @.str.2, i32 noundef 108, ptr noundef %78) #5
  store ptr @.str.23, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %88

80:                                               ; preds = %59
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %82

82:                                               ; preds = %80
  %83 = load ptr, ptr @foo, align 8, !tbaa !5
  call void @free(ptr noundef %83) #5
  %84 = load ptr, ptr @bar, align 8, !tbaa !5
  call void @free(ptr noundef %84) #5
  %85 = load ptr, ptr @quux, align 8, !tbaa !5
  call void @free(ptr noundef %85) #5
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %86) #5
  %87 = load ptr, ptr %2, align 8, !tbaa !5
  call void @SWPHeap_destroy(ptr noundef %87)
  store ptr null, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %88

88:                                               ; preds = %82, %77, %54, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  %89 = load ptr, ptr %1, align 8
  ret ptr %89
}

attributes #0 = { nounwind "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 #4 = { nounwind willreturn memory(none) "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(none) }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"SWPHeap_s", !6, i64 0, !6, i64 8, !13, i64 16, !13, i64 24, !10, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !7, i64 64, !13, i64 72}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 16}


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

@foo = external hidden local_unnamed_addr global ptr, align 8
@quux = external hidden local_unnamed_addr global ptr, align 8
@bar = external hidden local_unnamed_addr global ptr, align 8
@assertions = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [12 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [11 x i8], align 1
@baz = external hidden local_unnamed_addr global ptr, align 8
@.str.18 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #3

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #4

declare void @SWPHeap_destroy(ptr noundef) local_unnamed_addr #5

declare ptr @swp_allocate(ptr noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @test_heap_collect() local_unnamed_addr #1 {
  %1 = tail call ptr @new_heap(i32 noundef 4)
  %2 = tail call ptr @swp_allocate(ptr noundef %1) #6
  store ptr %2, ptr @foo, align 8, !tbaa !5
  %3 = tail call ptr @swp_allocate(ptr noundef %1) #6
  store ptr %3, ptr @bar, align 8, !tbaa !5
  %4 = tail call ptr @swp_allocate(ptr noundef %1) #6
  store ptr %4, ptr @baz, align 8, !tbaa !5
  %5 = tail call ptr @swp_allocate(ptr noundef %1) #6
  store ptr %5, ptr @quux, align 8, !tbaa !5
  %6 = tail call ptr @swp_allocate(ptr noundef %1) #6
  %7 = load i32, ptr @assertions, align 4, !tbaa !9
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr @assertions, align 4, !tbaa !9
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %9, label %20

9:                                                ; preds = %0
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = tail call ptr @__errno_location() #7
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %17, label %15

15:                                               ; preds = %9
  %16 = tail call ptr @strerror(i32 noundef %13) #6
  br label %17

17:                                               ; preds = %9, %15
  %18 = phi ptr [ %16, %15 ], [ @.str.3, %9 ]
  %19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str.18, ptr noundef nonnull @.str.2, i32 noundef 105, ptr noundef %18) #8
  br label %61

20:                                               ; preds = %0
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %22 = load i32, ptr @assertions, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr @assertions, align 4, !tbaa !9
  %24 = getelementptr inbounds i8, ptr %1, i64 32
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %38, label %27

27:                                               ; preds = %20
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = tail call ptr @__errno_location() #7
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %35, label %33

33:                                               ; preds = %27
  %34 = tail call ptr @strerror(i32 noundef %31) #6
  br label %35

35:                                               ; preds = %27, %33
  %36 = phi ptr [ %34, %33 ], [ @.str.3, %27 ]
  %37 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef nonnull @.str.20, ptr noundef nonnull @.str.2, i32 noundef 107, ptr noundef %36) #8
  br label %61

38:                                               ; preds = %20
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %40 = load i32, ptr @assertions, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr @assertions, align 4, !tbaa !9
  %42 = getelementptr inbounds i8, ptr %1, i64 16
  %43 = load i64, ptr %42, align 8, !tbaa !14
  %44 = icmp eq i64 %43, 12
  br i1 %44, label %56, label %45

45:                                               ; preds = %38
  %46 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %47 = load ptr, ptr @stderr, align 8, !tbaa !5
  %48 = tail call ptr @__errno_location() #7
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %53, label %51

51:                                               ; preds = %45
  %52 = tail call ptr @strerror(i32 noundef %49) #6
  br label %53

53:                                               ; preds = %45, %51
  %54 = phi ptr [ %52, %51 ], [ @.str.3, %45 ]
  %55 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %47, ptr noundef nonnull @.str.22, ptr noundef nonnull @.str.2, i32 noundef 108, ptr noundef %54) #8
  br label %61

56:                                               ; preds = %38
  %57 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %58 = load ptr, ptr @foo, align 8, !tbaa !5
  tail call void @free(ptr noundef %58) #6
  %59 = load ptr, ptr @bar, align 8, !tbaa !5
  tail call void @free(ptr noundef %59) #6
  %60 = load ptr, ptr @quux, align 8, !tbaa !5
  tail call void @free(ptr noundef %60) #6
  tail call void @free(ptr noundef nonnull %6) #6
  tail call void @SWPHeap_destroy(ptr noundef nonnull %1) #6
  br label %61

61:                                               ; preds = %56, %53, %35, %17
  %.0 = phi ptr [ null, %56 ], [ @.str.23, %53 ], [ @.str.21, %35 ], [ @.str.19, %17 ]
  ret ptr %.0
}

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nofree nounwind "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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 #4 = { nounwind "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 #5 = { "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(none) }
attributes #8 = { cold 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"SWPHeap_s", !6, i64 0, !6, i64 8, !13, i64 16, !13, i64 24, !10, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !7, i64 64, !13, i64 72}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 16}


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