; LLVM IR from tevador/RandomX :: src (jit_compiler_x86)

; 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.randomx::ProgramConfiguration" = type { [2 x i64], i32, i32, i32, i32 }
%"class.randomx::JitCompilerX86" = type <{ %"class.std::vector", [8 x i32], ptr, i32, [4 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@_ZN7randomxL12REX_MOV_RR64E = external hidden constant [2 x i8], align 1
@_ZN7randomx13codeLoopStoreE = external dso_local global ptr, align 8
@_ZN7randomxL12prologueSizeE = external hidden global i32, align 4
@_ZN7randomxL14epilogueOffsetE = external hidden global i32, align 4
@_ZN7randomxL15REX_XOR_RAX_R64E = external hidden constant [2 x i8], align 1
@_ZN7randomxL13loopStoreSizeE = external hidden global i32, align 4
@_ZN7randomxL7SUB_EBXE = external hidden constant [3 x i8], align 1
@_ZN7randomxL3JNZE = external hidden constant [2 x i8], align 1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7randomx14JitCompilerX864emitEPKhm(ptr noundef nonnull align 8 dereferenceable(68), ptr noundef, i64 noundef) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7randomx14JitCompilerX868emitByteEh(ptr noundef nonnull align 8 dereferenceable(68), i8 noundef zeroext) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7randomx14JitCompilerX8623generateProgramEpilogueERNS_7ProgramERNS_20ProgramConfigurationE(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr noundef nonnull align 8 dereferenceable(2176) %1, ptr noundef nonnull align 8 dereferenceable(32) %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8
  call void @_ZN7randomx14JitCompilerX864emitILm2EEEvRAT__Kh(ptr noundef nonnull align 8 dereferenceable(68) %7, ptr noundef nonnull align 1 dereferenceable(2) @_ZN7randomxL12REX_MOV_RR64E)
  %8 = load ptr, ptr %6, align 8, !tbaa !5
  %9 = getelementptr inbounds %"struct.randomx::ProgramConfiguration", ptr %8, i32 0, i32 1
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = add i32 192, %10
  %12 = trunc i32 %11 to i8
  call void @_ZN7randomx14JitCompilerX868emitByteEh(ptr noundef nonnull align 8 dereferenceable(68) %7, i8 noundef zeroext %12)
  call void @_ZN7randomx14JitCompilerX864emitILm2EEEvRAT__Kh(ptr noundef nonnull align 8 dereferenceable(68) %7, ptr noundef nonnull align 1 dereferenceable(2) @_ZN7randomxL15REX_XOR_RAX_R64E)
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %"struct.randomx::ProgramConfiguration", ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = add i32 192, %15
  %17 = trunc i32 %16 to i8
  call void @_ZN7randomx14JitCompilerX868emitByteEh(ptr noundef nonnull align 8 dereferenceable(68) %7, i8 noundef zeroext %17)
  call void @_ZN7randomx14JitCompilerX864emitEPKhm(ptr noundef nonnull align 8 dereferenceable(68) %7, ptr noundef @randomx_prefetch_scratchpad, i64 noundef sub (i64 ptrtoint (ptr @randomx_prefetch_scratchpad_end to i64), i64 ptrtoint (ptr @randomx_prefetch_scratchpad to i64)))
  %18 = getelementptr inbounds %"class.randomx::JitCompilerX86", ptr %7, i32 0, i32 2
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = getelementptr inbounds %"class.randomx::JitCompilerX86", ptr %7, i32 0, i32 3
  %21 = load i32, ptr %20, align 8, !tbaa !19
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i8, ptr %19, i64 %22
  %24 = load ptr, ptr @_ZN7randomx13codeLoopStoreE, align 8, !tbaa !5
  %25 = load i32, ptr @_ZN7randomxL13loopStoreSizeE, align 4, !tbaa !20
  %26 = sext i32 %25 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %23, ptr align 1 %24, i64 %26, i1 false)
  %27 = load i32, ptr @_ZN7randomxL13loopStoreSizeE, align 4, !tbaa !20
  %28 = getelementptr inbounds %"class.randomx::JitCompilerX86", ptr %7, i32 0, i32 3
  %29 = load i32, ptr %28, align 8, !tbaa !19
  %30 = add nsw i32 %29, %27
  store i32 %30, ptr %28, align 8, !tbaa !19
  call void @_ZN7randomx14JitCompilerX864emitILm3EEEvRAT__Kh(ptr noundef nonnull align 8 dereferenceable(68) %7, ptr noundef nonnull align 1 dereferenceable(3) @_ZN7randomxL7SUB_EBXE)
  call void @_ZN7randomx14JitCompilerX864emitILm2EEEvRAT__Kh(ptr noundef nonnull align 8 dereferenceable(68) %7, ptr noundef nonnull align 1 dereferenceable(2) @_ZN7randomxL3JNZE)
  %31 = load i32, ptr @_ZN7randomxL12prologueSizeE, align 4, !tbaa !20
  %32 = getelementptr inbounds %"class.randomx::JitCompilerX86", ptr %7, i32 0, i32 3
  %33 = load i32, ptr %32, align 8, !tbaa !19
  %34 = sub nsw i32 %31, %33
  %35 = sub nsw i32 %34, 4
  call void @_ZN7randomx14JitCompilerX866emit32Ej(ptr noundef nonnull align 8 dereferenceable(68) %7, i32 noundef %35)
  call void @_ZN7randomx14JitCompilerX868emitByteEh(ptr noundef nonnull align 8 dereferenceable(68) %7, i8 noundef zeroext -23)
  %36 = load i32, ptr @_ZN7randomxL14epilogueOffsetE, align 4, !tbaa !20
  %37 = getelementptr inbounds %"class.randomx::JitCompilerX86", ptr %7, i32 0, i32 3
  %38 = load i32, ptr %37, align 8, !tbaa !19
  %39 = sub nsw i32 %36, %38
  %40 = sub nsw i32 %39, 4
  call void @_ZN7randomx14JitCompilerX866emit32Ej(ptr noundef nonnull align 8 dereferenceable(68) %7, i32 noundef %40)
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7randomx14JitCompilerX866emit32Ej(ptr noundef nonnull align 8 dereferenceable(68), i32 noundef) #1 align 2

declare void @randomx_prefetch_scratchpad() #3

declare void @randomx_prefetch_scratchpad_end() #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7randomx14JitCompilerX864emitILm3EEEvRAT__Kh(ptr noundef nonnull align 8 dereferenceable(68), ptr noundef nonnull align 1 dereferenceable(3)) #1 align 2

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 16}
!10 = !{!"_ZTSN7randomx20ProgramConfigurationE", !7, i64 0, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 20}
!13 = !{!14, !6, i64 56}
!14 = !{!"_ZTSN7randomx14JitCompilerX86E", !15, i64 0, !7, i64 24, !6, i64 56, !11, i64 64}
!15 = !{!"_ZTSSt6vectorIiSaIiEE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!14, !11, i64 64}
!20 = !{!11, !11, i64 0}


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

@_ZN7randomxL12REX_MOV_RR64E = external hidden constant [2 x i8], align 1
@_ZN7randomx13codeLoopStoreE = external dso_local local_unnamed_addr global ptr, align 8
@_ZN7randomxL12prologueSizeE = external hidden local_unnamed_addr global i32, align 4
@_ZN7randomxL14epilogueOffsetE = external hidden local_unnamed_addr global i32, align 4
@_ZN7randomxL15REX_XOR_RAX_R64E = external hidden constant [2 x i8], align 1
@_ZN7randomxL13loopStoreSizeE = external hidden local_unnamed_addr global i32, align 4
@_ZN7randomxL7SUB_EBXE = external hidden constant [3 x i8], align 1
@_ZN7randomxL3JNZE = external hidden constant [2 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7randomx14JitCompilerX864emitEPKhm(ptr noundef nonnull align 8 dereferenceable(68), ptr noundef, i64 noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7randomx14JitCompilerX868emitByteEh(ptr noundef nonnull align 8 dereferenceable(68), i8 noundef zeroext) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7randomx14JitCompilerX8623generateProgramEpilogueERNS_7ProgramERNS_20ProgramConfigurationE(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr nocapture noundef nonnull readnone align 8 dereferenceable(2176) %1, ptr nocapture noundef nonnull readonly align 8 dereferenceable(32) %2) local_unnamed_addr #1 align 2 {
  tail call void @_ZN7randomx14JitCompilerX864emitILm2EEEvRAT__Kh(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr noundef nonnull align 1 dereferenceable(2) @_ZN7randomxL12REX_MOV_RR64E)
  %4 = getelementptr inbounds i8, ptr %2, i64 16
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = trunc i32 %5 to i8
  %7 = add i8 %6, -64
  tail call void @_ZN7randomx14JitCompilerX868emitByteEh(ptr noundef nonnull align 8 dereferenceable(68) %0, i8 noundef zeroext %7)
  tail call void @_ZN7randomx14JitCompilerX864emitILm2EEEvRAT__Kh(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr noundef nonnull align 1 dereferenceable(2) @_ZN7randomxL15REX_XOR_RAX_R64E)
  %8 = getelementptr inbounds i8, ptr %2, i64 20
  %9 = load i32, ptr %8, align 4, !tbaa !10
  %10 = trunc i32 %9 to i8
  %11 = add i8 %10, -64
  tail call void @_ZN7randomx14JitCompilerX868emitByteEh(ptr noundef nonnull align 8 dereferenceable(68) %0, i8 noundef zeroext %11)
  tail call void @_ZN7randomx14JitCompilerX864emitEPKhm(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr noundef nonnull @randomx_prefetch_scratchpad, i64 noundef sub (i64 ptrtoint (ptr @randomx_prefetch_scratchpad_end to i64), i64 ptrtoint (ptr @randomx_prefetch_scratchpad to i64)))
  %12 = getelementptr inbounds i8, ptr %0, i64 56
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %0, i64 64
  %15 = load i32, ptr %14, align 8, !tbaa !18
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %13, i64 %16
  %18 = load ptr, ptr @_ZN7randomx13codeLoopStoreE, align 8, !tbaa !19
  %19 = load i32, ptr @_ZN7randomxL13loopStoreSizeE, align 4, !tbaa !20
  %20 = sext i32 %19 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %17, ptr align 1 %18, i64 %20, i1 false)
  %21 = load i32, ptr @_ZN7randomxL13loopStoreSizeE, align 4, !tbaa !20
  %22 = load i32, ptr %14, align 8, !tbaa !18
  %23 = add nsw i32 %22, %21
  store i32 %23, ptr %14, align 8, !tbaa !18
  tail call void @_ZN7randomx14JitCompilerX864emitILm3EEEvRAT__Kh(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr noundef nonnull align 1 dereferenceable(3) @_ZN7randomxL7SUB_EBXE)
  tail call void @_ZN7randomx14JitCompilerX864emitILm2EEEvRAT__Kh(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr noundef nonnull align 1 dereferenceable(2) @_ZN7randomxL3JNZE)
  %24 = load i32, ptr @_ZN7randomxL12prologueSizeE, align 4, !tbaa !20
  %25 = load i32, ptr %14, align 8, !tbaa !18
  %26 = add i32 %24, -4
  %27 = sub i32 %26, %25
  tail call void @_ZN7randomx14JitCompilerX866emit32Ej(ptr noundef nonnull align 8 dereferenceable(68) %0, i32 noundef %27)
  tail call void @_ZN7randomx14JitCompilerX868emitByteEh(ptr noundef nonnull align 8 dereferenceable(68) %0, i8 noundef zeroext -23)
  %28 = load i32, ptr @_ZN7randomxL14epilogueOffsetE, align 4, !tbaa !20
  %29 = load i32, ptr %14, align 8, !tbaa !18
  %30 = add i32 %28, -4
  %31 = sub i32 %30, %29
  tail call void @_ZN7randomx14JitCompilerX866emit32Ej(ptr noundef nonnull align 8 dereferenceable(68) %0, i32 noundef %31)
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7randomx14JitCompilerX866emit32Ej(ptr noundef nonnull align 8 dereferenceable(68), i32 noundef) local_unnamed_addr #1 align 2

declare void @randomx_prefetch_scratchpad() #2

declare void @randomx_prefetch_scratchpad_end() #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7randomx14JitCompilerX864emitILm3EEEvRAT__Kh(ptr noundef nonnull align 8 dereferenceable(68), ptr noundef nonnull align 1 dereferenceable(3)) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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" }

!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, !9, i64 16}
!6 = !{!"_ZTSN7randomx20ProgramConfigurationE", !7, i64 0, !9, i64 16, !9, i64 20, !9, i64 24, !9, i64 28}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!6, !9, i64 20}
!11 = !{!12, !17, i64 56}
!12 = !{!"_ZTSN7randomx14JitCompilerX86E", !13, i64 0, !7, i64 24, !17, i64 56, !9, i64 64}
!13 = !{!"_ZTSSt6vectorIiSaIiEE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !17, i64 0, !17, i64 8, !17, i64 16}
!17 = !{!"any pointer", !7, i64 0}
!18 = !{!12, !9, i64 64}
!19 = !{!17, !17, i64 0}
!20 = !{!9, !9, i64 0}


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