; LLVM IR from hydrabus/hydrafw :: src/common (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.pool = type { ptr, i32, i8, i8, [128 x i8] }

@ram_pool = external hidden global %struct.pool, align 8
@pool_buf = external hidden global [65536 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local void @pool_init() #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i8 -128, ptr getelementptr inbounds (%struct.pool, ptr @ram_pool, i32 0, i32 2), align 4, !tbaa !5
  store i32 512, ptr getelementptr inbounds (%struct.pool, ptr @ram_pool, i32 0, i32 1), align 8, !tbaa !11
  store i8 0, ptr getelementptr inbounds (%struct.pool, ptr @ram_pool, i32 0, i32 3), align 1, !tbaa !12
  store ptr @pool_buf, ptr @ram_pool, align 8, !tbaa !13
  store i32 0, ptr %1, align 4, !tbaa !14
  br label %2

2:                                                ; preds = %10, %0
  %3 = load i32, ptr %1, align 4, !tbaa !14
  %4 = zext i32 %3 to i64
  %5 = icmp ult i64 %4, 128
  br i1 %5, label %6, label %13

6:                                                ; preds = %2
  %7 = load i32, ptr %1, align 4, !tbaa !14
  %8 = zext i32 %7 to i64
  %9 = getelementptr inbounds [128 x i8], ptr getelementptr inbounds (%struct.pool, ptr @ram_pool, i32 0, i32 4), i64 0, i64 %8
  store i8 0, ptr %9, align 1, !tbaa !15
  br label %10

10:                                               ; preds = %6
  %11 = load i32, ptr %1, align 4, !tbaa !14
  %12 = add i32 %11, 1
  store i32 %12, ptr %1, align 4, !tbaa !14
  br label %2, !llvm.loop !16

13:                                               ; preds = %2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!6, !8, i64 12}
!6 = !{!"pool", !7, i64 0, !10, i64 8, !8, i64 12, !8, i64 13, !8, i64 14}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !8, i64 13}
!13 = !{!6, !7, i64 0}
!14 = !{!10, !10, i64 0}
!15 = !{!8, !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%struct.pool = type { ptr, i32, i8, i8, [128 x i8] }

@ram_pool = external hidden local_unnamed_addr global %struct.pool, align 8
@pool_buf = external hidden global [65536 x i8], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @pool_init() local_unnamed_addr #0 {
  store i8 -128, ptr getelementptr inbounds (i8, ptr @ram_pool, i64 12), align 4, !tbaa !5
  store i32 512, ptr getelementptr inbounds (i8, ptr @ram_pool, i64 8), align 8, !tbaa !11
  store i8 0, ptr getelementptr inbounds (i8, ptr @ram_pool, i64 13), align 1, !tbaa !12
  store ptr @pool_buf, ptr @ram_pool, align 8, !tbaa !13
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(128) getelementptr inbounds (i8, ptr @ram_pool, i64 14), i8 0, i64 128, i1 false), !tbaa !14
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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, !8, i64 12}
!6 = !{!"pool", !7, i64 0, !10, i64 8, !8, i64 12, !8, i64 13, !8, i64 14}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !8, i64 13}
!13 = !{!6, !7, i64 0}
!14 = !{!8, !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass