; 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_is_initialized = external hidden global i32, align 4
@GC_page_size = external hidden global i64, align 8

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

; Function Attrs: nounwind uwtable
declare dso_local void @GC_init() #1

; Function Attrs: nounwind allocsize(1) uwtable
declare dso_local noalias ptr @GC_memalign(i64 noundef, i64 noundef) #2

; Function Attrs: nounwind allocsize(0) uwtable
define dso_local noalias ptr @GC_pvalloc(i64 noundef %0) #3 {
  %2 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  %3 = load i32, ptr @GC_is_initialized, align 4, !tbaa !9
  %4 = sext i32 %3 to i64
  %5 = call i64 @llvm.expect.i64(i64 %4, i64 1)
  %6 = icmp ne i64 %5, 0
  br i1 %6, label %8, label %7

7:                                                ; preds = %1
  call void @GC_init()
  br label %8

8:                                                ; preds = %7, %1
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = load i64, ptr @GC_page_size, align 8, !tbaa !5
  %11 = sub i64 %10, 1
  %12 = sub i64 -1, %11
  %13 = icmp ult i64 %9, %12
  %14 = zext i1 %13 to i32
  %15 = sext i32 %14 to i64
  %16 = call i64 @llvm.expect.i64(i64 %15, i64 1)
  %17 = icmp ne i64 %16, 0
  br i1 %17, label %18, label %23

18:                                               ; preds = %8
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %20 = load i64, ptr @GC_page_size, align 8, !tbaa !5
  %21 = sub i64 %20, 1
  %22 = add i64 %19, %21
  br label %24

23:                                               ; preds = %8
  br label %24

24:                                               ; preds = %23, %18
  %25 = phi i64 [ %22, %18 ], [ -1, %23 ]
  %26 = load i64, ptr @GC_page_size, align 8, !tbaa !5
  %27 = sub i64 %26, 1
  %28 = xor i64 %27, -1
  %29 = and i64 %25, %28
  store i64 %29, ptr %2, align 8, !tbaa !5
  %30 = load i64, ptr @GC_page_size, align 8, !tbaa !5
  %31 = load i64, ptr %2, align 8, !tbaa !5
  %32 = call noalias ptr @GC_memalign(i64 noundef %30, i64 noundef %31) #4
  ret ptr %32
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 allocsize(1) 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 = { allocsize(1) }

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


; 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_is_initialized = external hidden local_unnamed_addr global i32, align 4
@GC_page_size = external hidden local_unnamed_addr global i64, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @GC_init() local_unnamed_addr #0

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

; Function Attrs: nounwind allocsize(0) uwtable
define dso_local noalias ptr @GC_pvalloc(i64 noundef %0) local_unnamed_addr #2 {
  %2 = load i32, ptr @GC_is_initialized, align 4, !tbaa !5
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %3, label %4, !prof !9

3:                                                ; preds = %1
  tail call void @GC_init()
  br label %4

4:                                                ; preds = %3, %1
  %5 = load i64, ptr @GC_page_size, align 8
  %6 = sub i64 0, %5
  %7 = icmp ugt i64 %6, %0
  %8 = add i64 %0, -1
  %9 = add i64 %8, %5
  %10 = select i1 %7, i64 %9, i64 -1, !prof !10
  %11 = and i64 %10, %6
  %12 = tail call noalias ptr @GC_memalign(i64 noundef %5, i64 noundef %11) #3
  ret ptr %12
}

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(1) 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 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 #3 = { allocsize(1) }

!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 = !{!"branch_weights", !"expected", i32 2000, i32 1}


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