; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/memory.ll (ZN3qOS3mem4pool4initEv)

; 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"

%"class.qOS::mem::pool" = type { ptr, ptr, %"struct.qOS::mem::blockConnect_t", ptr, i64, i64 }
%"struct.qOS::mem::blockConnect_t" = type { ptr, i64 }

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3qOS3mem4pool4initEv(ptr noundef nonnull align 8 dereferenceable(56) %0) #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %9 = getelementptr inbounds %"class.qOS::mem::pool", ptr %8, i32 0, i32 4
  %10 = load i64, ptr %9, align 8, !tbaa !9
  store i64 %10, ptr %7, align 8, !tbaa !13
  %11 = getelementptr inbounds %"class.qOS::mem::pool", ptr %8, i32 0, i32 3
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %13 = ptrtoint ptr %12 to i64
  store i64 %13, ptr %5, align 8, !tbaa !13
  %14 = load i64, ptr %5, align 8, !tbaa !13
  %15 = and i64 %14, 7
  %16 = icmp ne i64 0, %15
  br i1 %16, label %17, label %29

17:                                               ; preds = %1
  %18 = load i64, ptr %5, align 8, !tbaa !13
  %19 = add i64 %18, 7
  store i64 %19, ptr %5, align 8, !tbaa !13
  %20 = load i64, ptr %5, align 8, !tbaa !13
  %21 = and i64 %20, -8
  store i64 %21, ptr %5, align 8, !tbaa !13
  %22 = load i64, ptr %5, align 8, !tbaa !13
  %23 = getelementptr inbounds %"class.qOS::mem::pool", ptr %8, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = ptrtoint ptr %24 to i64
  %26 = sub i64 %22, %25
  %27 = load i64, ptr %7, align 8, !tbaa !13
  %28 = sub i64 %27, %26
  store i64 %28, ptr %7, align 8, !tbaa !13
  br label %29

29:                                               ; preds = %17, %1
  %30 = load i64, ptr %5, align 8, !tbaa !13
  %31 = inttoptr i64 %30 to ptr
  store ptr %31, ptr %4, align 8, !tbaa !5
  %32 = invoke noundef ptr @_ZN3qOS12aligned_castIPNS_3mem14blockConnect_tEPhEET_RT0_(ptr noundef nonnull align 8 dereferenceable(8) %4)
          to label %33 unwind label %73

33:                                               ; preds = %29
  %34 = getelementptr inbounds %"class.qOS::mem::pool", ptr %8, i32 0, i32 2
  %35 = getelementptr inbounds %"struct.qOS::mem::blockConnect_t", ptr %34, i32 0, i32 0
  store ptr %32, ptr %35, align 8, !tbaa !15
  %36 = getelementptr inbounds %"class.qOS::mem::pool", ptr %8, i32 0, i32 2
  %37 = getelementptr inbounds %"struct.qOS::mem::blockConnect_t", ptr %36, i32 0, i32 1
  store i64 0, ptr %37, align 8, !tbaa !16
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = ptrtoint ptr %38 to i64
  store i64 %39, ptr %6, align 8, !tbaa !13
  %40 = load i64, ptr %6, align 8, !tbaa !13
  %41 = load i64, ptr %7, align 8, !tbaa !13
  %42 = add i64 %40, %41
  store i64 %42, ptr %5, align 8, !tbaa !13
  %43 = load i64, ptr %5, align 8, !tbaa !13
  %44 = sub i64 %43, 16
  store i64 %44, ptr %5, align 8, !tbaa !13
  %45 = load i64, ptr %5, align 8, !tbaa !13
  %46 = and i64 %45, -8
  store i64 %46, ptr %5, align 8, !tbaa !13
  %47 = load i64, ptr %5, align 8, !tbaa !13
  %48 = inttoptr i64 %47 to ptr
  %49 = getelementptr inbounds %"class.qOS::mem::pool", ptr %8, i32 0, i32 1
  store ptr %48, ptr %49, align 8, !tbaa !17
  %50 = getelementptr inbounds %"class.qOS::mem::pool", ptr %8, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !17
  %52 = getelementptr inbounds %"struct.qOS::mem::blockConnect_t", ptr %51, i32 0, i32 0
  store ptr null, ptr %52, align 8, !tbaa !18
  %53 = getelementptr inbounds %"class.qOS::mem::pool", ptr %8, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !17
  %55 = getelementptr inbounds %"struct.qOS::mem::blockConnect_t", ptr %54, i32 0, i32 1
  store i64 0, ptr %55, align 8, !tbaa !19
  %56 = invoke noundef ptr @_ZN3qOS12aligned_castIPNS_3mem14blockConnect_tEPhEET_RT0_(ptr noundef nonnull align 8 dereferenceable(8) %4)
          to label %57 unwind label %73

