; LLVM IR from humz2k/sugaryc :: ext/bdwgc (reclaim)

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

@GC_have_errors = external dso_local global i32, align 4
@GC_print_all_errors.printing_errors = external hidden global i32, align 4
@GC_n_leaked = external hidden global i32, align 4
@GC_leaked = external hidden global [40 x ptr], align 16
@GC_debugging_started = external global i32, align 4
@GC_print_all_smashed = external global ptr, align 8
@.str = external hidden unnamed_addr constant [26 x i8], align 1
@GC_print_heap_obj = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1
@GC_on_abort = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [38 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @GC_print_all_errors() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca [40 x ptr], align 16
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #7
  call void @llvm.lifetime.start.p0(i64 320, ptr %4) #7
  %7 = load i32, ptr @GC_print_all_errors.printing_errors, align 4, !tbaa !5
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %0
  store i32 1, ptr %5, align 4
  br label %59

10:                                               ; preds = %0
  %11 = load i32, ptr @GC_have_errors, align 4, !tbaa !5
  store i32 %11, ptr %1, align 4, !tbaa !5
  store i32 1, ptr @GC_print_all_errors.printing_errors, align 4, !tbaa !5
  %12 = load i32, ptr @GC_n_leaked, align 4, !tbaa !5
  store i32 %12, ptr %3, align 4, !tbaa !5
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = icmp ugt i32 %13, 0
  br i1 %14, label %15, label %23

15:                                               ; preds = %10
  %16 = getelementptr inbounds [40 x ptr], ptr %4, i64 0, i64 0
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = zext i32 %17 to i64
  %19 = mul i64 %18, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %16, ptr align 16 @GC_leaked, i64 %19, i1 false)
  store i32 0, ptr @GC_n_leaked, align 4, !tbaa !5
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = zext i32 %20 to i64
  %22 = mul i64 %21, 8
  call void @llvm.memset.p0.i64(ptr align 16 @GC_leaked, i8 0, i64 %22, i1 false)
  br label %23

23:                                               ; preds = %15, %10
  %24 = load i32, ptr @GC_debugging_started, align 4, !tbaa !5
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %23
  %27 = load ptr, ptr @GC_print_all_smashed, align 8, !tbaa !9
  call void %27()
  br label %29

28:                                               ; preds = %23
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %28, %26
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = icmp ugt i32 %30, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %29
  %33 = load i32, ptr %3, align 4, !tbaa !5
  call void (ptr, ...) @GC_err_printf(ptr noundef @.str, i32 noundef %33)
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %32, %29
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %47, %34
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = icmp ult i32 %36, %37
  br i1 %38, label %39, label %50

39:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds [40 x ptr], ptr %4, i64 0, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  store ptr %43, ptr %6, align 8, !tbaa !9
  %44 = load ptr, ptr @GC_print_heap_obj, align 8, !tbaa !9
  %45 = load ptr, ptr %6, align 8, !tbaa !9
  call void %44(ptr noundef %45)
  %46 = load ptr, ptr %6, align 8, !tbaa !9
  call void @GC_free(ptr noundef %46)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  br label %47

47:                                               ; preds = %39
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = add i32 %48, 1
  store i32 %49, ptr %2, align 4, !tbaa !5
  br label %35, !llvm.loop !11

50:                                               ; preds = %35
  %51 = load i32, ptr %1, align 4, !tbaa !5
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %58

53:                                               ; preds = %50
  %54 = call ptr @getenv(ptr noundef @.str.1) #7
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %58

56:                                               ; preds = %53
  %57 = load ptr, ptr @GC_on_abort, align 8, !tbaa !9
  call void %57(ptr noundef @.str.2)
  call void @abort() #8
  unreachable

58:                                               ; preds = %53, %50
  store i32 0, ptr @GC_print_all_errors.printing_errors, align 4, !tbaa !5
  store i32 0, ptr %5, align 4
  br label %59

59:                                               ; preds = %58, %9
  call void @llvm.lifetime.end.p0(i64 320, ptr %4) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #7
  %60 = load i32, ptr %5, align 4
  switch i32 %60, label %62 [
    i32 0, label %61
    i32 1, label %61
  ]

61:                                               ; preds = %59, %59
  ret void

62:                                               ; preds = %59
  unreachable
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

declare void @GC_err_printf(ptr noundef, ...) #4

declare void @GC_free(ptr noundef) #4

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

; Function Attrs: nounwind
declare ptr @getenv(ptr noundef) #5

