; LLVM IR from mirohs/gc :: util (base_atexit)

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

@stderr = external global ptr, align 8
@exit_status = external hidden global i32, align 4
@base_check_count = external hidden global i32, align 4
@base_check_success_count = external hidden global i32, align 4
@.str.70 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.71 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.72 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.73 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.74 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.75 = external hidden unnamed_addr constant [24 x i8], align 1

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

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local void @base_atexit() #2 {
  %1 = alloca i32, align 4
  %2 = load i32, ptr @exit_status, align 4, !tbaa !5
  %3 = icmp eq i32 %2, 0
  br i1 %3, label %4, label %57

4:                                                ; preds = %0
  %5 = load i32, ptr @base_check_count, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %7, label %56

7:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  %8 = load i32, ptr @base_check_count, align 4, !tbaa !5
  %9 = load i32, ptr @base_check_success_count, align 4, !tbaa !5
  %10 = sub nsw i32 %8, %9
  store i32 %10, ptr %1, align 4, !tbaa !5
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = icmp sle i32 %11, 0
  br i1 %12, label %13, label %35

13:                                               ; preds = %7
  %14 = load i32, ptr @base_check_count, align 4, !tbaa !5
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %16, label %19

16:                                               ; preds = %13
  %17 = load ptr, ptr @stderr, align 8, !tbaa !9
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef @.str.70) #3
  br label %34

19:                                               ; preds = %13
  %20 = load i32, ptr @base_check_count, align 4, !tbaa !5
  %21 = icmp eq i32 %20, 2
  br i1 %21, label %22, label %25

22:                                               ; preds = %19
  %23 = load ptr, ptr @stderr, align 8, !tbaa !9
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef @.str.71) #3
  br label %33

25:                                               ; preds = %19
  %26 = load i32, ptr @base_check_count, align 4, !tbaa !5
  %27 = icmp sge i32 %26, 3
  br i1 %27, label %28, label %32

28:                                               ; preds = %25
  %29 = load ptr, ptr @stderr, align 8, !tbaa !9
  %30 = load i32, ptr @base_check_count, align 4, !tbaa !5
  %31 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef @.str.72, i32 noundef %30) #3
  br label %32

32:                                               ; preds = %28, %25
  br label %33

33:                                               ; preds = %32, %22
  br label %34

34:                                               ; preds = %33, %16
  br label %55

35:                                               ; preds = %7
  %36 = load i32, ptr @base_check_count, align 4, !tbaa !5
  %37 = icmp eq i32 %36, 1
  br i1 %37, label %38, label %41

38:                                               ; preds = %35
  %39 = load ptr, ptr @stderr, align 8, !tbaa !9
  %40 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef @.str.73) #3
  br label %54

41:                                               ; preds = %35
  %42 = load i32, ptr @base_check_success_count, align 4, !tbaa !5
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %48

44:                                               ; preds = %41
  %45 = load ptr, ptr @stderr, align 8, !tbaa !9
  %46 = load i32, ptr @base_check_count, align 4, !tbaa !5
  %47 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.74, i32 noundef %46) #3
  br label %53

48:                                               ; preds = %41
  %49 = load ptr, ptr @stderr, align 8, !tbaa !9
  %50 = load i32, ptr %1, align 4, !tbaa !5
  %51 = load i32, ptr @base_check_count, align 4, !tbaa !5
  %52 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %49, ptr noundef @.str.75, i32 noundef %50, i32 noundef %51) #3
  br label %53

53:                                               ; preds = %48, %44
  br label %54

54:                                               ; preds = %53, %38
  br label %55

55:                                               ; preds = %54, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %56

56:                                               ; preds = %55, %4
  br label %57

57:                                               ; preds = %56, %0
  ret void
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"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}


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

@stderr = external local_unnamed_addr global ptr, align 8
@exit_status = external hidden local_unnamed_addr global i32, align 4
@base_check_count = external hidden local_unnamed_addr global i32, align 4
@base_check_success_count = external hidden local_unnamed_addr global i32, align 4
@.str.70 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.71 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.72 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.73 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.74 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.75 = external hidden unnamed_addr constant [24 x i8], align 1

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @base_atexit() local_unnamed_addr #1 {
  %1 = load i32, ptr @exit_status, align 4, !tbaa !5
  %2 = icmp eq i32 %1, 0
  %3 = load i32, ptr @base_check_count, align 4
  %4 = icmp sgt i32 %3, 0
  %or.cond = select i1 %2, i1 %4, i1 false
  br i1 %or.cond, label %5, label %29

5:                                                ; preds = %0
  %6 = load i32, ptr @base_check_success_count, align 4, !tbaa !5
  %7 = sub nsw i32 %3, %6
  %8 = icmp slt i32 %7, 1
  br i1 %8, label %9, label %17

9:                                                ; preds = %5
  %10 = load ptr, ptr @stderr, align 8, !tbaa !9
  switch i32 %3, label %15 [
    i32 1, label %11
    i32 2, label %13
  ]

11:                                               ; preds = %9
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str.70) #2
  br label %29

13:                                               ; preds = %9
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str.71) #2
  br label %29

15:                                               ; preds = %9
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str.72, i32 noundef %3) #2
  br label %29

17:                                               ; preds = %5
  %18 = icmp eq i32 %3, 1
  br i1 %18, label %19, label %22

19:                                               ; preds = %17
  %20 = load ptr, ptr @stderr, align 8, !tbaa !9
  %21 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str.73) #2
  br label %29

22:                                               ; preds = %17
  %23 = icmp eq i32 %6, 0
  %24 = load ptr, ptr @stderr, align 8, !tbaa !9
  br i1 %23, label %25, label %27

25:                                               ; preds = %22
  %26 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str.74, i32 noundef %3) #2
  br label %29

27:                                               ; preds = %22
  %28 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str.75, i32 noundef %7, i32 noundef %3) #2
  br label %29

29:                                               ; preds = %13, %15, %11, %25, %27, %19, %0
  ret void
}

attributes #0 = { 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 #1 = { nofree 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 = { 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 = !{!"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}


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