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

@GC_manual_vdb = external hidden global i32, align 4
@GC_explicit_kind = external hidden global i32, align 4

; 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: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @GC_size(ptr noundef nonnull) #2

; Function Attrs: nounwind uwtable
declare hidden void @GC_dirty_inner(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @GC_generic_malloc_aligned(i64 noundef, i32 noundef, i32 noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @GC_clear_stack(ptr noundef) #2

; Function Attrs: nounwind allocsize(0) uwtable
declare dso_local noalias ptr @GC_malloc_explicitly_typed(i64 noundef, i64 noundef) #3

; Function Attrs: nounwind allocsize(0) uwtable
define dso_local noalias ptr @GC_malloc_explicitly_typed_ignore_off_page(i64 noundef %0, i64 noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %9 = load i64, ptr %4, align 8, !tbaa !5
  %10 = icmp ult i64 %9, 4088
  br i1 %10, label %11, label %15

11:                                               ; preds = %2
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = load i64, ptr %5, align 8, !tbaa !5
  %14 = call noalias ptr @GC_malloc_explicitly_typed(i64 noundef %12, i64 noundef %13) #5
  store ptr %14, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %59

15:                                               ; preds = %2
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = icmp ult i64 %16, -9
  %18 = zext i1 %17 to i32
  %19 = sext i32 %18 to i64
  %20 = call i64 @llvm.expect.i64(i64 %19, i64 1)
  %21 = icmp ne i64 %20, 0
  br i1 %21, label %22, label %25

22:                                               ; preds = %15
  %23 = load i64, ptr %4, align 8, !tbaa !5
  %24 = add i64 %23, 8
  br label %26

25:                                               ; preds = %15
  br label %26

26:                                               ; preds = %25, %22
  %27 = phi i64 [ %24, %22 ], [ -1, %25 ]
  %28 = load i32, ptr @GC_explicit_kind, align 4, !tbaa !9
  %29 = call ptr @GC_generic_malloc_aligned(i64 noundef %27, i32 noundef %28, i32 noundef 1, i64 noundef 0)
  %30 = call ptr @GC_clear_stack(ptr noundef %29)
  store ptr %30, ptr %6, align 8, !tbaa !11
  %31 = load ptr, ptr %6, align 8, !tbaa !11
  %32 = icmp eq ptr null, %31
  %33 = zext i1 %32 to i32
  %34 = sext i32 %33 to i64
  %35 = call i64 @llvm.expect.i64(i64 %34, i64 0)
  %36 = icmp ne i64 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %26
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %59

38:                                               ; preds = %26
  %39 = load ptr, ptr %6, align 8, !tbaa !11
  %40 = call i64 @GC_size(ptr noundef %39)
  %41 = lshr i64 %40, 4
  %42 = shl i64 %41, 1
  store i64 %42, ptr %7, align 8, !tbaa !5
  %43 = load i64, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %6, align 8, !tbaa !11
  %45 = load i64, ptr %7, align 8, !tbaa !5
  %46 = sub i64 %45, 1
  %47 = getelementptr inbounds i64, ptr %44, i64 %46
  store i64 %43, ptr %47, align 8, !tbaa !5
  %48 = load i32, ptr @GC_manual_vdb, align 4, !tbaa !9
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %55

50:                                               ; preds = %38
  %51 = load ptr, ptr %6, align 8, !tbaa !11
  %52 = load i64, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds i64, ptr %51, i64 %52
  %54 = getelementptr inbounds i64, ptr %53, i64 -1
  call void @GC_dirty_inner(ptr noundef %54)
  br label %56

55:                                               ; preds = %38
  br label %56

56:                                               ; preds = %55, %50
  %57 = load i64, ptr %5, align 8, !tbaa !5
  call void asm sideeffect " ", "X,~{memory},~{dirflag},~{fpsr},~{flags}"(i64 %57) #4, !srcloc !13
  %58 = load ptr, ptr %6, align 8, !tbaa !11
  store ptr %58, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %59

59:                                               ; preds = %56, %37, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %60 = load ptr, ptr %3, align 8
  ret ptr %60
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #2 = { 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 #3 = { nounwind allocsize(0) 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 #4 = { nounwind }
attributes #5 = { allocsize(0) }

!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 = !{i64 2149281535}


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

@GC_manual_vdb = external hidden local_unnamed_addr global i32, align 4
@GC_explicit_kind = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
declare dso_local i64 @GC_size(ptr noundef nonnull) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind allocsize(0) uwtable
declare dso_local noalias ptr @GC_malloc_explicitly_typed(i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind allocsize(0) uwtable
define dso_local noalias ptr @GC_malloc_explicitly_typed_ignore_off_page(i64 noundef %0, i64 noundef %1) local_unnamed_addr #1 {
  %3 = icmp ult i64 %0, 4088
  br i1 %3, label %4, label %6

4:                                                ; preds = %2
  %5 = tail call noalias ptr @GC_malloc_explicitly_typed(i64 noundef %0, i64 noundef %1) #3
  br label %21

6:                                                ; preds = %2
  %7 = tail call i64 @llvm.uadd.sat.i64(i64 %0, i64 8)
  %8 = load i32, ptr @GC_explicit_kind, align 4, !tbaa !5
  %9 = tail call ptr @GC_generic_malloc_aligned(i64 noundef %7, i32 noundef %8, i32 noundef 1, i64 noundef 0)
  %10 = tail call ptr @GC_clear_stack(ptr noundef %9)
  %11 = icmp eq ptr %10, null
  br i1 %11, label %21, label %12, !prof !9

12:                                               ; preds = %6
  %13 = tail call i64 @GC_size(ptr noundef %10)
  %14 = lshr i64 %13, 3
  %15 = and i64 %14, 2305843009213693950
  %16 = getelementptr i64, ptr %10, i64 %15
  %17 = getelementptr i8, ptr %16, i64 -8
  store i64 %1, ptr %17, align 8, !tbaa !10
  %18 = load i32, ptr @GC_manual_vdb, align 4, !tbaa !5
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %20, label %19

19:                                               ; preds = %12
  tail call void @GC_dirty_inner(ptr noundef nonnull %17)
  br label %20

20:                                               ; preds = %12, %19
  tail call void asm sideeffect " ", "X,~{memory},~{dirflag},~{fpsr},~{flags}"(i64 %1) #4, !srcloc !12
  br label %21

21:                                               ; preds = %6, %20, %4
  %.0 = phi ptr [ %5, %4 ], [ %10, %20 ], [ null, %6 ]
  ret ptr %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.uadd.sat.i64(i64, i64) #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 = { nounwind allocsize(0) 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { allocsize(0) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{i64 2149281535}


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