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

; 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_on_abort = external global ptr, align 8
@GC_page_size = external dso_local global i64, align 8
@.str.8 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [18 x i8], align 1
@GC_log_pagesize = 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: noreturn nounwind
declare void @abort() #1

; 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
define dso_local void @GC_setpagesize() #2 {
  %1 = alloca i64, align 8
  %2 = alloca i32, align 4
  %3 = call i32 @getpagesize() #4
  %4 = zext i32 %3 to i64
  store i64 %4, ptr @GC_page_size, align 8, !tbaa !5
  %5 = load i64, ptr @GC_page_size, align 8, !tbaa !5
  %6 = icmp eq i64 0, %5
  br i1 %6, label %7, label %9

7:                                                ; preds = %0
  %8 = load ptr, ptr @GC_on_abort, align 8, !tbaa !9
  call void %8(ptr noundef @.str.8)
  call void @abort() #5
  unreachable

9:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 0, ptr %2, align 4, !tbaa !11
  %10 = load i64, ptr @GC_page_size, align 8, !tbaa !5
  %11 = sub i64 %10, 1
  %12 = load i64, ptr @GC_page_size, align 8, !tbaa !5
  %13 = and i64 %11, %12
  %14 = icmp ne i64 %13, 0
  br i1 %14, label %15, label %17

15:                                               ; preds = %9
  %16 = load ptr, ptr @GC_on_abort, align 8, !tbaa !9
  call void %16(ptr noundef @.str.9)
  call void @abort() #5
  unreachable

17:                                               ; preds = %9
  %18 = load i64, ptr @GC_page_size, align 8, !tbaa !5
  store i64 %18, ptr %1, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %25, %17
  %20 = load i64, ptr %1, align 8, !tbaa !5
  %21 = icmp ugt i64 %20, 1
  br i1 %21, label %22, label %28

22:                                               ; preds = %19
  %23 = load i32, ptr %2, align 4, !tbaa !11
  %24 = add i32 %23, 1
  store i32 %24, ptr %2, align 4, !tbaa !11
  br label %25

25:                                               ; preds = %22
  %26 = load i64, ptr %1, align 8, !tbaa !5
  %27 = lshr i64 %26, 1
  store i64 %27, ptr %1, align 8, !tbaa !5
  br label %19, !llvm.loop !13

28:                                               ; preds = %19
  %29 = load i32, ptr %2, align 4, !tbaa !11
  store i32 %29, ptr @GC_log_pagesize, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #6
  ret void
}

; Function Attrs: nounwind willreturn memory(none)
declare i32 @getpagesize() #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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 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 willreturn memory(none) "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 willreturn memory(none) }
attributes #5 = { noreturn nounwind }
attributes #6 = { 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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@GC_on_abort = external local_unnamed_addr global ptr, align 8
@GC_page_size = external dso_local local_unnamed_addr global i64, align 8
@.str.8 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [18 x i8], align 1
@GC_log_pagesize = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @GC_setpagesize() local_unnamed_addr #1 {
  %1 = tail call i32 @getpagesize() #3
  %2 = zext i32 %1 to i64
  store i64 %2, ptr @GC_page_size, align 8, !tbaa !5
  %3 = icmp eq i32 %1, 0
  br i1 %3, label %4, label %6

4:                                                ; preds = %0
  %5 = load ptr, ptr @GC_on_abort, align 8, !tbaa !9
  tail call void %5(ptr noundef nonnull @.str.8) #4
  tail call void @abort() #5
  unreachable

6:                                                ; preds = %0
  %7 = add nuw nsw i64 %2, 4294967295
  %8 = and i64 %7, %2
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %.preheader, label %9

.preheader:                                       ; preds = %6
  %.not8 = icmp eq i32 %1, 1
  br i1 %.not8, label %._crit_edge, label %.lr.ph

9:                                                ; preds = %6
  %10 = load ptr, ptr @GC_on_abort, align 8, !tbaa !9
  tail call void %10(ptr noundef nonnull @.str.9) #4
  tail call void @abort() #5
  unreachable

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.07 = phi i32 [ %11, %.lr.ph ], [ 0, %.preheader ]
  %.046 = phi i64 [ %12, %.lr.ph ], [ %2, %.preheader ]
  %11 = add nuw nsw i32 %.07, 1
  %12 = lshr i64 %.046, 1
  %13 = icmp ugt i64 %.046, 3
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.0.lcssa = phi i32 [ 0, %.preheader ], [ %11, %.lr.ph ]
  store i32 %.0.lcssa, ptr @GC_log_pagesize, align 4, !tbaa !13
  ret void
}

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare i32 @getpagesize() local_unnamed_addr #2

attributes #0 = { noreturn nounwind "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 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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 willreturn memory(none) }
attributes #4 = { nounwind }
attributes #5 = { noreturn 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 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}


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