; LLVM IR from BitFunnel/NativeJIT :: src/CodeGen/ExecutionBuffer.ll (ZN9NativeJIT15ExecutionBuffer8AllocateEm)

; 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.NativeJIT::ExecutionBuffer" = type { %"class.Allocators::IAllocator", i64, i64, ptr }
%"class.Allocators::IAllocator" = type { ptr }

@.str.1 = external hidden unnamed_addr constant [85 x i8], align 1
@__FUNCTION__._ZN9NativeJIT15ExecutionBuffer8AllocateEm = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN9NativeJIT15ExecutionBuffer8AllocateEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %1) unnamed_addr #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  br label %7

7:                                                ; preds = %2
  %8 = getelementptr inbounds %"class.NativeJIT::ExecutionBuffer", ptr %6, i32 0, i32 2
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %10 = load i64, ptr %4, align 8, !tbaa !9
  %11 = add i64 %9, %10
  %12 = getelementptr inbounds %"class.NativeJIT::ExecutionBuffer", ptr %6, i32 0, i32 1
  %13 = load i64, ptr %12, align 8, !tbaa !14
  %14 = icmp ule i64 %11, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %7
  call void (ptr, ptr, i32, ptr, ptr, ...) @_ZN9NativeJIT12LogThrowImplEPKcS1_jS1_S1_z(ptr noundef @.str.1, ptr noundef @__FUNCTION__._ZN9NativeJIT15ExecutionBuffer8AllocateEm, i32 noundef 142, ptr noundef @.str.2, ptr noundef @.str.3)
  br label %16

16:                                               ; preds = %15, %7
  br label %17

17:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %18 = getelementptr inbounds %"class.NativeJIT::ExecutionBuffer", ptr %6, i32 0, i32 3
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = getelementptr inbounds %"class.NativeJIT::ExecutionBuffer", ptr %6, i32 0, i32 2
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %19, i64 %21
  store ptr %22, ptr %5, align 8, !tbaa !5
  %23 = load i64, ptr %4, align 8, !tbaa !9
  %24 = getelementptr inbounds %"class.NativeJIT::ExecutionBuffer", ptr %6, i32 0, i32 2
  %25 = load i64, ptr %24, align 8, !tbaa !11
  %26 = add i64 %25, %23
  store i64 %26, ptr %24, align 8, !tbaa !11
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret ptr %27
}

declare void @_ZN9NativeJIT12LogThrowImplEPKcS1_jS1_S1_z(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #1

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

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

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 = { "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 willreturn memory(argmem: readwrite) }
attributes #3 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"_ZTSN9NativeJIT15ExecutionBufferE", !13, i64 0, !10, i64 8, !10, i64 16, !6, i64 24}
!13 = !{!"_ZTSN10Allocators10IAllocatorE"}
!14 = !{!12, !10, i64 8}
!15 = !{!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.1 = external hidden unnamed_addr constant [85 x i8], align 1
@__FUNCTION__._ZN9NativeJIT15ExecutionBuffer8AllocateEm = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN9NativeJIT15ExecutionBuffer8AllocateEm(ptr nocapture noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = add i64 %4, %1
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !12
  %.not = icmp ugt i64 %5, %7
  br i1 %.not, label %8, label %9

8:                                                ; preds = %2
  tail call void (ptr, ptr, i32, ptr, ptr, ...) @_ZN9NativeJIT12LogThrowImplEPKcS1_jS1_S1_z(ptr noundef nonnull @.str.1, ptr noundef nonnull @__FUNCTION__._ZN9NativeJIT15ExecutionBuffer8AllocateEm, i32 noundef 142, ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3)
  %.pre = load i64, ptr %3, align 8, !tbaa !5
  %.pre3 = add i64 %.pre, %1
  br label %9

9:                                                ; preds = %2, %8
  %.pre-phi = phi i64 [ %5, %2 ], [ %.pre3, %8 ]
  %10 = phi i64 [ %4, %2 ], [ %.pre, %8 ]
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %12, i64 %10
  store i64 %.pre-phi, ptr %3, align 8, !tbaa !5
  ret ptr %13
}

declare void @_ZN9NativeJIT12LogThrowImplEPKcS1_jS1_S1_z(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #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 = { "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" }

!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, !8, i64 16}
!6 = !{!"_ZTSN9NativeJIT15ExecutionBufferE", !7, i64 0, !8, i64 8, !8, i64 16, !11, i64 24}
!7 = !{!"_ZTSN10Allocators10IAllocatorE"}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!6, !8, i64 8}
!13 = !{!6, !11, i64 24}


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