; LLVM IR from mentebinaria/maProc :: src/include/memory/arena.ll (ZN5Arena3reqEj)

; 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.Arena = type <{ ptr, i32, i32, i32, [4 x i8], ptr, i8, [7 x i8] }>

@.str = external hidden unnamed_addr constant [22 x i8], align 1
@_ZTISt13runtime_error = external constant ptr

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

13:                                               ; preds = %2
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = getelementptr inbounds %struct.Arena, ptr %8, i32 0, i32 3
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = icmp ult i32 %14, %16
  br i1 %17, label %18, label %31

18:                                               ; preds = %13
  %19 = getelementptr inbounds %struct.Arena, ptr %8, i32 0, i32 6
  %20 = load i8, ptr %19, align 8, !tbaa !15, !range !16, !noundef !17
  %21 = trunc i8 %20 to i1
  br i1 %21, label %22, label %31

22:                                               ; preds = %18
  %23 = getelementptr inbounds %struct.Arena, ptr %8, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !18
  %25 = getelementptr inbounds %struct.Arena, ptr %8, i32 0, i32 3
  %26 = load i32, ptr %25, align 8, !tbaa !14
  %27 = icmp ugt i32 %24, %26
  br i1 %27, label %28, label %31

28:                                               ; preds = %22
  %29 = getelementptr inbounds %struct.Arena, ptr %8, i32 0, i32 3
  %30 = load i32, ptr %29, align 8, !tbaa !14
  call void @_ZN5Arena7reallocEj(ptr noundef nonnull align 8 dereferenceable(33) %8, i32 noundef %30)
  br label %51

31:                                               ; preds = %22, %18, %13
  br label %51

32:                                               ; preds = %2
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = getelementptr inbounds %struct.Arena, ptr %8, i32 0, i32 1
  %35 = load i32, ptr %34, align 8, !tbaa !18
  %36 = icmp ugt i32 %33, %35
  br i1 %36, label %37, label %39

37:                                               ; preds = %32
  %38 = load i32, ptr %4, align 4, !tbaa !9
  call void @_ZN5Arena7reallocEj(ptr noundef nonnull align 8 dereferenceable(33) %8, i32 noundef %38)
  br label %51

39:                                               ; preds = %32
  %40 = getelementptr inbounds %struct.Arena, ptr %8, i32 0, i32 6
  %41 = load i8, ptr %40, align 8, !tbaa !15, !range !16, !noundef !17
  %42 = trunc i8 %41 to i1
  br i1 %42, label %43, label %44

43:                                               ; preds = %39
  call void @_ZN5Arena4dellEv(ptr noundef nonnull align 8 dereferenceable(33) %8)
  br label %51

44:                                               ; preds = %39
  %45 = call ptr @__cxa_allocate_exception(i64 16) #5
  invoke void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16) %45, ptr noundef @.str)
          to label %46 unwind label %47

46:                                               ; preds = %44
  call void @__cxa_throw(ptr %45, ptr @_ZTISt13runtime_error, ptr @_ZNSt13runtime_errorD1Ev) #6
  unreachable

47:                                               ; preds = %44
  %48 = landingpad { ptr, i32 }
          cleanup
  %49 = extractvalue { ptr, i32 } %48, 0
  store ptr %49, ptr %5, align 8
  %50 = extractvalue { ptr, i32 } %48, 1
  store i32 %50, ptr %6, align 4
  call void @__cxa_free_exception(ptr %45) #5
  br label %64

51:                                               ; preds = %43, %37, %31, %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %52 = getelementptr inbounds %struct.Arena, ptr %8, i32 0, i32 5
  %53 = load ptr, ptr %52, align 8, !tbaa !19
  store ptr %53, ptr %7, align 8, !tbaa !5
  %54 = load i32, ptr %4, align 4, !tbaa !9
  %55 = getelementptr inbounds %struct.Arena, ptr %8, i32 0, i32 5
  %56 = load ptr, ptr %55, align 8, !tbaa !19
  %57 = zext i32 %54 to i64
  %58 = getelementptr inbounds i8, ptr %56, i64 %57
  store ptr %58, ptr %55, align 8, !tbaa !19
  %59 = load i32, ptr %4, align 4, !tbaa !9
  %60 = getelementptr inbounds %struct.Arena, ptr %8, i32 0, i32 2
  %61 = load i32, ptr %60, align 4, !tbaa !11
  %62 = sub i32 %61, %59
  store i32 %62, ptr %60, align 4, !tbaa !11
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret ptr %63

64:                                               ; preds = %47
  %65 = load ptr, ptr %5, align 8
  %66 = load i32, ptr %6, align 4
  %67 = insertvalue { ptr, i32 } poison, ptr %65, 0
  %68 = insertvalue { ptr, i32 } %67, i32 %66, 1
  resume { ptr, i32 } %68
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Arena7reallocEj(ptr noundef nonnull align 8 dereferenceable(33), i32 noundef) #0 align 2

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

declare ptr @__cxa_allocate_exception(i64)

declare void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

declare void @__cxa_free_exception(ptr)

; Function Attrs: nounwind
declare void @_ZNSt13runtime_errorD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #3

declare void @__cxa_throw(ptr, ptr, ptr)

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

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

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 = { 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 = { "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 = { 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 }
attributes #6 = { noreturn }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 12}
!12 = !{!"_ZTS5Arena", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !6, i64 24, !13, i64 32}
!13 = !{!"bool", !7, i64 0}
!14 = !{!12, !10, i64 16}
!15 = !{!12, !13, i64 32}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!12, !10, i64 8}
!19 = !{!12, !6, i64 24}


; 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 [22 x i8], align 1
@_ZTISt13runtime_error = external constant ptr

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

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i32, ptr %6, align 8, !tbaa !12
  %8 = icmp ugt i32 %7, %1
  br i1 %8, label %9, label %32

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = load i8, ptr %10, align 8, !tbaa !13, !range !14, !noundef !15
  %12 = trunc nuw i8 %11 to i1
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load i32, ptr %13, align 8
  %15 = icmp ugt i32 %14, %7
  %or.cond = select i1 %12, i1 %15, i1 false
  br i1 %or.cond, label %16, label %32

16:                                               ; preds = %9
  tail call void @_ZN5Arena7reallocEj(ptr noundef nonnull align 8 dereferenceable(33) %0, i32 noundef %7)
  br label %32

17:                                               ; preds = %2
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %19 = load i32, ptr %18, align 8, !tbaa !16
  %20 = icmp ult i32 %19, %1
  br i1 %20, label %21, label %22

21:                                               ; preds = %17
  tail call void @_ZN5Arena7reallocEj(ptr noundef nonnull align 8 dereferenceable(33) %0, i32 noundef %1)
  br label %32

22:                                               ; preds = %17
  %23 = getelementptr inbounds i8, ptr %0, i64 32
  %24 = load i8, ptr %23, align 8, !tbaa !13, !range !14, !noundef !15
  %25 = trunc nuw i8 %24 to i1
  br i1 %25, label %26, label %27

26:                                               ; preds = %22
  tail call void @_ZN5Arena4dellEv(ptr noundef nonnull align 8 dereferenceable(33) %0)
  br label %32

27:                                               ; preds = %22
  %28 = tail call ptr @__cxa_allocate_exception(i64 16) #4
  invoke void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16) %28, ptr noundef nonnull @.str)
          to label %29 unwind label %30

29:                                               ; preds = %27
  tail call void @__cxa_throw(ptr nonnull %28, ptr nonnull @_ZTISt13runtime_error, ptr nonnull @_ZNSt13runtime_errorD1Ev) #5
  unreachable

30:                                               ; preds = %27
  %31 = landingpad { ptr, i32 }
          cleanup
  tail call void @__cxa_free_exception(ptr %28) #4
  resume { ptr, i32 } %31

32:                                               ; preds = %5, %9, %26, %21, %16
  %33 = getelementptr inbounds i8, ptr %0, i64 24
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  %35 = zext i32 %1 to i64
  %36 = getelementptr inbounds i8, ptr %34, i64 %35
  store ptr %36, ptr %33, align 8, !tbaa !17
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sub i32 %37, %1
  store i32 %38, ptr %3, align 4, !tbaa !5
  ret ptr %34
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Arena7reallocEj(ptr noundef nonnull align 8 dereferenceable(33), i32 noundef) local_unnamed_addr #0 align 2

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

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

declare void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

declare void @__cxa_free_exception(ptr) local_unnamed_addr

; Function Attrs: nounwind
declare void @_ZNSt13runtime_errorD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #3

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

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 = { 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 = { "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 = { 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 }
attributes #5 = { noreturn }

!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 12}
!6 = !{!"_ZTS5Arena", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !7, i64 24, !11, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!6, !10, i64 16}
!13 = !{!6, !11, i64 32}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!6, !10, i64 8}
!17 = !{!6, !7, i64 24}


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