; Function Attrs: noreturn nounwind
declare void @abort() #6

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { "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 "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 = { 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 #7 = { nounwind }
attributes #8 = { 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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@GC_have_errors = external dso_local local_unnamed_addr global i32, align 4
@GC_print_all_errors.printing_errors = external hidden local_unnamed_addr global i32, align 4
@GC_n_leaked = external hidden local_unnamed_addr global i32, align 4
@GC_leaked = external hidden local_unnamed_addr global [40 x ptr], align 16
@GC_debugging_started = external local_unnamed_addr global i32, align 4
@GC_print_all_smashed = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [26 x i8], align 1
@GC_print_heap_obj = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1
@GC_on_abort = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [38 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @GC_print_all_errors() local_unnamed_addr #0 {
  %1 = alloca [40 x ptr], align 16
  call void @llvm.lifetime.start.p0(i64 320, ptr nonnull %1) #7
  %2 = load i32, ptr @GC_print_all_errors.printing_errors, align 4, !tbaa !5
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %3, label %19

3:                                                ; preds = %0
  %4 = load i32, ptr @GC_have_errors, align 4, !tbaa !5
  store i32 1, ptr @GC_print_all_errors.printing_errors, align 4, !tbaa !5
  %5 = load i32, ptr @GC_n_leaked, align 4, !tbaa !5
  %.not14 = icmp eq i32 %5, 0
  br i1 %.not14, label %6, label %.thread31

6:                                                ; preds = %3
  %7 = load i32, ptr @GC_debugging_started, align 4, !tbaa !5
  %.not15 = icmp eq i32 %7, 0
  br i1 %.not15, label %._crit_edge.thread28, label %._crit_edge

.thread31:                                        ; preds = %3
  %8 = zext i32 %5 to i64
  %9 = shl nuw nsw i64 %8, 3
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %1, ptr nonnull align 16 @GC_leaked, i64 %9, i1 false)
  store i32 0, ptr @GC_n_leaked, align 4, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @GC_leaked, i8 0, i64 %9, i1 false)
  %10 = load i32, ptr @GC_debugging_started, align 4, !tbaa !5
  %.not1532 = icmp eq i32 %10, 0
  br i1 %.not1532, label %.lr.ph.preheader, label %.thread33

.thread33:                                        ; preds = %.thread31
  %11 = load ptr, ptr @GC_print_all_smashed, align 8, !tbaa !9
  tail call void %11() #7
  br label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.thread33, %.thread31
  tail call void (ptr, ...) @GC_err_printf(ptr noundef nonnull @.str, i32 noundef %5) #7
  %wide.trip.count = zext i32 %5 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %12 = getelementptr inbounds [40 x ptr], ptr %1, i64 0, i64 %indvars.iv
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = load ptr, ptr @GC_print_heap_obj, align 8, !tbaa !9
  tail call void %14(ptr noundef %13) #7
  tail call void @GC_free(ptr noundef %13) #7
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.thread, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %6
  %15 = load ptr, ptr @GC_print_all_smashed, align 8, !tbaa !9
  tail call void %15() #7
  %.not16 = icmp eq i32 %4, 0
  br i1 %.not16, label %._crit_edge.thread28, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.lr.ph, %._crit_edge
  %16 = tail call ptr @getenv(ptr noundef nonnull @.str.1) #7
  %.not17 = icmp eq ptr %16, null
  br i1 %.not17, label %._crit_edge.thread28, label %17

17:                                               ; preds = %._crit_edge.thread
  %18 = load ptr, ptr @GC_on_abort, align 8, !tbaa !9
  tail call void %18(ptr noundef nonnull @.str.2) #7
  tail call void @abort() #8
  unreachable

._crit_edge.thread28:                             ; preds = %6, %._crit_edge.thread, %._crit_edge
  store i32 0, ptr @GC_print_all_errors.printing_errors, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %0, %._crit_edge.thread28
  call void @llvm.lifetime.end.p0(i64 320, ptr nonnull %1) #7
  ret void
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

declare void @GC_err_printf(ptr noundef, ...) local_unnamed_addr #4

declare void @GC_free(ptr noundef) local_unnamed_addr #4

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

; Function Attrs: nofree nounwind memory(read)
declare noundef ptr @getenv(ptr nocapture noundef) local_unnamed_addr #5

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #6

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { "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 = { nofree nounwind memory(read) "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 = { 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 #7 = { nounwind }
attributes #8 = { 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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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