; 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._GC_arrays = type { i64, i64, i64, ptr, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i64, i64, i64, ptr, ptr, i64, i32, i64, i64, i64, %struct.dl_hashtbl_s, %struct.dl_hashtbl_s, %struct.fnlz_roots_s, i32, ptr, i64, i64, i32, i64, i64, i64, ptr, [64 x ptr], [8 x i8], [64 x ptr], [129 x ptr], [129 x ptr], [129 x ptr], [2049 x i64], [129 x ptr], [4096 x i8], [4096 x i64], [4096 x i64], ptr, [2048 x %struct.roots], [512 x %struct.exclusion], [2048 x ptr] }
%struct.dl_hashtbl_s = type { ptr, i64, i32 }
%struct.fnlz_roots_s = type { ptr, ptr }
%struct.roots = type { ptr, ptr, ptr, i32 }
%struct.exclusion = type { ptr, ptr }

@GC_arrays = external global %struct._GC_arrays, align 8
@GC_print_stats = external global i32, align 4
@.str.4 = external hidden unnamed_addr constant [23 x i8], align 1

; 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

declare void @GC_log_printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @GC_os_get_mem(i64 noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %6 = load i64, ptr %3, align 8, !tbaa !5
  %7 = call ptr @GC_unix_get_mem(i64 noundef %6)
  store ptr %7, ptr %4, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !9
  %9 = icmp eq ptr null, %8
  %10 = zext i1 %9 to i32
  %11 = sext i32 %10 to i64
  %12 = call i64 @llvm.expect.i64(i64 %11, i64 0)
  %13 = icmp ne i64 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %30

15:                                               ; preds = %1
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = load i64, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 8), align 8, !tbaa !11
  %18 = add i64 %17, %16
  store i64 %18, ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 8), align 8, !tbaa !11
  %19 = load i32, ptr @GC_print_stats, align 4, !tbaa !16
  %20 = icmp ne i32 %19, 2
  %21 = zext i1 %20 to i32
  %22 = sext i32 %21 to i64
  %23 = call i64 @llvm.expect.i64(i64 %22, i64 1)
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %15
  br label %28

26:                                               ; preds = %15
  %27 = load i64, ptr %3, align 8, !tbaa !5
  call void (ptr, ...) @GC_log_printf(ptr noundef @.str.4, i64 noundef %27)
  br label %28

28:                                               ; preds = %26, %25
  %29 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %29, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %30

30:                                               ; preds = %28, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %31 = load ptr, ptr %2, align 8
  ret ptr %31
}

declare ptr @GC_unix_get_mem(i64 noundef) #2

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

!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, !6, i64 64}
!12 = !{!"_GC_arrays", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !13, i64 176, !13, i64 180, !13, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !10, i64 216, !10, i64 224, !6, i64 232, !13, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !14, i64 272, !14, i64 296, !15, i64 320, !13, i64 336, !10, i64 344, !6, i64 352, !6, i64 360, !13, i64 368, !6, i64 376, !6, i64 384, !6, i64 392, !10, i64 400, !7, i64 408, !7, i64 920, !7, i64 928, !7, i64 1440, !7, i64 2472, !7, i64 3504, !7, i64 4536, !7, i64 20928, !7, i64 21960, !7, i64 26056, !7, i64 58824, !10, i64 91592, !7, i64 91600, !7, i64 157136, !7, i64 165328}
!13 = !{!"int", !7, i64 0}
!14 = !{!"dl_hashtbl_s", !10, i64 0, !6, i64 8, !13, i64 16}
!15 = !{!"fnlz_roots_s", !10, i64 0, !10, i64 8}
!16 = !{!13, !13, 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"

%struct._GC_arrays = type { i64, i64, i64, ptr, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i64, i64, i64, ptr, ptr, i64, i32, i64, i64, i64, %struct.dl_hashtbl_s, %struct.dl_hashtbl_s, %struct.fnlz_roots_s, i32, ptr, i64, i64, i32, i64, i64, i64, ptr, [64 x ptr], [8 x i8], [64 x ptr], [129 x ptr], [129 x ptr], [129 x ptr], [2049 x i64], [129 x ptr], [4096 x i8], [4096 x i64], [4096 x i64], ptr, [2048 x %struct.roots], [512 x %struct.exclusion], [2048 x ptr] }
%struct.dl_hashtbl_s = type { ptr, i64, i32 }
%struct.fnlz_roots_s = type { ptr, ptr }
%struct.roots = type { ptr, ptr, ptr, i32 }
%struct.exclusion = type { ptr, ptr }

@GC_arrays = external local_unnamed_addr global %struct._GC_arrays, align 8
@GC_print_stats = external local_unnamed_addr global i32, align 4
@.str.4 = external hidden unnamed_addr constant [23 x i8], align 1

declare void @GC_log_printf(ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @GC_os_get_mem(i64 noundef %0) local_unnamed_addr #1 {
  %2 = tail call ptr @GC_unix_get_mem(i64 noundef %0) #2
  %3 = icmp eq ptr %2, null
  br i1 %3, label %9, label %4, !prof !5

4:                                                ; preds = %1
  %5 = load i64, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 64), align 8, !tbaa !6
  %6 = add i64 %5, %0
  store i64 %6, ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 64), align 8, !tbaa !6
  %7 = load i32, ptr @GC_print_stats, align 4, !tbaa !15
  %.not = icmp eq i32 %7, 2
  br i1 %.not, label %8, label %9, !prof !5

8:                                                ; preds = %4
  tail call void (ptr, ...) @GC_log_printf(ptr noundef nonnull @.str.4, i64 noundef %0) #2
  br label %9

9:                                                ; preds = %8, %4, %1
  ret ptr %2
}

declare ptr @GC_unix_get_mem(i64 noundef) local_unnamed_addr #0

attributes #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 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 }

!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 = !{!7, !8, i64 64}
!7 = !{!"_GC_arrays", !8, i64 0, !8, i64 8, !8, i64 16, !11, i64 24, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !8, i64 64, !8, i64 72, !8, i64 80, !8, i64 88, !8, i64 96, !8, i64 104, !11, i64 112, !11, i64 120, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152, !11, i64 160, !11, i64 168, !12, i64 176, !12, i64 180, !12, i64 184, !8, i64 192, !8, i64 200, !8, i64 208, !11, i64 216, !11, i64 224, !8, i64 232, !12, i64 240, !8, i64 248, !8, i64 256, !8, i64 264, !13, i64 272, !13, i64 296, !14, i64 320, !12, i64 336, !11, i64 344, !8, i64 352, !8, i64 360, !12, i64 368, !8, i64 376, !8, i64 384, !8, i64 392, !11, i64 400, !9, i64 408, !9, i64 920, !9, i64 928, !9, i64 1440, !9, i64 2472, !9, i64 3504, !9, i64 4536, !9, i64 20928, !9, i64 21960, !9, i64 26056, !9, i64 58824, !11, i64 91592, !9, i64 91600, !9, i64 157136, !9, i64 165328}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = !{!"dl_hashtbl_s", !11, i64 0, !8, i64 8, !12, i64 16}
!14 = !{!"fnlz_roots_s", !11, i64 0, !11, i64 8}
!15 = !{!12, !12, i64 0}


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