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

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

@GC_debugging_started = external global i32, align 4
@GC_obj_kinds = external global [16 x %struct.obj_kind], align 16

; Function Attrs: nounwind uwtable
declare dso_local ptr @GC_build_fl(ptr noundef, i64 noundef, i32 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 @GC_new_hblk(i64 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = shl i64 %7, 4
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = call ptr @GC_allochblk(i64 noundef %8, i32 noundef %9, i32 noundef 0, i64 noundef 0)
  store ptr %10, ptr %5, align 8, !tbaa !11
  %11 = load ptr, ptr %5, align 8, !tbaa !11
  %12 = icmp eq ptr null, %11
  %13 = zext i1 %12 to i32
  %14 = sext i32 %13 to i64
  %15 = call i64 @llvm.expect.i64(i64 %14, i64 0)
  %16 = icmp ne i64 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %2
  store i32 1, ptr %6, align 4
  br label %56

18:                                               ; preds = %2
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = icmp eq i32 %19, 2
  br i1 %20, label %21, label %24

21:                                               ; preds = %18
  %22 = load ptr, ptr %5, align 8, !tbaa !11
  %23 = call ptr @GC_find_header(ptr noundef %22)
  call void @GC_set_hdr_marks(ptr noundef %23)
  br label %24

24:                                               ; preds = %21, %18
  %25 = load ptr, ptr %5, align 8, !tbaa !11
  %26 = load i64, ptr %3, align 8, !tbaa !5
  %27 = shl i64 %26, 1
  %28 = load i32, ptr @GC_debugging_started, align 4, !tbaa !9
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %37, label %30

30:                                               ; preds = %24
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [16 x %struct.obj_kind], ptr @GC_obj_kinds, i64 0, i64 %32
  %34 = getelementptr inbounds %struct.obj_kind, ptr %33, i32 0, i32 4
  %35 = load i32, ptr %34, align 4, !tbaa !13
  %36 = icmp ne i32 %35, 0
  br label %37

37:                                               ; preds = %30, %24
  %38 = phi i1 [ true, %24 ], [ %36, %30 ]
  %39 = zext i1 %38 to i32
  %40 = load i32, ptr %4, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [16 x %struct.obj_kind], ptr @GC_obj_kinds, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.obj_kind, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 16, !tbaa !15
  %45 = load i64, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds ptr, ptr %44, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !11
  %48 = call ptr @GC_build_fl(ptr noundef %25, i64 noundef %27, i32 noundef %39, ptr noundef %47)
  %49 = load i32, ptr %4, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [16 x %struct.obj_kind], ptr @GC_obj_kinds, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.obj_kind, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 16, !tbaa !15
  %54 = load i64, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds ptr, ptr %53, i64 %54
  store ptr %48, ptr %55, align 8, !tbaa !11
  store i32 0, ptr %6, align 4
  br label %56

56:                                               ; preds = %37, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %57 = load i32, ptr %6, align 4
  switch i32 %57, label %59 [
    i32 0, label %58
    i32 1, label %58
  ]

58:                                               ; preds = %56, %56
  ret void

59:                                               ; preds = %56
  unreachable
}

declare ptr @GC_allochblk(i64 noundef, i32 noundef, i32 noundef, i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #3

declare void @GC_set_hdr_marks(ptr noundef) #2

declare ptr @GC_find_header(ptr noundef) #2

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

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

@GC_debugging_started = external local_unnamed_addr global i32, align 4
@GC_obj_kinds = external local_unnamed_addr global [16 x %struct.obj_kind], align 16

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

; Function Attrs: nounwind uwtable
define dso_local void @GC_new_hblk(i64 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = shl i64 %0, 4
  %4 = tail call ptr @GC_allochblk(i64 noundef %3, i32 noundef %1, i32 noundef 0, i64 noundef 0) #2
  %5 = icmp eq ptr %4, null
  br i1 %5, label %27, label %6, !prof !5

6:                                                ; preds = %2
  %7 = icmp eq i32 %1, 2
  br i1 %7, label %8, label %10

8:                                                ; preds = %6
  %9 = tail call ptr @GC_find_header(ptr noundef nonnull %4) #2
  tail call void @GC_set_hdr_marks(ptr noundef %9) #2
  br label %10

10:                                               ; preds = %8, %6
  %11 = shl i64 %0, 1
  %12 = load i32, ptr @GC_debugging_started, align 4, !tbaa !6
  %.not = icmp eq i32 %12, 0
  %13 = sext i32 %1 to i64
  br i1 %.not, label %14, label %._crit_edge

14:                                               ; preds = %10
  %15 = getelementptr inbounds [16 x %struct.obj_kind], ptr @GC_obj_kinds, i64 0, i64 %13, i32 4
  %16 = load i32, ptr %15, align 4, !tbaa !10
  %17 = icmp ne i32 %16, 0
  %18 = zext i1 %17 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %10, %14
  %19 = phi i32 [ %18, %14 ], [ 1, %10 ]
  %20 = getelementptr inbounds [16 x %struct.obj_kind], ptr @GC_obj_kinds, i64 0, i64 %13
  %21 = load ptr, ptr %20, align 16, !tbaa !14
  %22 = getelementptr inbounds ptr, ptr %21, i64 %0
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = tail call ptr @GC_build_fl(ptr noundef nonnull %4, i64 noundef %11, i32 noundef %19, ptr noundef %23)
  %25 = load ptr, ptr %20, align 16, !tbaa !14
  %26 = getelementptr inbounds ptr, ptr %25, i64 %0
  store ptr %24, ptr %26, align 8, !tbaa !15
  br label %27

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

declare ptr @GC_allochblk(i64 noundef, i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #1

declare void @GC_set_hdr_marks(ptr noundef) local_unnamed_addr #1

declare ptr @GC_find_header(ptr noundef) local_unnamed_addr #1

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 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!6 = !{!7, !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 28}
!11 = !{!"obj_kind", !12, i64 0, !12, i64 8, !13, i64 16, !7, i64 24, !7, i64 28}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!11, !12, i64 0}
!15 = !{!12, !12, i64 0}


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