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

; 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_kind = type { ptr, ptr, i64, i32, i32 }

@.str.53 = external hidden unnamed_addr constant [39 x i8], align 1
@GC_obj_kinds = external hidden global <{ %struct.obj_kind, %struct.obj_kind, %struct.obj_kind, [13 x %struct.obj_kind] }>, align 16

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @GC_printf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @GC_print_free_list(i32 noundef %0, i64 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [16 x %struct.obj_kind], ptr @GC_obj_kinds, i64 0, i64 %8
  %10 = getelementptr inbounds %struct.obj_kind, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 16, !tbaa !11
  %12 = load i64, ptr %4, align 8, !tbaa !9
  %13 = getelementptr inbounds ptr, ptr %11, i64 %12
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  store ptr %14, ptr %5, align 8, !tbaa !14
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %27, %2
  %16 = load ptr, ptr %5, align 8, !tbaa !14
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %30

18:                                               ; preds = %15
  %19 = load ptr, ptr %5, align 8, !tbaa !14
  %20 = ptrtoint ptr %19 to i64
  %21 = and i64 %20, -4096
  %22 = inttoptr i64 %21 to ptr
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !14
  call void (ptr, ...) @GC_printf(ptr noundef @.str.53, ptr noundef %22, i32 noundef %23, ptr noundef %24)
  %25 = load ptr, ptr %5, align 8, !tbaa !14
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  store ptr %26, ptr %5, align 8, !tbaa !14
  br label %27

27:                                               ; preds = %18
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %6, align 4, !tbaa !5
  br label %15, !llvm.loop !15

30:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"obj_kind", !13, i64 0, !13, i64 8, !10, i64 16, !6, i64 24, !6, i64 28}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

%struct.obj_kind = type { ptr, ptr, i64, i32, i32 }

@.str.53 = external hidden unnamed_addr constant [39 x i8], align 1
@GC_obj_kinds = external hidden local_unnamed_addr global <{ %struct.obj_kind, %struct.obj_kind, %struct.obj_kind, [13 x %struct.obj_kind] }>, align 16

; Function Attrs: nounwind uwtable
declare dso_local void @GC_printf(ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @GC_print_free_list(i32 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [16 x %struct.obj_kind], ptr @GC_obj_kinds, i64 0, i64 %3
  %5 = load ptr, ptr %4, align 16, !tbaa !5
  %6 = getelementptr inbounds ptr, ptr %5, i64 %1
  %.078 = load ptr, ptr %6, align 8, !tbaa !12
  %.not9 = icmp eq ptr %.078, null
  br i1 %.not9, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.0711 = phi ptr [ %.07, %.lr.ph ], [ %.078, %2 ]
  %.010 = phi i32 [ %10, %.lr.ph ], [ 0, %2 ]
  %7 = ptrtoint ptr %.0711 to i64
  %8 = and i64 %7, -4096
  %9 = inttoptr i64 %8 to ptr
  tail call void (ptr, ...) @GC_printf(ptr noundef nonnull @.str.53, ptr noundef %9, i32 noundef %.010, ptr noundef nonnull %.0711)
  %10 = add nuw nsw i32 %.010, 1
  %.07 = load ptr, ptr %.0711, align 8, !tbaa !12
  %.not = icmp eq ptr %.07, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %2
  ret void
}

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

!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, !7, i64 0}
!6 = !{!"obj_kind", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24, !11, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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