; 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_all_interior_pointers = external dso_local global i32, align 4
@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 allocsize(0) uwtable
declare dso_local noalias ptr @GC_malloc_kind(i64 noundef, i32 noundef) #3

; Function Attrs: nounwind allocsize(0) uwtable
define dso_local noalias ptr @GC_malloc_explicitly_typed(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 eq i64 0, %9
  %11 = zext i1 %10 to i32
  %12 = sext i32 %11 to i64
  %13 = call i64 @llvm.expect.i64(i64 %12, i64 0)
  %14 = icmp ne i64 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store i64 1, ptr %4, align 8, !tbaa !5
  br label %16

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

27:                                               ; preds = %16
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = load i32, ptr @GC_all_interior_pointers, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = sub i64 8, %30
  %32 = add i64 %28, %31
  br label %34

33:                                               ; preds = %16
  br label %34

34:                                               ; preds = %33, %27
  %35 = phi i64 [ %32, %27 ], [ -1, %33 ]
  %36 = load i32, ptr @GC_explicit_kind, align 4, !tbaa !9
  %37 = call noalias ptr @GC_malloc_kind(i64 noundef %35, i32 noundef %36) #5
  store ptr %37, ptr %6, align 8, !tbaa !11
  %38 = load ptr, ptr %6, align 8, !tbaa !11
  %39 = icmp eq ptr null, %38
  %40 = zext i1 %39 to i32
  %41 = sext i32 %40 to i64
  %42 = call i64 @llvm.expect.i64(i64 %41, i64 0)
  %43 = icmp ne i64 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %34
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %66

45:                                               ; preds = %34
  %46 = load ptr, ptr %6, align 8, !tbaa !11
  %47 = call i64 @GC_size(ptr noundef %46)
  %48 = lshr i64 %47, 4
  %49 = shl i64 %48, 1
  store i64 %49, ptr %7, align 8, !tbaa !5
  %50 = load i64, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !11
  %52 = load i64, ptr %7, align 8, !tbaa !5
  %53 = sub i64 %52, 1
  %54 = getelementptr inbounds i64, ptr %51, i64 %53
  store i64 %50, ptr %54, align 8, !tbaa !5
  %55 = load i32, ptr @GC_manual_vdb, align 4, !tbaa !9
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %62

57:                                               ; preds = %45
  %58 = load ptr, ptr %6, align 8, !tbaa !11
  %59 = load i64, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds i64, ptr %58, i64 %59
  %61 = getelementptr inbounds i64, ptr %60, i64 -1
  call void @GC_dirty_inner(ptr noundef %61)
  br label %63

62:                                               ; preds = %45
  br label %63

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

66:                                               ; preds = %63, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %67 = load ptr, ptr %3, align 8
  ret ptr %67
}

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


; 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_all_interior_pointers = external dso_local local_unnamed_addr global i32, align 4
@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 allocsize(0) uwtable
declare dso_local noalias ptr @GC_malloc_kind(i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind allocsize(0) uwtable
define dso_local noalias ptr @GC_malloc_explicitly_typed(i64 noundef %0, i64 noundef %1) local_unnamed_addr #1 {
  %3 = icmp eq i64 %0, 0
  br i1 %3, label %4, label %5, !prof !5

4:                                                ; preds = %2
  br label %5

5:                                                ; preds = %4, %2
  %.012 = phi i64 [ 1, %4 ], [ %0, %2 ]
  %6 = load i32, ptr @GC_all_interior_pointers, align 4
  %7 = sext i32 %6 to i64
  %8 = add nsw i64 %7, -9
  %9 = icmp ult i64 %.012, %8
  %reass.sub = add i64 %.012, 8
  %10 = sub i64 %reass.sub, %7
  %11 = select i1 %9, i64 %10, i64 -1, !prof !6
  %12 = load i32, ptr @GC_explicit_kind, align 4, !tbaa !7
  %13 = tail call noalias ptr @GC_malloc_kind(i64 noundef %11, i32 noundef %12) #2
  %14 = icmp eq ptr %13, null
  br i1 %14, label %24, label %15, !prof !5

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

22:                                               ; preds = %15
  tail call void @GC_dirty_inner(ptr noundef nonnull %20)
  br label %23

23:                                               ; preds = %15, %22
  tail call void asm sideeffect " ", "X,~{memory},~{dirflag},~{fpsr},~{flags}"(i64 %1) #3, !srcloc !13
  br label %24

24:                                               ; preds = %5, %23
  ret ptr %13
}

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 = { allocsize(0) }
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 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!6 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !9, i64 0}
!13 = !{i64 2149280916}


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