57:                                               ; preds = %33
  store ptr %56, ptr %3, align 8, !tbaa !5
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = ptrtoint ptr %58 to i64
  store i64 %59, ptr %6, align 8, !tbaa !13
  %60 = load i64, ptr %5, align 8, !tbaa !13
  %61 = load i64, ptr %6, align 8, !tbaa !13
  %62 = sub i64 %60, %61
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %"struct.qOS::mem::blockConnect_t", ptr %63, i32 0, i32 1
  store i64 %62, ptr %64, align 8, !tbaa !19
  %65 = getelementptr inbounds %"class.qOS::mem::pool", ptr %8, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !17
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %"struct.qOS::mem::blockConnect_t", ptr %67, i32 0, i32 0
  store ptr %66, ptr %68, align 8, !tbaa !18
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %"struct.qOS::mem::blockConnect_t", ptr %69, i32 0, i32 1
  %71 = load i64, ptr %70, align 8, !tbaa !19
  %72 = getelementptr inbounds %"class.qOS::mem::pool", ptr %8, i32 0, i32 5
  store i64 %71, ptr %72, align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void

73:                                               ; preds = %33, %29
  %74 = landingpad { ptr, i32 }
          catch ptr null
  %75 = extractvalue { ptr, i32 } %74, 0
  call void @__clang_call_terminate(ptr %75) #5
  unreachable
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN3qOS12aligned_castIPNS_3mem14blockConnect_tEPhEET_RT0_(ptr noundef nonnull align 8 dereferenceable(8)) #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { inlinehint mustprogress 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 = { noinline noreturn nounwind uwtable "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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 40}
!10 = !{!"_ZTSN3qOS3mem4poolE", !6, i64 8, !11, i64 16, !6, i64 32, !12, i64 40, !12, i64 48}
!11 = !{!"_ZTSN3qOS3mem14blockConnect_tE", !6, i64 0, !12, i64 8}
!12 = !{!"long", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!10, !6, i64 32}
!15 = !{!10, !6, i64 16}
!16 = !{!10, !12, i64 24}
!17 = !{!10, !6, i64 8}
!18 = !{!11, !6, i64 0}
!19 = !{!11, !12, i64 8}
!20 = !{!10, !12, i64 48}


; 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"

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3qOS3mem4pool4initEv(ptr nocapture noundef nonnull align 8 dereferenceable(56) %0) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %7 = ptrtoint ptr %6 to i64
  %8 = and i64 %7, 7
  %.not = icmp eq i64 %8, 0
  %9 = add i64 %7, 7
  %10 = and i64 %9, -8
  %.neg = sub i64 %7, %10
  %11 = inttoptr i64 %10 to ptr
  %.017 = select i1 %.not, ptr %6, ptr %11
  %12 = select i1 %.not, i64 0, i64 %.neg
  %.0 = add i64 %12, %4
  store ptr %.017, ptr %2, align 8, !tbaa !13
  %13 = call noundef ptr @_ZN3qOS12aligned_castIPNS_3mem14blockConnect_tEPhEET_RT0_(ptr noundef nonnull align 8 dereferenceable(8) %2)
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %13, ptr %14, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 0, ptr %15, align 8, !tbaa !15
  %16 = load ptr, ptr %2, align 8, !tbaa !13
  %17 = ptrtoint ptr %16 to i64
  %18 = add i64 %.0, %17
  %19 = and i64 %18, -8
  %20 = add i64 %19, -16
  %21 = inttoptr i64 %20 to ptr
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %21, ptr %22, align 8, !tbaa !16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %21, i8 0, i64 16, i1 false)
  %23 = call noundef ptr @_ZN3qOS12aligned_castIPNS_3mem14blockConnect_tEPhEET_RT0_(ptr noundef nonnull align 8 dereferenceable(8) %2)
  %24 = ptrtoint ptr %23 to i64
  %25 = sub i64 %20, %24
  %26 = getelementptr inbounds i8, ptr %23, i64 8
  store i64 %25, ptr %26, align 8, !tbaa !17
  %27 = load ptr, ptr %22, align 8, !tbaa !16
  store ptr %27, ptr %23, align 8, !tbaa !18
  %28 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 %25, ptr %28, align 8, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN3qOS12aligned_castIPNS_3mem14blockConnect_tEPhEET_RT0_(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { inlinehint mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !11, i64 40}
!6 = !{!"_ZTSN3qOS3mem4poolE", !7, i64 8, !10, i64 16, !7, i64 32, !11, i64 40, !11, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN3qOS3mem14blockConnect_tE", !7, i64 0, !11, i64 8}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !7, i64 32}
!13 = !{!7, !7, i64 0}
!14 = !{!6, !7, i64 16}
!15 = !{!6, !11, i64 24}
!16 = !{!6, !7, i64 8}
!17 = !{!10, !11, i64 8}
!18 = !{!10, !7, i64 0}
!19 = !{!6, !11, i64 48}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass