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

; 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::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 }
%"class.randomx::Instruction" = type { i8, i8, i8, i8, i32 }

@_ZN7randomxL9MOV_RAX_IE = external hidden constant [2 x i8], align 1
@_ZN7randomxL11REX_IMUL_RME = external hidden constant [3 x i8], align 1

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK7randomx11Instruction8getImm32Ev(ptr noundef nonnull align 4 dereferenceable(8)) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7randomx14JitCompilerX8610h_IMUL_RCPERNS_11InstructionEi(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr noundef nonnull align 4 dereferenceable(8) %1, i32 noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = call noundef i32 @_ZNK7randomx11Instruction8getImm32Ev(ptr noundef nonnull align 4 dereferenceable(8) %9)
  store i32 %10, ptr %7, align 4, !tbaa !9
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = zext i32 %11 to i64
  %13 = call noundef zeroext i1 @_ZN7randomx16isZeroOrPowerOf2Em(i64 noundef %12)
  br i1 %13, label %31, label %14

14:                                               ; preds = %3
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = getelementptr inbounds %"class.randomx::JitCompilerX86", ptr %8, i32 0, i32 1
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %"class.randomx::Instruction", ptr %17, i32 0, i32 1
  %19 = load i8, ptr %18, align 1, !tbaa !11
  %20 = zext i8 %19 to i64
  %21 = getelementptr inbounds [8 x i32], ptr %16, i64 0, i64 %20
  store i32 %15, ptr %21, align 4, !tbaa !9
  call void @_ZN7randomx14JitCompilerX864emitILm2EEEvRAT__Kh(ptr noundef nonnull align 8 dereferenceable(68) %8, ptr noundef nonnull align 1 dereferenceable(2) @_ZN7randomxL9MOV_RAX_IE)
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = call i64 @randomx_reciprocal_fast(i32 noundef %22)
  call void @_ZN7randomx14JitCompilerX866emit64Em(ptr noundef nonnull align 8 dereferenceable(68) %8, i64 noundef %23)
  call void @_ZN7randomx14JitCompilerX864emitILm3EEEvRAT__Kh(ptr noundef nonnull align 8 dereferenceable(68) %8, ptr noundef nonnull align 1 dereferenceable(3) @_ZN7randomxL11REX_IMUL_RME)
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %"class.randomx::Instruction", ptr %24, i32 0, i32 1
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = zext i8 %26 to i32
  %28 = mul nsw i32 8, %27
  %29 = add nsw i32 192, %28
  %30 = trunc i32 %29 to i8
  call void @_ZN7randomx14JitCompilerX868emitByteEh(ptr noundef nonnull align 8 dereferenceable(68) %8, i8 noundef zeroext %30)
  br label %31

31:                                               ; preds = %14, %3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN7randomx16isZeroOrPowerOf2Em(i64 noundef) #3

declare i64 @randomx_reciprocal_fast(i32 noundef) #4

attributes #0 = { nocallback nofree nosync 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 = { inlinehint 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 #4 = { "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 #5 = { 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, !7, i64 1}
!12 = !{!"_ZTSN7randomx11InstructionE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !10, i64 4}


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

@_ZN7randomxL9MOV_RAX_IE = external hidden constant [2 x i8], align 1
@_ZN7randomxL11REX_IMUL_RME = external hidden constant [3 x i8], align 1

; 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 #0 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 #0 align 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 #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7randomx14JitCompilerX8610h_IMUL_RCPERNS_11InstructionEi(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr noundef nonnull align 4 dereferenceable(8) %1, i32 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = tail call noundef i32 @_ZNK7randomx11Instruction8getImm32Ev(ptr noundef nonnull align 4 dereferenceable(8) %1)
  %5 = zext i32 %4 to i64
  %6 = tail call noundef zeroext i1 @_ZN7randomx16isZeroOrPowerOf2Em(i64 noundef %5)
  br i1 %6, label %17, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = getelementptr inbounds i8, ptr %1, i64 1
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = zext i8 %10 to i64
  %12 = getelementptr inbounds [8 x i32], ptr %8, i64 0, i64 %11
  store i32 %2, ptr %12, align 4, !tbaa !10
  tail call void @_ZN7randomx14JitCompilerX864emitILm2EEEvRAT__Kh(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr noundef nonnull align 1 dereferenceable(2) @_ZN7randomxL9MOV_RAX_IE)
  %13 = tail call i64 @randomx_reciprocal_fast(i32 noundef %4)
  tail call void @_ZN7randomx14JitCompilerX866emit64Em(ptr noundef nonnull align 8 dereferenceable(68) %0, i64 noundef %13)
  tail call void @_ZN7randomx14JitCompilerX864emitILm3EEEvRAT__Kh(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr noundef nonnull align 1 dereferenceable(3) @_ZN7randomxL11REX_IMUL_RME)
  %14 = load i8, ptr %9, align 1, !tbaa !5
  %15 = shl i8 %14, 3
  %16 = add i8 %15, -64
  tail call void @_ZN7randomx14JitCompilerX868emitByteEh(ptr noundef nonnull align 8 dereferenceable(68) %0, i8 noundef zeroext %16)
  br label %17

17:                                               ; preds = %7, %3
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN7randomx16isZeroOrPowerOf2Em(i64 noundef) local_unnamed_addr #2

declare i64 @randomx_reciprocal_fast(i32 noundef) local_unnamed_addr #3

attributes #0 = { 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 #1 = { 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 #2 = { inlinehint 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 = { "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, !7, i64 1}
!6 = !{!"_ZTSN7randomx11InstructionE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !9, i64 4}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!9, !9, i64 0}


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