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

; 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_vm = type { ptr, [56 x i8], %"class.randomx::Program", %"struct.randomx::RegisterFile", %"struct.randomx::ProgramConfiguration", %"struct.randomx::MemoryRegisters", ptr, %union.anon.8, i64, %"class.std::__cxx11::basic_string", [8 x i8], [8 x i64], [16 x i8] }
%"class.randomx::Program" = type { [16 x i64], [256 x %"class.randomx::Instruction"] }
%"class.randomx::Instruction" = type { i8, i8, i8, i8, i32 }
%"struct.randomx::RegisterFile" = type { [8 x i64], [4 x %"struct.randomx::fpu_reg_t"], [4 x %"struct.randomx::fpu_reg_t"], [4 x %"struct.randomx::fpu_reg_t"] }
%"struct.randomx::fpu_reg_t" = type { double, double }
%"struct.randomx::ProgramConfiguration" = type { [2 x i64], i32, i32, i32, i32 }
%"struct.randomx::MemoryRegisters" = type { i32, i32, ptr }
%union.anon.8 = type { ptr }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

; 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

declare i32 @randomx_blake2b(ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) #1

declare void @_ZN10randomx_vm17resetRoundingModeEv(ptr noundef nonnull align 64 dereferenceable(2672)) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN10randomx_vm15getRegisterFileEv(ptr noundef nonnull align 64 dereferenceable(2672)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @randomx_calculate_hash_next(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN10randomx_vm17resetRoundingModeEv(ptr noundef nonnull align 64 dereferenceable(2672) %10)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %11

11:                                               ; preds = %29, %4
  %12 = load i32, ptr %9, align 4, !tbaa !11
  %13 = icmp ult i32 %12, 7
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %32

15:                                               ; preds = %11
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %class.randomx_vm, ptr %17, i32 0, i32 11
  %19 = getelementptr inbounds [8 x i64], ptr %18, i64 0, i64 0
  %20 = load ptr, ptr %16, align 64, !tbaa !13
  %21 = getelementptr inbounds ptr, ptr %20, i64 8
  %22 = load ptr, ptr %21, align 8
  call void %22(ptr noundef nonnull align 64 dereferenceable(2672) %16, ptr noundef %19)
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %class.randomx_vm, ptr %23, i32 0, i32 11
  %25 = getelementptr inbounds [8 x i64], ptr %24, i64 0, i64 0
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call noundef ptr @_ZN10randomx_vm15getRegisterFileEv(ptr noundef nonnull align 64 dereferenceable(2672) %26)
  %28 = call i32 @randomx_blake2b(ptr noundef %25, i64 noundef 64, ptr noundef %27, i64 noundef 256, ptr noundef null, i64 noundef 0)
  br label %29

29:                                               ; preds = %15
  %30 = load i32, ptr %9, align 4, !tbaa !11
  %31 = add i32 %30, 1
  store i32 %31, ptr %9, align 4, !tbaa !11
  br label %11, !llvm.loop !15

32:                                               ; preds = %14
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %class.randomx_vm, ptr %34, i32 0, i32 11
  %36 = getelementptr inbounds [8 x i64], ptr %35, i64 0, i64 0
  %37 = load ptr, ptr %33, align 64, !tbaa !13
  %38 = getelementptr inbounds ptr, ptr %37, i64 8
  %39 = load ptr, ptr %38, align 8
  call void %39(ptr noundef nonnull align 64 dereferenceable(2672) %33, ptr noundef %36)
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %class.randomx_vm, ptr %40, i32 0, i32 11
  %42 = getelementptr inbounds [8 x i64], ptr %41, i64 0, i64 0
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load i64, ptr %7, align 8, !tbaa !9
  %45 = call i32 @randomx_blake2b(ptr noundef %42, i64 noundef 64, ptr noundef %43, i64 noundef %44, ptr noundef null, i64 noundef 0)
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %class.randomx_vm, ptr %48, i32 0, i32 11
  %50 = getelementptr inbounds [8 x i64], ptr %49, i64 0, i64 0
  %51 = load ptr, ptr %46, align 64, !tbaa !13
  %52 = getelementptr inbounds ptr, ptr %51, i64 4
  %53 = load ptr, ptr %52, align 8
  call void %53(ptr noundef nonnull align 64 dereferenceable(2672) %46, ptr noundef %47, i64 noundef 32, ptr noundef %50)
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 #4 = { 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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"vtable pointer", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

declare i32 @randomx_blake2b(ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

declare void @_ZN10randomx_vm17resetRoundingModeEv(ptr noundef nonnull align 64 dereferenceable(2672)) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN10randomx_vm15getRegisterFileEv(ptr noundef nonnull align 64 dereferenceable(2672)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @randomx_calculate_hash_next(ptr noundef nonnull %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  tail call void @_ZN10randomx_vm17resetRoundingModeEv(ptr noundef nonnull align 64 dereferenceable(2672) %0)
  %5 = getelementptr inbounds i8, ptr %0, i64 2608
  %6 = load ptr, ptr %0, align 64, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 64
  %8 = load ptr, ptr %7, align 8
  tail call void %8(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef nonnull %5)
  %9 = tail call noundef ptr @_ZN10randomx_vm15getRegisterFileEv(ptr noundef nonnull align 64 dereferenceable(2672) %0)
  %10 = tail call i32 @randomx_blake2b(ptr noundef nonnull %5, i64 noundef 64, ptr noundef %9, i64 noundef 256, ptr noundef null, i64 noundef 0)
  %11 = load ptr, ptr %0, align 64, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 64
  %13 = load ptr, ptr %12, align 8
  tail call void %13(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef nonnull %5)
  %14 = tail call noundef ptr @_ZN10randomx_vm15getRegisterFileEv(ptr noundef nonnull align 64 dereferenceable(2672) %0)
  %15 = tail call i32 @randomx_blake2b(ptr noundef nonnull %5, i64 noundef 64, ptr noundef %14, i64 noundef 256, ptr noundef null, i64 noundef 0)
  %16 = load ptr, ptr %0, align 64, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 64
  %18 = load ptr, ptr %17, align 8
  tail call void %18(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef nonnull %5)
  %19 = tail call noundef ptr @_ZN10randomx_vm15getRegisterFileEv(ptr noundef nonnull align 64 dereferenceable(2672) %0)
  %20 = tail call i32 @randomx_blake2b(ptr noundef nonnull %5, i64 noundef 64, ptr noundef %19, i64 noundef 256, ptr noundef null, i64 noundef 0)
  %21 = load ptr, ptr %0, align 64, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 64
  %23 = load ptr, ptr %22, align 8
  tail call void %23(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef nonnull %5)
  %24 = tail call noundef ptr @_ZN10randomx_vm15getRegisterFileEv(ptr noundef nonnull align 64 dereferenceable(2672) %0)
  %25 = tail call i32 @randomx_blake2b(ptr noundef nonnull %5, i64 noundef 64, ptr noundef %24, i64 noundef 256, ptr noundef null, i64 noundef 0)
  %26 = load ptr, ptr %0, align 64, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 64
  %28 = load ptr, ptr %27, align 8
  tail call void %28(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef nonnull %5)
  %29 = tail call noundef ptr @_ZN10randomx_vm15getRegisterFileEv(ptr noundef nonnull align 64 dereferenceable(2672) %0)
  %30 = tail call i32 @randomx_blake2b(ptr noundef nonnull %5, i64 noundef 64, ptr noundef %29, i64 noundef 256, ptr noundef null, i64 noundef 0)
  %31 = load ptr, ptr %0, align 64, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i64 64
  %33 = load ptr, ptr %32, align 8
  tail call void %33(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef nonnull %5)
  %34 = tail call noundef ptr @_ZN10randomx_vm15getRegisterFileEv(ptr noundef nonnull align 64 dereferenceable(2672) %0)
  %35 = tail call i32 @randomx_blake2b(ptr noundef nonnull %5, i64 noundef 64, ptr noundef %34, i64 noundef 256, ptr noundef null, i64 noundef 0)
  %36 = load ptr, ptr %0, align 64, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 64
  %38 = load ptr, ptr %37, align 8
  tail call void %38(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef nonnull %5)
  %39 = tail call noundef ptr @_ZN10randomx_vm15getRegisterFileEv(ptr noundef nonnull align 64 dereferenceable(2672) %0)
  %40 = tail call i32 @randomx_blake2b(ptr noundef nonnull %5, i64 noundef 64, ptr noundef %39, i64 noundef 256, ptr noundef null, i64 noundef 0)
  %41 = load ptr, ptr %0, align 64, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 64
  %43 = load ptr, ptr %42, align 8
  tail call void %43(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef nonnull %5)
  %44 = tail call i32 @randomx_blake2b(ptr noundef nonnull %5, i64 noundef 64, ptr noundef %1, i64 noundef %2, ptr noundef null, i64 noundef 0)
  %45 = load ptr, ptr %0, align 64, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 32
  %47 = load ptr, ptr %46, align 8
  tail call void %47(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef %3, i64 noundef 32, ptr noundef nonnull %5)
  ret void
}

attributes #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 = { 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" }

!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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass