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

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

@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [111 x i8], align 1
@__PRETTY_FUNCTION__._ZN9Allocator8AllocateEm = external hidden unnamed_addr constant [34 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

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

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

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

12:                                               ; preds = %2
  br label %15

13:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 58, ptr noundef @__PRETTY_FUNCTION__._ZN9Allocator8AllocateEm) #6
  unreachable

14:                                               ; No predecessors!
  br label %15

15:                                               ; preds = %14, %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  %16 = call noundef ptr @_ZN9Allocator3PopEv(ptr noundef nonnull align 8 dereferenceable(72) %7)
  store ptr %16, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %59, label %19

19:                                               ; preds = %15
  %20 = getelementptr inbounds %class.Allocator, ptr %7, i32 0, i32 2
  %21 = load i32, ptr %20, align 8, !tbaa !15
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %51

23:                                               ; preds = %19
  %24 = getelementptr inbounds %class.Allocator, ptr %7, i32 0, i32 6
  %25 = load i32, ptr %24, align 8, !tbaa !16
  %26 = getelementptr inbounds %class.Allocator, ptr %7, i32 0, i32 2
  %27 = load i32, ptr %26, align 8, !tbaa !15
  %28 = icmp ult i32 %25, %27
  br i1 %28, label %29, label %40

29:                                               ; preds = %23
  %30 = getelementptr inbounds %class.Allocator, ptr %7, i32 0, i32 5
  %31 = load ptr, ptr %30, align 8, !tbaa !17
  %32 = getelementptr inbounds %class.Allocator, ptr %7, i32 0, i32 6
  %33 = load i32, ptr %32, align 8, !tbaa !16
  %34 = add i32 %33, 1
  store i32 %34, ptr %32, align 8, !tbaa !16
  %35 = zext i32 %33 to i64
  %36 = getelementptr inbounds %class.Allocator, ptr %7, i32 0, i32 0
  %37 = load i64, ptr %36, align 8, !tbaa !18
  %38 = mul i64 %35, %37
  %39 = getelementptr inbounds i8, ptr %31, i64 %38
  store ptr %39, ptr %5, align 8, !tbaa !5
  br label %50

40:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  %41 = call noundef ptr @_ZSt15set_new_handlerPFvvE(ptr noundef null) #7
  store ptr %41, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = call noundef ptr @_ZSt15set_new_handlerPFvvE(ptr noundef %42) #7
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %48

46:                                               ; preds = %40
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  call void %47()
  br label %49

48:                                               ; preds = %40
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 79, ptr noundef @__PRETTY_FUNCTION__._ZN9Allocator8AllocateEm) #6
  unreachable

49:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  br label %50

50:                                               ; preds = %49, %29
  br label %58

51:                                               ; preds = %19
  %52 = getelementptr inbounds %class.Allocator, ptr %7, i32 0, i32 7
  %53 = load i32, ptr %52, align 4, !tbaa !19
  %54 = add i32 %53, 1
  store i32 %54, ptr %52, align 4, !tbaa !19
  %55 = getelementptr inbounds %class.Allocator, ptr %7, i32 0, i32 0
  %56 = load i64, ptr %55, align 8, !tbaa !18
  %57 = call noalias noundef nonnull ptr @_Znam(i64 noundef %56) #8
  store ptr %57, ptr %5, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %51, %50
  br label %59

59:                                               ; preds = %58, %15
  %60 = getelementptr inbounds %class.Allocator, ptr %7, i32 0, i32 8
  %61 = load i32, ptr %60, align 8, !tbaa !20
  %62 = add i32 %61, 1
  store i32 %62, ptr %60, align 8, !tbaa !20
  %63 = getelementptr inbounds %class.Allocator, ptr %7, i32 0, i32 9
  %64 = load i32, ptr %63, align 4, !tbaa !21
  %65 = add i32 %64, 1
  store i32 %65, ptr %63, align 4, !tbaa !21
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  ret ptr %66
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

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

; Function Attrs: nounwind
declare noundef ptr @_ZSt15set_new_handlerPFvvE(ptr noundef) #5

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

attributes #0 = { 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 #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 = { 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 #3 = { noreturn nounwind "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind "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 #6 = { noreturn nounwind }
attributes #7 = { nounwind }
attributes #8 = { 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, !10, i64 8}
!12 = !{!"_ZTS9Allocator", !10, i64 0, !10, i64 8, !13, i64 16, !14, i64 20, !6, i64 24, !6, i64 32, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52, !13, i64 56, !6, i64 64}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTSN9Allocator13AllocatorModeE", !7, i64 0}
!15 = !{!12, !13, i64 16}
!16 = !{!12, !13, i64 40}
!17 = !{!12, !6, i64 32}
!18 = !{!12, !10, i64 0}
!19 = !{!12, !13, i64 44}
!20 = !{!12, !13, i64 48}
!21 = !{!12, !13, i64 52}


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

@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [111 x i8], align 1
@__PRETTY_FUNCTION__._ZN9Allocator8AllocateEm = external hidden unnamed_addr constant [34 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN9Allocator8AllocateEm(ptr noundef nonnull align 8 dereferenceable(72) %0, i64 noundef %1) local_unnamed_addr #2 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp ult i64 %4, %1
  br i1 %.not, label %5, label %6

5:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 58, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN9Allocator8AllocateEm) #5
  unreachable

6:                                                ; preds = %2
  %7 = tail call noundef ptr @_ZN9Allocator3PopEv(ptr noundef nonnull align 8 dereferenceable(72) %0)
  %.not10 = icmp eq ptr %7, null
  br i1 %.not10, label %8, label %34

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load i32, ptr %9, align 8, !tbaa !13
  %.not11 = icmp eq i32 %10, 0
  br i1 %.not11, label %28, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 40
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %14 = icmp ult i32 %13, %10
  br i1 %14, label %15, label %23

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %0, i64 32
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = add nuw i32 %13, 1
  store i32 %18, ptr %12, align 8, !tbaa !14
  %19 = zext i32 %13 to i64
  %20 = load i64, ptr %0, align 8, !tbaa !16
  %21 = mul i64 %20, %19
  %22 = getelementptr inbounds i8, ptr %17, i64 %21
  br label %34

23:                                               ; preds = %11
  %24 = tail call noundef ptr @_ZSt15set_new_handlerPFvvE(ptr noundef null) #6
  %25 = tail call noundef ptr @_ZSt15set_new_handlerPFvvE(ptr noundef %24) #6
  %.not12 = icmp eq ptr %24, null
  br i1 %.not12, label %27, label %26

26:                                               ; preds = %23
  tail call void %24()
  br label %34

27:                                               ; preds = %23
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 79, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN9Allocator8AllocateEm) #5
  unreachable

28:                                               ; preds = %8
  %29 = getelementptr inbounds i8, ptr %0, i64 44
  %30 = load i32, ptr %29, align 4, !tbaa !17
  %31 = add i32 %30, 1
  store i32 %31, ptr %29, align 4, !tbaa !17
  %32 = load i64, ptr %0, align 8, !tbaa !16
  %33 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %32) #7
  br label %34

34:                                               ; preds = %28, %26, %15, %6
  %.0 = phi ptr [ %7, %6 ], [ %22, %15 ], [ null, %26 ], [ %33, %28 ]
  %35 = getelementptr inbounds i8, ptr %0, i64 48
  %36 = load <2 x i32>, ptr %35, align 8, !tbaa !18
  %37 = add <2 x i32> %36, <i32 1, i32 1>
  store <2 x i32> %37, ptr %35, align 8, !tbaa !18
  ret ptr %.0
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare noundef ptr @_ZSt15set_new_handlerPFvvE(ptr noundef) local_unnamed_addr #4

attributes #0 = { 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 #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 = { 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 #3 = { noreturn nounwind "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 "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 #5 = { noreturn nounwind }
attributes #6 = { nounwind }
attributes #7 = { 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 8}
!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, !10, i64 16}
!14 = !{!6, !10, i64 40}
!15 = !{!6, !12, i64 32}
!16 = !{!6, !7, i64 0}
!17 = !{!6, !10, i64 44}
!18 = !{!10, !10, i64 0}


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