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

; 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_incremental = external dso_local global i32, align 4
@GC_time_limit = external dso_local global i64, align 8
@GC_dont_gc = external global i32, align 4
@GC_fail_count = external dso_local global i32, align 4
@GC_obj_kinds = external global [16 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_collect_a_little_inner(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @GC_collect_or_expand(i64 noundef, i32 noundef, i32 noundef) #1

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

19:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %72

20:                                               ; preds = %2
  br label %21

21:                                               ; preds = %68, %20
  %22 = load ptr, ptr %6, align 8, !tbaa !14
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = icmp eq ptr null, %23
  br i1 %24, label %25, label %69

25:                                               ; preds = %21
  %26 = load i32, ptr @GC_incremental, align 4, !tbaa !9
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %35

28:                                               ; preds = %25
  %29 = load i64, ptr @GC_time_limit, align 8, !tbaa !5
  %30 = icmp ne i64 %29, 999999
  br i1 %30, label %31, label %35

31:                                               ; preds = %28
  %32 = load i32, ptr @GC_dont_gc, align 4, !tbaa !9
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %35, label %34

34:                                               ; preds = %31
  call void @GC_collect_a_little_inner(i32 noundef 1)
  br label %35

35:                                               ; preds = %34, %31, %28, %25
  %36 = load i64, ptr %4, align 8, !tbaa !5
  %37 = load i32, ptr %5, align 4, !tbaa !9
  call void @GC_continue_reclaim(i64 noundef %36, i32 noundef %37)
  %38 = load ptr, ptr %6, align 8, !tbaa !14
  %39 = load ptr, ptr %38, align 8, !tbaa !14
  %40 = icmp eq ptr null, %39
  br i1 %40, label %41, label %68

41:                                               ; preds = %35
  %42 = load i64, ptr %4, align 8, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !9
  call void @GC_new_hblk(i64 noundef %42, i32 noundef %43)
  %44 = load ptr, ptr %6, align 8, !tbaa !14
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = icmp eq ptr null, %45
  br i1 %46, label %47, label %67

47:                                               ; preds = %41
  %48 = load i32, ptr @GC_incremental, align 4, !tbaa !9
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %60

50:                                               ; preds = %47
  %51 = load i64, ptr @GC_time_limit, align 8, !tbaa !5
  %52 = icmp eq i64 %51, 999999
  br i1 %52, label %53, label %60

53:                                               ; preds = %50
  %54 = load i32, ptr %7, align 4, !tbaa !9
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %60, label %56

56:                                               ; preds = %53
  %57 = load i32, ptr @GC_dont_gc, align 4, !tbaa !9
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %60, label %59

59:                                               ; preds = %56
  call void @GC_collect_a_little_inner(i32 noundef 1)
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %66

60:                                               ; preds = %56, %53, %50, %47
  %61 = load i32, ptr %8, align 4, !tbaa !9
  %62 = call i32 @GC_collect_or_expand(i64 noundef 1, i32 noundef 0, i32 noundef %61)
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %65, label %64

64:                                               ; preds = %60
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %72

65:                                               ; preds = %60
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %65, %59
  br label %67

67:                                               ; preds = %66, %41
  br label %68

68:                                               ; preds = %67, %35
  br label %21, !llvm.loop !15

69:                                               ; preds = %21
  store i32 0, ptr @GC_fail_count, align 4, !tbaa !9
  %70 = load ptr, ptr %6, align 8, !tbaa !14
  %71 = load ptr, ptr %70, align 8, !tbaa !14
  store ptr %71, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %72

72:                                               ; preds = %69, %64, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %73 = load ptr, ptr %3, align 8
  ret ptr %73
}

declare void @GC_continue_reclaim(i64 noundef, i32 noundef) #2

declare void @GC_new_hblk(i64 noundef, i32 noundef) #2

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 = { "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 = !{!"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, !13, i64 0}
!12 = !{!"obj_kind", !13, i64 0, !13, i64 8, !6, i64 16, !10, i64 24, !10, 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 }

@GC_incremental = external dso_local local_unnamed_addr global i32, align 4
@GC_time_limit = external dso_local local_unnamed_addr global i64, align 8
@GC_dont_gc = external local_unnamed_addr global i32, align 4
@GC_fail_count = external dso_local 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 void @GC_collect_a_little_inner(i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local ptr @GC_allocobj(i64 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %1 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 %0
  %7 = icmp eq i64 %0, 0
  br i1 %7, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %2
  %8 = load ptr, ptr %6, align 8, !tbaa !12
  %9 = icmp eq ptr %8, null
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %34
  %.031 = phi i32 [ %.1.ph, %34 ], [ 0, %.preheader ]
  %.02230 = phi i32 [ %.123.ph, %34 ], [ 0, %.preheader ]
  %10 = load i32, ptr @GC_incremental, align 4, !tbaa !13
  %11 = icmp eq i32 %10, 0
  %12 = load i64, ptr @GC_time_limit, align 8
  %13 = icmp eq i64 %12, 999999
  %or.cond.not26 = select i1 %11, i1 true, i1 %13
  %14 = load i32, ptr @GC_dont_gc, align 4
  %15 = icmp ne i32 %14, 0
  %or.cond3 = select i1 %or.cond.not26, i1 true, i1 %15
  br i1 %or.cond3, label %17, label %16

16:                                               ; preds = %.lr.ph
  tail call void @GC_collect_a_little_inner(i32 noundef 1)
  br label %17

17:                                               ; preds = %16, %.lr.ph
  tail call void @GC_continue_reclaim(i64 noundef %0, i32 noundef %1) #2
  %18 = load ptr, ptr %6, align 8, !tbaa !12
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %._crit_edge

20:                                               ; preds = %17
  tail call void @GC_new_hblk(i64 noundef %0, i32 noundef %1) #2
  %21 = load ptr, ptr %6, align 8, !tbaa !12
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %._crit_edge

23:                                               ; preds = %20
  %24 = load i32, ptr @GC_incremental, align 4, !tbaa !13
  %25 = icmp eq i32 %24, 0
  %26 = load i64, ptr @GC_time_limit, align 8
  %27 = icmp ne i64 %26, 999999
  %or.cond5.not28 = select i1 %25, i1 true, i1 %27
  %28 = icmp ne i32 %.02230, 0
  %or.cond7 = select i1 %or.cond5.not28, i1 true, i1 %28
  %29 = load i32, ptr @GC_dont_gc, align 4
  %30 = icmp ne i32 %29, 0
  %or.cond9 = select i1 %or.cond7, i1 true, i1 %30
  br i1 %or.cond9, label %32, label %31

31:                                               ; preds = %23
  tail call void @GC_collect_a_little_inner(i32 noundef 1)
  br label %34

32:                                               ; preds = %23
  %33 = tail call i32 @GC_collect_or_expand(i64 noundef 1, i32 noundef 0, i32 noundef %.031)
  %.not = icmp eq i32 %33, 0
  br i1 %.not, label %.loopexit, label %34

34:                                               ; preds = %32, %31
  %.123.ph = phi i32 [ %.02230, %32 ], [ 1, %31 ]
  %.1.ph = phi i32 [ 1, %32 ], [ %.031, %31 ]
  %.pr = load ptr, ptr %6, align 8, !tbaa !12
  %35 = icmp eq ptr %.pr, null
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %17, %20, %34, %.preheader
  %.lcssa = phi ptr [ %8, %.preheader ], [ %21, %20 ], [ %18, %17 ], [ %.pr, %34 ]
  store i32 0, ptr @GC_fail_count, align 4, !tbaa !13
  br label %.loopexit

.loopexit:                                        ; preds = %32, %2, %._crit_edge
  %.024 = phi ptr [ %.lcssa, %._crit_edge ], [ null, %2 ], [ null, %32 ]
  ret ptr %.024
}

declare void @GC_continue_reclaim(i64 noundef, i32 noundef) local_unnamed_addr #1

declare void @GC_new_hblk(i64 noundef, i32 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 = !{!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 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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