; LLVM IR from FlorentCLMichel/palisade :: src/core/lib/utils/blockAllocator/blockAllocator.ll (ZN9AllocatorC2EmjPcPKc)

; 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.Allocator = type { i64, i64, i32, i32, ptr, ptr, i32, i32, i32, i32, i32, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9AllocatorC2EmjPcPKc(ptr noundef nonnull align 8 dereferenceable(72) %0, i64 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) unnamed_addr #0 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !11
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8
  %12 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 0
  %13 = load i64, ptr %7, align 8, !tbaa !9
  %14 = icmp ult i64 %13, 8
  br i1 %14, label %15, label %16

15:                                               ; preds = %5
  br label %18

16:                                               ; preds = %5
  %17 = load i64, ptr %7, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %16, %15
  %19 = phi i64 [ 8, %15 ], [ %17, %16 ]
  store i64 %19, ptr %12, align 8, !tbaa !13
  %20 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 1
  %21 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %21, ptr %20, align 8, !tbaa !16
  %22 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 2
  %23 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %23, ptr %22, align 8, !tbaa !17
  %24 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 4
  store ptr null, ptr %24, align 8, !tbaa !18
  %25 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 6
  store i32 0, ptr %25, align 8, !tbaa !19
  %26 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 7
  store i32 0, ptr %26, align 4, !tbaa !20
  %27 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 8
  store i32 0, ptr %27, align 8, !tbaa !21
  %28 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 9
  store i32 0, ptr %28, align 4, !tbaa !22
  %29 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 10
  store i32 0, ptr %29, align 8, !tbaa !23
  %30 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 11
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %31, ptr %30, align 8, !tbaa !24
  %32 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 2
  %33 = load i32, ptr %32, align 8, !tbaa !17
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %53

35:                                               ; preds = %18
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %42

38:                                               ; preds = %35
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 5
  store ptr %39, ptr %40, align 8, !tbaa !25
  %41 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 3
  store i32 2, ptr %41, align 4, !tbaa !26
  br label %52

42:                                               ; preds = %35
  %43 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 0
  %44 = load i64, ptr %43, align 8, !tbaa !13
  %45 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 2
  %46 = load i32, ptr %45, align 8, !tbaa !17
  %47 = zext i32 %46 to i64
  %48 = mul i64 %44, %47
  %49 = call noalias noundef nonnull ptr @_Znam(i64 noundef %48) #2
  %50 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 5
  store ptr %49, ptr %50, align 8, !tbaa !25
  %51 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 3
  store i32 1, ptr %51, align 4, !tbaa !26
  br label %52

52:                                               ; preds = %42, %38
  br label %55

53:                                               ; preds = %18
  %54 = getelementptr inbounds %class.Allocator, ptr %11, i32 0, i32 3
  store i32 0, ptr %54, align 4, !tbaa !26
  br label %55

55:                                               ; preds = %53, %52
  ret void
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #1

attributes #0 = { mustprogress 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 = { nobuiltin allocsize(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 = { builtin allocsize(0) }

!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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTS9Allocator", !10, i64 0, !10, i64 8, !12, i64 16, !15, i64 20, !6, i64 24, !6, i64 32, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !12, i64 56, !6, i64 64}
!15 = !{!"_ZTSN9Allocator13AllocatorModeE", !7, i64 0}
!16 = !{!14, !10, i64 8}
!17 = !{!14, !12, i64 16}
!18 = !{!14, !6, i64 24}
!19 = !{!14, !12, i64 40}
!20 = !{!14, !12, i64 44}
!21 = !{!14, !12, i64 48}
!22 = !{!14, !12, i64 52}
!23 = !{!14, !12, i64 56}
!24 = !{!14, !6, i64 64}
!25 = !{!14, !6, i64 32}
!26 = !{!14, !15, i64 20}


; 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 uwtable
define dso_local void @_ZN9AllocatorC2EmjPcPKc(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(72) %0, i64 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) unnamed_addr #0 align 2 {
  %6 = tail call i64 @llvm.umax.i64(i64 %1, i64 8)
  store i64 %6, ptr %0, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %1, ptr %7, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %2, ptr %8, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr null, ptr %9, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(20) %10, i8 0, i64 20, i1 false)
  store ptr %4, ptr %11, align 8, !tbaa !16
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %18, label %12

12:                                               ; preds = %5
  %.not8 = icmp eq ptr %3, null
  br i1 %.not8, label %13, label %.sink.split

13:                                               ; preds = %12
  %14 = zext i32 %2 to i64
  %15 = mul i64 %6, %14
  %16 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %15) #4
  br label %.sink.split

.sink.split:                                      ; preds = %12, %13
  %.sink10 = phi ptr [ %16, %13 ], [ %3, %12 ]
  %.sink.ph = phi i32 [ 1, %13 ], [ 2, %12 ]
  %17 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %.sink10, ptr %17, align 8, !tbaa !17
  br label %18

18:                                               ; preds = %.sink.split, %5
  %.sink = phi i32 [ 0, %5 ], [ %.sink.ph, %.sink.split ]
  %19 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %.sink, ptr %19, align 4, !tbaa !18
  ret void
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #2

; 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 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 = { nobuiltin allocsize(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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { builtin allocsize(0) }

!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, !7, i64 0}
!6 = !{!"_ZTS9Allocator", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 20, !12, i64 24, !12, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !12, i64 64}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTSN9Allocator13AllocatorModeE", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !10, i64 16}
!15 = !{!6, !12, i64 24}
!16 = !{!6, !12, i64 64}
!17 = !{!6, !12, i64 32}
!18 = !{!6, !11, i64 20}


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