; 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_last(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZN10randomx_vm17resetRoundingModeEv(ptr noundef nonnull align 64 dereferenceable(2672) %6)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %25, %2
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = icmp slt i32 %8, 7
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %28

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

25:                                               ; preds = %11
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %5, align 4, !tbaa !9
  br label %7, !llvm.loop !13

28:                                               ; preds = %10
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %class.randomx_vm, ptr %30, i32 0, i32 11
  %32 = getelementptr inbounds [8 x i64], ptr %31, i64 0, i64 0
  %33 = load ptr, ptr %29, align 64, !tbaa !11
  %34 = getelementptr inbounds ptr, ptr %33, i64 8
  %35 = load ptr, ptr %34, align 8
  call void %35(ptr noundef nonnull align 64 dereferenceable(2672) %29, ptr noundef %32)
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load ptr, ptr %36, align 64, !tbaa !11
  %39 = getelementptr inbounds ptr, ptr %38, i64 3
  %40 = load ptr, ptr %39, align 8
  call void %40(ptr noundef nonnull align 64 dereferenceable(2672) %36, ptr noundef %37, i64 noundef 32)
  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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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_last(ptr noundef nonnull %0, ptr noundef %1) local_unnamed_addr #2 {
  tail call void @_ZN10randomx_vm17resetRoundingModeEv(ptr noundef nonnull align 64 dereferenceable(2672) %0)
  %3 = getelementptr inbounds i8, ptr %0, i64 2608
  %4 = load ptr, ptr %0, align 64, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 64
  %6 = load ptr, ptr %5, align 8
  tail call void %6(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef nonnull %3)
  %7 = tail call noundef ptr @_ZN10randomx_vm15getRegisterFileEv(ptr noundef nonnull align 64 dereferenceable(2672) %0)
  %8 = tail call i32 @randomx_blake2b(ptr noundef nonnull %3, i64 noundef 64, ptr noundef %7, i64 noundef 256, ptr noundef null, i64 noundef 0)
  %9 = load ptr, ptr %0, align 64, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 64
  %11 = load ptr, ptr %10, align 8
  tail call void %11(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef nonnull %3)
  %12 = tail call noundef ptr @_ZN10randomx_vm15getRegisterFileEv(ptr noundef nonnull align 64 dereferenceable(2672) %0)
  %13 = tail call i32 @randomx_blake2b(ptr noundef nonnull %3, i64 noundef 64, ptr noundef %12, i64 noundef 256, ptr noundef null, i64 noundef 0)
  %14 = load ptr, ptr %0, align 64, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 64
  %16 = load ptr, ptr %15, align 8
  tail call void %16(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef nonnull %3)
  %17 = tail call noundef ptr @_ZN10randomx_vm15getRegisterFileEv(ptr noundef nonnull align 64 dereferenceable(2672) %0)
  %18 = tail call i32 @randomx_blake2b(ptr noundef nonnull %3, i64 noundef 64, ptr noundef %17, i64 noundef 256, ptr noundef null, i64 noundef 0)
  %19 = load ptr, ptr %0, align 64, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 64
  %21 = load ptr, ptr %20, align 8
  tail call void %21(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef nonnull %3)
  %22 = tail call noundef ptr @_ZN10randomx_vm15getRegisterFileEv(ptr noundef nonnull align 64 dereferenceable(2672) %0)
  %23 = tail call i32 @randomx_blake2b(ptr noundef nonnull %3, i64 noundef 64, ptr noundef %22, i64 noundef 256, ptr noundef null, i64 noundef 0)
  %24 = load ptr, ptr %0, align 64, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 64
  %26 = load ptr, ptr %25, align 8
  tail call void %26(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef nonnull %3)
  %27 = tail call noundef ptr @_ZN10randomx_vm15getRegisterFileEv(ptr noundef nonnull align 64 dereferenceable(2672) %0)
  %28 = tail call i32 @randomx_blake2b(ptr noundef nonnull %3, i64 noundef 64, ptr noundef %27, i64 noundef 256, ptr noundef null, i64 noundef 0)
  %29 = load ptr, ptr %0, align 64, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 64
  %31 = load ptr, ptr %30, align 8
  tail call void %31(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef nonnull %3)
  %32 = tail call noundef ptr @_ZN10randomx_vm15getRegisterFileEv(ptr noundef nonnull align 64 dereferenceable(2672) %0)
  %33 = tail call i32 @randomx_blake2b(ptr noundef nonnull %3, i64 noundef 64, ptr noundef %32, i64 noundef 256, ptr noundef null, i64 noundef 0)
  %34 = load ptr, ptr %0, align 64, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 64
  %36 = load ptr, ptr %35, align 8
  tail call void %36(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef nonnull %3)
  %37 = tail call noundef ptr @_ZN10randomx_vm15getRegisterFileEv(ptr noundef nonnull align 64 dereferenceable(2672) %0)
  %38 = tail call i32 @randomx_blake2b(ptr noundef nonnull %3, i64 noundef 64, ptr noundef %37, i64 noundef 256, ptr noundef null, i64 noundef 0)
  %39 = load ptr, ptr %0, align 64, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 64
  %41 = load ptr, ptr %40, align 8
  tail call void %41(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef nonnull %3)
  %42 = load ptr, ptr %0, align 64, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i64 24
  %44 = load ptr, ptr %43, align 8
  tail call void %44(ptr noundef nonnull align 64 dereferenceable(2672) %0, ptr noundef %1, i64 noundef 32)
  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,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass