; LLVM IR from brewlin/garbage-collect :: gc-python (gc_test)

; 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.obj = type { i32, i32, ptr }
%struct.array_t = type { ptr, i32, i64, i32 }

@__failed_tests = external dso_local global i32, align 4
@__test_num = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [77 x i8], align 1
@__PRETTY_FUNCTION__.array_test = external hidden unnamed_addr constant [18 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [17 x i8], align 1

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

7:                                                ; preds = %0
  %8 = load i32, ptr @__test_num, align 4, !tbaa !9
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr @__test_num, align 4, !tbaa !9
  %10 = load i32, ptr @__test_num, align 4, !tbaa !9
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %10, ptr noundef @.str.1)
  %12 = load ptr, ptr %1, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %16

14:                                               ; preds = %7
  %15 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %20

16:                                               ; preds = %7
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  %18 = load i32, ptr @__failed_tests, align 4, !tbaa !9
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @__failed_tests, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %16, %14
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %40, %22
  %24 = load i32, ptr %2, align 4, !tbaa !9
  %25 = icmp slt i32 %24, 1000
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %43

27:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %28 = load ptr, ptr %1, align 8, !tbaa !5
  %29 = call ptr @array_push(ptr noundef %28)
  store ptr %29, ptr %3, align 8, !tbaa !5
  %30 = call ptr @gc_malloc(i64 noundef 16)
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %30, ptr %31, align 8, !tbaa !5
  %32 = load i32, ptr %2, align 4, !tbaa !9
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.obj, ptr %34, i32 0, i32 0
  store i32 %32, ptr %35, align 8, !tbaa !11
  %36 = load i32, ptr %2, align 4, !tbaa !9
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.obj, ptr %38, i32 0, i32 1
  store i32 %36, ptr %39, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %40

40:                                               ; preds = %27
  %41 = load i32, ptr %2, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %2, align 4, !tbaa !9
  br label %23, !llvm.loop !14

43:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %44 = load ptr, ptr %1, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.array_t, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !16
  store ptr %46, ptr %4, align 8, !tbaa !5
  call void (...) @gc()
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %76, %43
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = icmp slt i32 %48, 1000
  br i1 %49, label %51, label %50

50:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %79

51:                                               ; preds = %47
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds ptr, ptr %52, i64 %54
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.obj, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %57, align 8, !tbaa !11
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = icmp eq i32 %58, %59
  br i1 %60, label %61, label %62

61:                                               ; preds = %51
  br label %63

62:                                               ; preds = %51
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.5, i32 noundef 30, ptr noundef @__PRETTY_FUNCTION__.array_test) #5
  unreachable

63:                                               ; preds = %61
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds ptr, ptr %64, i64 %66
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.obj, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !13
  %71 = load i32, ptr %5, align 4, !tbaa !9
  %72 = icmp eq i32 %70, %71
  br i1 %72, label %73, label %74

73:                                               ; preds = %63
  br label %75

74:                                               ; preds = %63
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.5, i32 noundef 31, ptr noundef @__PRETTY_FUNCTION__.array_test) #5
  unreachable

75:                                               ; preds = %73
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %5, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %5, align 4, !tbaa !9
  br label %47, !llvm.loop !19

79:                                               ; preds = %50
  call void (...) @gc()
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

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

declare ptr @array_create(i32 noundef, i64 noundef) #2

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

declare ptr @array_push(ptr noundef) #2

declare ptr @gc_malloc(i64 noundef) #2

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

declare void @gc(...) #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { noreturn 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 #4 = { nounwind }
attributes #5 = { noreturn 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 0}
!12 = !{!"obj", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = !{!12, !10, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 0}
!17 = !{!"", !6, i64 0, !10, i64 8, !18, i64 16, !10, i64 24}
!18 = !{!"long", !7, i64 0}
!19 = distinct !{!19, !15}


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

@__failed_tests = external dso_local local_unnamed_addr global i32, align 4
@__test_num = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [77 x i8], align 1
@__PRETTY_FUNCTION__.array_test = external hidden unnamed_addr constant [18 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @array_test() local_unnamed_addr #0 {
  %1 = tail call ptr @array_create(i32 noundef 8, i64 noundef 8) #4
  %2 = load i32, ptr @__test_num, align 4, !tbaa !5
  %3 = add nsw i32 %2, 1
  store i32 %3, ptr @__test_num, align 4, !tbaa !5
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %3, ptr noundef nonnull @.str.1)
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %7, label %5

5:                                                ; preds = %0
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %.preheader

.preheader:                                       ; preds = %7, %5
  br label %13

7:                                                ; preds = %0
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %9 = load i32, ptr @__failed_tests, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr @__failed_tests, align 4, !tbaa !5
  br label %.preheader

11:                                               ; preds = %13
  %12 = load ptr, ptr %1, align 8, !tbaa !9
  tail call void (...) @gc() #4
  br label %31

13:                                               ; preds = %.preheader, %13
  %.01718 = phi i32 [ %17, %13 ], [ 0, %.preheader ]
  %14 = tail call ptr @array_push(ptr noundef %1) #4
  %15 = tail call ptr @gc_malloc(i64 noundef 16) #4
  store ptr %15, ptr %14, align 8, !tbaa !13
  store i32 %.01718, ptr %15, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %15, i64 4
  store i32 %.01718, ptr %16, align 4, !tbaa !16
  %17 = add nuw nsw i32 %.01718, 1
  %exitcond.not = icmp eq i32 %17, 1000
  br i1 %exitcond.not, label %11, label %13, !llvm.loop !17

18:                                               ; preds = %38
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %19 = getelementptr inbounds ptr, ptr %12, i64 %indvars.iv.next
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = load i32, ptr %20, align 8, !tbaa !14
  %22 = zext i32 %21 to i64
  %23 = icmp eq i64 %indvars.iv.next, %22
  br i1 %23, label %24, label %37

24:                                               ; preds = %18
  %25 = getelementptr inbounds i8, ptr %20, i64 4
  %26 = load i32, ptr %25, align 4, !tbaa !16
  %27 = zext i32 %26 to i64
  %28 = icmp eq i64 %indvars.iv.next, %27
  br i1 %28, label %29, label %43

29:                                               ; preds = %24
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond21.not.1 = icmp eq i64 %indvars.iv.next.1, 1000
  br i1 %exitcond21.not.1, label %30, label %31, !llvm.loop !19

30:                                               ; preds = %29
  tail call void (...) @gc() #4
  ret void

31:                                               ; preds = %29, %11
  %indvars.iv = phi i64 [ 0, %11 ], [ %indvars.iv.next.1, %29 ]
  %32 = getelementptr inbounds ptr, ptr %12, i64 %indvars.iv
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = load i32, ptr %33, align 8, !tbaa !14
  %35 = zext i32 %34 to i64
  %36 = icmp eq i64 %indvars.iv, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %18, %31
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.5, i32 noundef 30, ptr noundef nonnull @__PRETTY_FUNCTION__.array_test) #5
  unreachable

38:                                               ; preds = %31
  %39 = getelementptr inbounds i8, ptr %33, i64 4
  %40 = load i32, ptr %39, align 4, !tbaa !16
  %41 = zext i32 %40 to i64
  %42 = icmp eq i64 %indvars.iv, %41
  br i1 %42, label %18, label %43

43:                                               ; preds = %24, %38
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.5, i32 noundef 31, ptr noundef nonnull @__PRETTY_FUNCTION__.array_test) #5
  unreachable
}

declare ptr @array_create(i32 noundef, i64 noundef) local_unnamed_addr #1

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

declare ptr @array_push(ptr noundef) local_unnamed_addr #1

declare ptr @gc_malloc(i64 noundef) local_unnamed_addr #1

declare void @gc(...) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

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


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