; LLVM IR from masyagin1998/GCI :: src/garbage-collector (allocator)

; 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.ALLOCATOR = type { ptr, i64, %struct.ALLOCATOR_LIST, %struct.ALLOCATOR_LIST }
%struct.ALLOCATOR_LIST = type { ptr, ptr, i64, i64 }

; Function Attrs: nounwind uwtable
define dso_local void @allocator_clean_pool(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.ALLOCATOR, ptr %4, i32 0, i32 1
  %6 = load i64, ptr %5, align 8, !tbaa !9
  %7 = sub i64 %6, 34
  store i64 %7, ptr %3, align 8, !tbaa !13
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.ALLOCATOR, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  store i8 0, ptr %10, align 1, !tbaa !15
  %11 = load i64, ptr %3, align 8, !tbaa !13
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ALLOCATOR, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %14, i64 1
  store i64 %11, ptr %15, align 8, !tbaa !13
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ALLOCATOR, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %18, i64 1
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  store ptr null, ptr %20, align 8, !tbaa !5
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ALLOCATOR, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = getelementptr inbounds i8, ptr %23, i64 1
  %25 = getelementptr inbounds i8, ptr %24, i64 8
  %26 = getelementptr inbounds i8, ptr %25, i64 8
  store ptr null, ptr %26, align 8, !tbaa !5
  %27 = load i64, ptr %3, align 8, !tbaa !13
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ALLOCATOR, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = getelementptr inbounds i8, ptr %30, i64 1
  %32 = getelementptr inbounds i8, ptr %31, i64 8
  %33 = getelementptr inbounds i8, ptr %32, i64 8
  %34 = getelementptr inbounds i8, ptr %33, i64 8
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ALLOCATOR, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = getelementptr inbounds i8, ptr %37, i64 1
  %39 = load i64, ptr %38, align 8, !tbaa !13
  %40 = mul i64 %39, 1
  %41 = getelementptr inbounds i8, ptr %34, i64 %40
  store i64 %27, ptr %41, align 8, !tbaa !13
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.ALLOCATOR, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !14
  %45 = getelementptr inbounds i8, ptr %44, i64 1
  %46 = getelementptr inbounds i8, ptr %45, i64 8
  %47 = getelementptr inbounds i8, ptr %46, i64 8
  %48 = getelementptr inbounds i8, ptr %47, i64 8
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ALLOCATOR, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !14
  %52 = getelementptr inbounds i8, ptr %51, i64 1
  %53 = load i64, ptr %52, align 8, !tbaa !13
  %54 = mul i64 %53, 1
  %55 = getelementptr inbounds i8, ptr %48, i64 %54
  %56 = getelementptr inbounds i8, ptr %55, i64 8
  store i8 0, ptr %56, align 1, !tbaa !15
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ALLOCATOR, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !14
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ALLOCATOR, ptr %60, i32 0, i32 2
  %62 = getelementptr inbounds %struct.ALLOCATOR_LIST, ptr %61, i32 0, i32 0
  store ptr %59, ptr %62, align 8, !tbaa !16
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ALLOCATOR, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !14
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.ALLOCATOR, ptr %66, i32 0, i32 2
  %68 = getelementptr inbounds %struct.ALLOCATOR_LIST, ptr %67, i32 0, i32 1
  store ptr %65, ptr %68, align 8, !tbaa !17
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.ALLOCATOR, ptr %69, i32 0, i32 2
  %71 = getelementptr inbounds %struct.ALLOCATOR_LIST, ptr %70, i32 0, i32 2
  store i64 1, ptr %71, align 8, !tbaa !18
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.ALLOCATOR, ptr %72, i32 0, i32 1
  %74 = load i64, ptr %73, align 8, !tbaa !9
  %75 = sub i64 %74, 34
  %76 = load ptr, ptr %2, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.ALLOCATOR, ptr %76, i32 0, i32 2
  %78 = getelementptr inbounds %struct.ALLOCATOR_LIST, ptr %77, i32 0, i32 3
  store i64 %75, ptr %78, align 8, !tbaa !19
  %79 = load ptr, ptr %2, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.ALLOCATOR, ptr %79, i32 0, i32 3
  %81 = getelementptr inbounds %struct.ALLOCATOR_LIST, ptr %80, i32 0, i32 0
  store ptr null, ptr %81, align 8, !tbaa !20
  %82 = load ptr, ptr %2, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.ALLOCATOR, ptr %82, i32 0, i32 3
  %84 = getelementptr inbounds %struct.ALLOCATOR_LIST, ptr %83, i32 0, i32 1
  store ptr null, ptr %84, align 8, !tbaa !21
  %85 = load ptr, ptr %2, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.ALLOCATOR, ptr %85, i32 0, i32 3
  %87 = getelementptr inbounds %struct.ALLOCATOR_LIST, ptr %86, i32 0, i32 2
  store i64 0, ptr %87, align 8, !tbaa !22
  %88 = load ptr, ptr %2, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.ALLOCATOR, ptr %88, i32 0, i32 3
  %90 = getelementptr inbounds %struct.ALLOCATOR_LIST, ptr %89, i32 0, i32 3
  store i64 0, ptr %90, align 8, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"ALLOCATOR", !6, i64 0, !11, i64 8, !12, i64 16, !12, i64 48}
!11 = !{!"long", !7, i64 0}
!12 = !{!"ALLOCATOR_LIST", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 24}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!10, !6, i64 16}
!17 = !{!10, !6, i64 24}
!18 = !{!10, !11, i64 32}
!19 = !{!10, !11, i64 40}
!20 = !{!10, !6, i64 48}
!21 = !{!10, !6, i64 56}
!22 = !{!10, !11, i64 64}
!23 = !{!10, !11, i64 72}


; 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 nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @allocator_clean_pool(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = add i64 %3, -34
  %5 = load ptr, ptr %0, align 8, !tbaa !12
  store i8 0, ptr %5, align 1, !tbaa !13
  %6 = load ptr, ptr %0, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %6, i64 1
  store i64 %4, ptr %7, align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %6, i64 9
  store ptr null, ptr %8, align 8, !tbaa !15
  %9 = load ptr, ptr %0, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %9, i64 17
  store ptr null, ptr %10, align 8, !tbaa !15
  %11 = load ptr, ptr %0, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %11, i64 1
  %13 = getelementptr inbounds i8, ptr %11, i64 25
  %14 = load i64, ptr %12, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %13, i64 %14
  store i64 %4, ptr %15, align 8, !tbaa !14
  %16 = load i64, ptr %12, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %13, i64 %16
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  store i8 0, ptr %18, align 1, !tbaa !13
  %19 = load ptr, ptr %0, align 8, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %19, ptr %20, align 8, !tbaa !16
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %19, ptr %21, align 8, !tbaa !17
  %22 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 1, ptr %22, align 8, !tbaa !18
  %23 = load i64, ptr %2, align 8, !tbaa !5
  %24 = add i64 %23, -34
  %25 = getelementptr inbounds i8, ptr %0, i64 40
  store i64 %24, ptr %25, align 8, !tbaa !19
  %26 = getelementptr inbounds i8, ptr %0, i64 48
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %26, i8 0, i64 32, i1 false)
  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(readwrite, 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, !10, i64 8}
!6 = !{!"ALLOCATOR", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"ALLOCATOR_LIST", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24}
!12 = !{!6, !7, i64 0}
!13 = !{!8, !8, i64 0}
!14 = !{!10, !10, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!6, !7, i64 16}
!17 = !{!6, !7, i64 24}
!18 = !{!6, !10, i64 32}
!19 = !{!6, !10, i64 40}


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