; LLVM IR from BitFunnel/NativeJIT :: src/CodeGen/CodeBuffer.ll (ZN9NativeJIT10CodeBuffer12ReplaceBytesEjPKhj)

; 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::CodeBuffer" = type { ptr, ptr, i32, ptr, ptr, ptr, %"class.NativeJIT::JumpTable" }
%"class.NativeJIT::JumpTable" = type { %"class.std::vector", %"class.std::vector.0" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<const unsigned char *, std::allocator<const unsigned char *>>::_Vector_impl" }
%"struct.std::_Vector_base<const unsigned char *, std::allocator<const unsigned char *>>::_Vector_impl" = type { %"struct.std::_Vector_base<const unsigned char *, std::allocator<const unsigned char *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<const unsigned char *, std::allocator<const unsigned char *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<NativeJIT::CallSite, std::allocator<NativeJIT::CallSite>>::_Vector_impl" }
%"struct.std::_Vector_base<NativeJIT::CallSite, std::allocator<NativeJIT::CallSite>>::_Vector_impl" = type { %"struct.std::_Vector_base<NativeJIT::CallSite, std::allocator<NativeJIT::CallSite>>::_Vector_impl_data" }
%"struct.std::_Vector_base<NativeJIT::CallSite, std::allocator<NativeJIT::CallSite>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [80 x i8], align 1
@__FUNCTION__._ZN9NativeJIT10CodeBuffer12ReplaceBytesEjPKhj = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [102 x i8], align 1

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

10:                                               ; preds = %4
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = load i32, ptr %8, align 4, !tbaa !9
  %13 = add i32 %11, %12
  %14 = call noundef i32 @_ZNK9NativeJIT10CodeBuffer15CurrentPositionEv(ptr noundef nonnull align 8 dereferenceable(96) %9)
  %15 = icmp ule i32 %13, %14
  br i1 %15, label %22, label %16

16:                                               ; preds = %10
  %17 = call noundef i32 @_ZNK9NativeJIT10CodeBuffer15CurrentPositionEv(ptr noundef nonnull align 8 dereferenceable(96) %9)
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = add i32 %19, %20
  call void (ptr, ptr, i32, ptr, ptr, ...) @_ZN9NativeJIT12LogThrowImplEPKcS1_jS1_S1_z(ptr noundef @.str, ptr noundef @__FUNCTION__._ZN9NativeJIT10CodeBuffer12ReplaceBytesEjPKhj, i32 noundef 103, ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef %17, i32 noundef %18, i32 noundef %21)
  br label %22

22:                                               ; preds = %16, %10
  br label %23

23:                                               ; preds = %22
  %24 = getelementptr inbounds %"class.NativeJIT::CodeBuffer", ptr %9, i32 0, i32 3
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %25, i64 %27
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %28, ptr align 1 %29, i64 %31, i1 false)
  ret void
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, 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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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, !6, i64 24}
!12 = !{!"_ZTSN9NativeJIT10CodeBufferE", !6, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !13, i64 48}
!13 = !{!"_ZTSN9NativeJIT9JumpTableE", !14, i64 0, !18, i64 24}
!14 = !{!"_ZTSSt6vectorIPKhSaIS1_EE", !15, i64 0}
!15 = !{!"_ZTSSt12_Vector_baseIPKhSaIS1_EE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIPKhSaIS1_EE12_Vector_implE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIPKhSaIS1_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!"_ZTSSt6vectorIN9NativeJIT8CallSiteESaIS1_EE", !19, i64 0}
!19 = !{!"_ZTSSt12_Vector_baseIN9NativeJIT8CallSiteESaIS1_EE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIN9NativeJIT8CallSiteESaIS1_EE12_Vector_implE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseIN9NativeJIT8CallSiteESaIS1_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}


; 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 [80 x i8], align 1
@__FUNCTION__._ZN9NativeJIT10CodeBuffer12ReplaceBytesEjPKhj = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [102 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9NativeJIT10CodeBuffer12ReplaceBytesEjPKhj(ptr noundef nonnull align 8 dereferenceable(96) %0, i32 noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3) local_unnamed_addr #0 align 2 {
  %5 = add i32 %3, %1
  %6 = tail call noundef i32 @_ZNK9NativeJIT10CodeBuffer15CurrentPositionEv(ptr noundef nonnull align 8 dereferenceable(96) %0)
  %.not = icmp ugt i32 %5, %6
  br i1 %.not, label %7, label %9

7:                                                ; preds = %4
  %8 = tail call noundef i32 @_ZNK9NativeJIT10CodeBuffer15CurrentPositionEv(ptr noundef nonnull align 8 dereferenceable(96) %0)
  tail call void (ptr, ptr, i32, ptr, ptr, ...) @_ZN9NativeJIT12LogThrowImplEPKcS1_jS1_S1_z(ptr noundef nonnull @.str, ptr noundef nonnull @__FUNCTION__._ZN9NativeJIT10CodeBuffer12ReplaceBytesEjPKhj, i32 noundef 103, ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef %8, i32 noundef %1, i32 noundef %5)
  br label %9

9:                                                ; preds = %4, %7
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = zext i32 %1 to i64
  %13 = getelementptr inbounds i8, ptr %11, i64 %12
  %14 = zext i32 %3 to i64
  tail call void @llvm.memmove.p0.p0.i64(ptr align 1 %13, ptr align 1 %2, i64 %14, i1 false)
  ret void
}

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, 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 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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 24}
!6 = !{!"_ZTSN9NativeJIT10CodeBufferE", !7, i64 8, !10, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !11, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTSN9NativeJIT9JumpTableE", !12, i64 0, !16, i64 24}
!12 = !{!"_ZTSSt6vectorIPKhSaIS1_EE", !13, i64 0}
!13 = !{!"_ZTSSt12_Vector_baseIPKhSaIS1_EE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIPKhSaIS1_EE12_Vector_implE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIPKhSaIS1_EE17_Vector_impl_dataE", !7, i64 0, !7, i64 8, !7, i64 16}
!16 = !{!"_ZTSSt6vectorIN9NativeJIT8CallSiteESaIS1_EE", !17, i64 0}
!17 = !{!"_ZTSSt12_Vector_baseIN9NativeJIT8CallSiteESaIS1_EE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIN9NativeJIT8CallSiteESaIS1_EE12_Vector_implE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseIN9NativeJIT8CallSiteESaIS1_EE17_Vector_impl_dataE", !7, i64 0, !7, i64 8, !7, i64 16}


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