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

; 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
define dso_local i32 @GC_n_set_marks(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.hblkhdr, ptr %7, i32 0, i32 6
  %9 = load i64, ptr %8, align 8, !tbaa !11
  store i64 %9, ptr %4, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store i64 0, ptr %5, align 8, !tbaa !15
  br label %10

10:                                               ; preds = %22, %1
  %11 = load i64, ptr %5, align 8, !tbaa !15
  %12 = icmp ult i64 %11, 5
  br i1 %12, label %13, label %25

13:                                               ; preds = %10
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.hblkhdr, ptr %14, i32 0, i32 10
  %16 = load i64, ptr %5, align 8, !tbaa !15
  %17 = getelementptr inbounds [5 x i64], ptr %15, i64 0, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !15
  %19 = call i32 @count_ones(i64 noundef %18)
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = add i32 %20, %19
  store i32 %21, ptr %3, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %13
  %23 = load i64, ptr %5, align 8, !tbaa !15
  %24 = add i64 %23, 1
  store i64 %24, ptr %5, align 8, !tbaa !15
  br label %10, !llvm.loop !16

25:                                               ; preds = %10
  %26 = load i32, ptr %3, align 4, !tbaa !9
  %27 = add i32 %26, -1
  store i32 %27, ptr %3, align 4, !tbaa !9
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.hblkhdr, ptr %28, i32 0, i32 3
  %30 = load i8, ptr %29, align 8, !tbaa !18
  %31 = zext i8 %30 to i32
  %32 = icmp eq i32 %31, 2
  br i1 %32, label %33, label %40

33:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %34 = load i64, ptr %4, align 8, !tbaa !15
  %35 = lshr i64 %34, 4
  %36 = trunc i64 %35 to i32
  store i32 %36, ptr %6, align 4, !tbaa !9
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = load i32, ptr %3, align 4, !tbaa !9
  %39 = udiv i32 %38, %37
  store i32 %39, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %40

40:                                               ; preds = %33, %25
  %41 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %41
}

; Function Attrs: nounwind uwtable
declare hidden i32 @count_ones(i64 noundef) #1

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


; 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
define dso_local i32 @GC_n_set_marks(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  %5 = load i64, ptr %4, align 8, !tbaa !12
  %6 = tail call i32 @count_ones(i64 noundef %5)
  %7 = getelementptr inbounds i8, ptr %0, i64 72
  %8 = load i64, ptr %7, align 8, !tbaa !12
  %9 = tail call i32 @count_ones(i64 noundef %8)
  %10 = add i32 %9, %6
  %11 = getelementptr inbounds i8, ptr %0, i64 80
  %12 = load i64, ptr %11, align 8, !tbaa !12
  %13 = tail call i32 @count_ones(i64 noundef %12)
  %14 = add i32 %13, %10
  %15 = getelementptr inbounds i8, ptr %0, i64 88
  %16 = load i64, ptr %15, align 8, !tbaa !12
  %17 = tail call i32 @count_ones(i64 noundef %16)
  %18 = add i32 %17, %14
  %19 = getelementptr inbounds i8, ptr %0, i64 96
  %20 = load i64, ptr %19, align 8, !tbaa !12
  %21 = tail call i32 @count_ones(i64 noundef %20)
  %22 = add i32 %21, %18
  %23 = add i32 %22, -1
  %24 = getelementptr inbounds i8, ptr %0, i64 24
  %25 = load i8, ptr %24, align 8, !tbaa !13
  %26 = icmp eq i8 %25, 2
  br i1 %26, label %27, label %31

27:                                               ; preds = %1
  %28 = lshr i64 %3, 4
  %29 = trunc i64 %28 to i32
  %30 = udiv i32 %23, %29
  br label %31

31:                                               ; preds = %27, %1
  %.1 = phi i32 [ %30, %27 ], [ %23, %1 ]
  ret i32 %.1
}

; Function Attrs: nounwind uwtable
declare hidden i32 @count_ones(i64 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" }

!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 = !{!6, !8, i64 24}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass