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

; 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.randomx::JitCompilerRV64" = type { %"struct.randomx::CompilerState", ptr, ptr }
%"struct.randomx::CompilerState" = type { %"struct.randomx::CodeBuffer", [256 x i32], [8 x i32] }
%"struct.randomx::CodeBuffer" = type { ptr, i32, i32 }
%"struct.randomx::ProgramConfiguration" = type { [2 x i64], i32, i32, i32, i32 }

@_ZN7randomxL17codeDataReadLightE = external hidden global ptr, align 8
@_ZN7randomxL17sizeDataReadLightE = external hidden global i32, align 4
@_ZN7randomxL17offsetFixLoopCallE = external hidden global i32, align 4

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN7randomxL8emitJumpERNS_10CodeBufferEiii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN7randomxL17emitProgramPrefixERNS_13CompilerStateERNS_7ProgramERNS_20ProgramConfigurationE(ptr noundef nonnull align 8 dereferenceable(1072), ptr noundef nonnull align 8 dereferenceable(2176), ptr noundef nonnull align 8 dereferenceable(32)) #0

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7randomx3rviEjiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7randomx4regREi(i32 noundef) #2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN7randomxL17emitProgramSuffixERNS_13CompilerStateERNS_20ProgramConfigurationE(ptr noundef nonnull align 8 dereferenceable(1072), ptr noundef nonnull align 8 dereferenceable(32)) #0

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN7randomxL10clearCacheERNS_10CodeBufferE(ptr noundef nonnull align 8 dereferenceable(16)) #2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7randomx15JitCompilerRV6420generateProgramLightERNS_7ProgramERNS_20ProgramConfigurationEj(ptr noundef nonnull align 8 dereferenceable(1088) %0, ptr noundef nonnull align 8 dereferenceable(2176) %1, ptr noundef nonnull align 8 dereferenceable(32) %2, i32 noundef %3) #0 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8
  %14 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZN7randomxL17emitProgramPrefixERNS_13CompilerStateERNS_7ProgramERNS_20ProgramConfigurationE(ptr noundef nonnull align 8 dereferenceable(1072) %14, ptr noundef nonnull align 8 dereferenceable(2176) %15, ptr noundef nonnull align 8 dereferenceable(32) %16)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %17 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %13, i32 0, i32 0
  %18 = getelementptr inbounds %"struct.randomx::CodeBuffer", ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !11
  store i32 %19, ptr %9, align 4, !tbaa !9
  %20 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %13, i32 0, i32 0
  %21 = load ptr, ptr @_ZN7randomxL17codeDataReadLightE, align 8, !tbaa !5
  %22 = load i32, ptr @_ZN7randomxL17sizeDataReadLightE, align 4, !tbaa !9
  call void @_ZN7randomx10CodeBuffer4emitEPKhi(ptr noundef nonnull align 8 dereferenceable(16) %20, ptr noundef %21, i32 noundef %22)
  %23 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %13, i32 0, i32 0
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %"struct.randomx::ProgramConfiguration", ptr %25, i32 0, i32 3
  %27 = load i32, ptr %26, align 8, !tbaa !13
  %28 = call noundef i32 @_ZN7randomx4regREi(i32 noundef %27)
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.randomx::ProgramConfiguration", ptr %29, i32 0, i32 4
  %31 = load i32, ptr %30, align 4, !tbaa !15
  %32 = call noundef i32 @_ZN7randomx4regREi(i32 noundef %31)
  %33 = call noundef i32 @_ZN7randomx3rviEjiii(i32 noundef 16435, i32 noundef 8, i32 noundef %28, i32 noundef %32)
  call void @_ZN7randomx10CodeBuffer6emitAtIjEEviT_(ptr noundef nonnull align 8 dereferenceable(16) %23, i32 noundef %24, i32 noundef %33)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = udiv i64 %35, 64
  %37 = trunc i64 %36 to i32
  store i32 %37, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %38 = load i32, ptr %10, align 4, !tbaa !9
  %39 = shl i32 %38, 20
  %40 = ashr i32 %39, 20
  store i32 %40, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = ashr i32 %41, 12
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = icmp slt i32 %43, 0
  %45 = zext i1 %44 to i32
  %46 = add nsw i32 %42, %45
  store i32 %46, ptr %12, align 4, !tbaa !9
  %47 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %13, i32 0, i32 0
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = add nsw i32 %48, 4
  %50 = load i32, ptr %12, align 4, !tbaa !9
  %51 = shl i32 %50, 12
  %52 = or i32 55, %51
  %53 = call noundef i32 @_ZN7randomx4rvrdEi(i32 noundef 9)
  %54 = or i32 %52, %53
  call void @_ZN7randomx10CodeBuffer6emitAtIjEEviT_(ptr noundef nonnull align 8 dereferenceable(16) %47, i32 noundef %49, i32 noundef %54)
  %55 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %13, i32 0, i32 0
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = add nsw i32 %56, 8
  %58 = load i32, ptr %11, align 4, !tbaa !9
  %59 = call noundef i32 @_ZN7randomx3rviEjiii(i32 noundef 19, i32 noundef 9, i32 noundef 9, i32 noundef %58)
  call void @_ZN7randomx10CodeBuffer6emitAtIjEEviT_(ptr noundef nonnull align 8 dereferenceable(16) %55, i32 noundef %57, i32 noundef %59)
  %60 = load i32, ptr @_ZN7randomxL17offsetFixLoopCallE, align 4, !tbaa !9
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = add nsw i32 %61, %60
  store i32 %62, ptr %9, align 4, !tbaa !9
  %63 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %13, i32 0, i32 0
  %64 = load i32, ptr %9, align 4, !tbaa !9
  call void @_ZN7randomxL8emitJumpERNS_10CodeBufferEiii(ptr noundef nonnull align 8 dereferenceable(16) %63, i32 noundef 1, i32 noundef %64, i32 noundef 57344)
  %65 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %13, i32 0, i32 0
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZN7randomxL17emitProgramSuffixERNS_13CompilerStateERNS_20ProgramConfigurationE(ptr noundef nonnull align 8 dereferenceable(1072) %65, ptr noundef nonnull align 8 dereferenceable(32) %66)
  %67 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %13, i32 0, i32 0
  call void @_ZN7randomxL10clearCacheERNS_10CodeBufferE(ptr noundef nonnull align 8 dereferenceable(16) %67)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7randomx4rvrdEi(i32 noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTSN7randomx10CodeBufferE", !6, i64 0, !10, i64 8, !10, i64 12}
!13 = !{!14, !10, i64 24}
!14 = !{!"_ZTSN7randomx20ProgramConfigurationE", !7, i64 0, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!15 = !{!14, !10, i64 28}


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

@_ZN7randomxL17codeDataReadLightE = external hidden local_unnamed_addr global ptr, align 8
@_ZN7randomxL17sizeDataReadLightE = external hidden local_unnamed_addr global i32, align 4
@_ZN7randomxL17offsetFixLoopCallE = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN7randomxL8emitJumpERNS_10CodeBufferEiii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN7randomxL17emitProgramPrefixERNS_13CompilerStateERNS_7ProgramERNS_20ProgramConfigurationE(ptr noundef nonnull align 8 dereferenceable(1072), ptr noundef nonnull align 8 dereferenceable(2176), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7randomx3rviEjiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7randomx4regREi(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN7randomxL17emitProgramSuffixERNS_13CompilerStateERNS_20ProgramConfigurationE(ptr noundef nonnull align 8 dereferenceable(1072), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN7randomxL10clearCacheERNS_10CodeBufferE(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7randomx15JitCompilerRV6420generateProgramLightERNS_7ProgramERNS_20ProgramConfigurationEj(ptr noundef nonnull align 8 dereferenceable(1088) %0, ptr noundef nonnull align 8 dereferenceable(2176) %1, ptr noundef nonnull align 8 dereferenceable(32) %2, i32 noundef %3) local_unnamed_addr #0 align 2 {
  tail call void @_ZN7randomxL17emitProgramPrefixERNS_13CompilerStateERNS_7ProgramERNS_20ProgramConfigurationE(ptr noundef nonnull align 8 dereferenceable(1072) %0, ptr noundef nonnull align 8 dereferenceable(2176) %1, ptr noundef nonnull align 8 dereferenceable(32) %2)
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = load ptr, ptr @_ZN7randomxL17codeDataReadLightE, align 8, !tbaa !11
  %8 = load i32, ptr @_ZN7randomxL17sizeDataReadLightE, align 4, !tbaa !12
  tail call void @_ZN7randomx10CodeBuffer4emitEPKhi(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %7, i32 noundef %8)
  %9 = getelementptr inbounds i8, ptr %2, i64 24
  %10 = load i32, ptr %9, align 8, !tbaa !13
  %11 = tail call noundef i32 @_ZN7randomx4regREi(i32 noundef %10)
  %12 = getelementptr inbounds i8, ptr %2, i64 28
  %13 = load i32, ptr %12, align 4, !tbaa !15
  %14 = tail call noundef i32 @_ZN7randomx4regREi(i32 noundef %13)
  %15 = tail call noundef i32 @_ZN7randomx3rviEjiii(i32 noundef 16435, i32 noundef 8, i32 noundef %11, i32 noundef %14)
  tail call void @_ZN7randomx10CodeBuffer6emitAtIjEEviT_(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %6, i32 noundef %15)
  %16 = shl i32 %3, 14
  %17 = ashr i32 %16, 20
  %18 = lshr i32 %3, 18
  %.lobit = lshr i32 %17, 31
  %19 = add nuw nsw i32 %.lobit, %18
  %20 = add nsw i32 %6, 4
  %21 = shl nuw nsw i32 %19, 12
  %22 = tail call noundef i32 @_ZN7randomx4rvrdEi(i32 noundef 9)
  %23 = or i32 %21, %22
  %24 = or i32 %23, 55
  tail call void @_ZN7randomx10CodeBuffer6emitAtIjEEviT_(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %20, i32 noundef %24)
  %25 = add nsw i32 %6, 8
  %26 = tail call noundef i32 @_ZN7randomx3rviEjiii(i32 noundef 19, i32 noundef 9, i32 noundef 9, i32 noundef %17)
  tail call void @_ZN7randomx10CodeBuffer6emitAtIjEEviT_(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %25, i32 noundef %26)
  %27 = load i32, ptr @_ZN7randomxL17offsetFixLoopCallE, align 4, !tbaa !12
  %28 = add nsw i32 %27, %6
  tail call void @_ZN7randomxL8emitJumpERNS_10CodeBufferEiii(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef 1, i32 noundef %28, i32 noundef 57344)
  tail call void @_ZN7randomxL17emitProgramSuffixERNS_13CompilerStateERNS_20ProgramConfigurationE(ptr noundef nonnull align 8 dereferenceable(1072) %0, ptr noundef nonnull align 8 dereferenceable(32) %2)
  tail call void @_ZN7randomxL10clearCacheERNS_10CodeBufferE(ptr noundef nonnull align 8 dereferenceable(16) %0)
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7randomx4rvrdEi(i32 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 = { 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" }

!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 8}
!6 = !{!"_ZTSN7randomx10CodeBufferE", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !10, i64 24}
!14 = !{!"_ZTSN7randomx20ProgramConfigurationE", !8, i64 0, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!15 = !{!14, !10, i64 28}


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