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

; 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.hblkhdr = type { ptr, ptr, ptr, i8, i8, i16, i64, i64, ptr, i64, [5 x i64] }

; Function Attrs: nounwind uwtable
declare dso_local i32 @GC_has_other_debug_info(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

declare ptr @GC_find_header(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @GC_check_leaked(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = call i32 @GC_has_other_debug_info(ptr noundef %8)
  %10 = icmp sge i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %41

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 32
  store ptr %14, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = call ptr @GC_find_header(ptr noundef %15)
  %17 = getelementptr inbounds %struct.hblkhdr, ptr %16, i32 0, i32 6
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = sub i64 %18, 32
  %20 = lshr i64 %19, 3
  store i64 %20, ptr %5, align 8, !tbaa !13
  store i64 0, ptr %4, align 8, !tbaa !13
  br label %21

21:                                               ; preds = %37, %12
  %22 = load i64, ptr %4, align 8, !tbaa !13
  %23 = load i64, ptr %5, align 8, !tbaa !13
  %24 = icmp ult i64 %22, %23
  br i1 %24, label %25, label %40

25:                                               ; preds = %21
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load i64, ptr %4, align 8, !tbaa !13
  %28 = getelementptr inbounds i64, ptr %26, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !13
  %30 = icmp ne i64 %29, -1171307680339476753
  br i1 %30, label %31, label %36

31:                                               ; preds = %25
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  call void @GC_set_mark_bit(ptr noundef %32)
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load i64, ptr %4, align 8, !tbaa !13
  %35 = getelementptr inbounds i64, ptr %33, i64 %34
  call void @GC_add_smashed(ptr noundef %35)
  br label %40

36:                                               ; preds = %25
  br label %37

37:                                               ; preds = %36
  %38 = load i64, ptr %4, align 8, !tbaa !13
  %39 = add i64 %38, 1
  store i64 %39, ptr %4, align 8, !tbaa !13
  br label %21, !llvm.loop !14

40:                                               ; preds = %31, %21
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %41

41:                                               ; preds = %40, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %42 = load i32, ptr %2, align 4
  ret i32 %42
}

declare void @GC_set_mark_bit(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @GC_add_smashed(ptr noundef) #0

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 = { 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, !12, i64 32}
!10 = !{!"hblkhdr", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !7, i64 25, !11, i64 26, !12, i64 32, !12, i64 40, !6, i64 48, !12, i64 56, !7, i64 64}
!11 = !{!"short", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

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

declare ptr @GC_find_header(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @GC_check_leaked(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @GC_has_other_debug_info(ptr noundef %0)
  %3 = icmp sgt i32 %2, -1
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = tail call ptr @GC_find_header(ptr noundef %0) #2
  %7 = getelementptr inbounds i8, ptr %6, i64 32
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = add i64 %8, -32
  %.not13 = icmp ult i64 %9, 8
  br i1 %.not13, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %10 = lshr i64 %9, 3
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %15
  %.01112 = phi i64 [ %16, %15 ], [ 0, %.lr.ph.preheader ]
  %11 = getelementptr inbounds i64, ptr %5, i64 %.01112
  %12 = load i64, ptr %11, align 8, !tbaa !12
  %.not = icmp eq i64 %12, -1171307680339476753
  br i1 %.not, label %15, label %13

13:                                               ; preds = %.lr.ph
  %14 = getelementptr inbounds i64, ptr %5, i64 %.01112
  tail call void @GC_set_mark_bit(ptr noundef nonnull %0) #2
  tail call void @GC_add_smashed(ptr noundef nonnull %14)
  br label %.loopexit

15:                                               ; preds = %.lr.ph
  %16 = add nuw nsw i64 %.01112, 1
  %exitcond.not = icmp eq i64 %16, %10
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !13

.loopexit:                                        ; preds = %15, %4, %13, %1
  %.0 = phi i32 [ 1, %1 ], [ 0, %13 ], [ 0, %4 ], [ 0, %15 ]
  ret i32 %.0
}

declare void @GC_set_mark_bit(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @GC_add_smashed(ptr noundef) local_unnamed_addr #0

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, !11, i64 32}
!6 = !{!"hblkhdr", !7, i64 0, !7, i64 8, !7, i64 16, !8, i64 24, !8, i64 25, !10, i64 26, !11, i64 32, !11, i64 40, !7, i64 48, !11, i64 56, !8, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!11, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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