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

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

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@_ZTISt13runtime_error = external constant ptr
@_ZN7randomxL12codeLiteralsE = external hidden global ptr, align 8
@_ZN7randomxL12sizeLiteralsE = external hidden global i32, align 4
@_ZN7randomxL12codeDataInitE = external hidden global ptr, align 8
@_ZN7randomxL12sizeDataInitE = external hidden global i32, align 4
@_ZN7randomxL12sizePrologueE = external hidden global i32, align 4
@_ZN7randomxL13sizeLoopBeginE = external hidden global i32, align 4
@_ZN7randomxL17offsetFixDataCallE = external hidden global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7randomx15JitCompilerRV64C2Ev(ptr noundef nonnull align 8 dereferenceable(1088) %0) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  %6 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %5, i32 0, i32 0
  %7 = call ptr @allocMemoryPages(i64 noundef 114688)
  %8 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %5, i32 0, i32 0
  %9 = getelementptr inbounds %"struct.randomx::CodeBuffer", ptr %8, i32 0, i32 0
  store ptr %7, ptr %9, align 8, !tbaa !9
  %10 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %5, i32 0, i32 0
  %11 = getelementptr inbounds %"struct.randomx::CodeBuffer", ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %21

14:                                               ; preds = %1
  %15 = call ptr @__cxa_allocate_exception(i64 16) #4
  invoke void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16) %15, ptr noundef @.str)
          to label %16 unwind label %17

16:                                               ; preds = %14
  call void @__cxa_throw(ptr %15, ptr @_ZTISt13runtime_error, ptr @_ZNSt13runtime_errorD1Ev) #5
  unreachable

17:                                               ; preds = %14
  %18 = landingpad { ptr, i32 }
          cleanup
  %19 = extractvalue { ptr, i32 } %18, 0
  store ptr %19, ptr %3, align 8
  %20 = extractvalue { ptr, i32 } %18, 1
  store i32 %20, ptr %4, align 4
  call void @__cxa_free_exception(ptr %15) #4
  br label %50

21:                                               ; preds = %1
  %22 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %5, i32 0, i32 0
  %23 = load ptr, ptr @_ZN7randomxL12codeLiteralsE, align 8, !tbaa !5
  %24 = load i32, ptr @_ZN7randomxL12sizeLiteralsE, align 4, !tbaa !12
  call void @_ZN7randomx10CodeBuffer6emitAtEiPKhi(ptr noundef nonnull align 8 dereferenceable(16) %22, i32 noundef 2048, ptr noundef %23, i32 noundef %24)
  %25 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %5, i32 0, i32 0
  %26 = load ptr, ptr @_ZN7randomxL12codeDataInitE, align 8, !tbaa !5
  %27 = load i32, ptr @_ZN7randomxL12sizeDataInitE, align 4, !tbaa !12
  %28 = load i32, ptr @_ZN7randomxL12sizePrologueE, align 4, !tbaa !12
  %29 = add nsw i32 %27, %28
  %30 = load i32, ptr @_ZN7randomxL13sizeLoopBeginE, align 4, !tbaa !12
  %31 = add nsw i32 %29, %30
  call void @_ZN7randomx10CodeBuffer6emitAtEiPKhi(ptr noundef nonnull align 8 dereferenceable(16) %25, i32 noundef 4096, ptr noundef %26, i32 noundef %31)
  %32 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %5, i32 0, i32 0
  %33 = getelementptr inbounds %"struct.randomx::CodeBuffer", ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  %35 = getelementptr inbounds i8, ptr %34, i64 4096
  %36 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %5, i32 0, i32 1
  store ptr %35, ptr %36, align 8, !tbaa !13
  %37 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %5, i32 0, i32 0
  %38 = getelementptr inbounds %"struct.randomx::CodeBuffer", ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = getelementptr inbounds i8, ptr %39, i64 4096
  %41 = load i32, ptr @_ZN7randomxL12sizeDataInitE, align 4, !tbaa !12
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr %40, i64 %42
  %44 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %5, i32 0, i32 2
  store ptr %43, ptr %44, align 8, !tbaa !16
  %45 = getelementptr inbounds %"class.randomx::JitCompilerRV64", ptr %5, i32 0, i32 0
  %46 = load i32, ptr @_ZN7randomxL17offsetFixDataCallE, align 4, !tbaa !12
  %47 = sext i32 %46 to i64
  %48 = add i64 4096, %47
  %49 = trunc i64 %48 to i32
  call void @_ZN7randomxL8emitJumpERNS_10CodeBufferEiii(ptr noundef nonnull align 8 dereferenceable(16) %45, i32 noundef 1, i32 noundef %49, i32 noundef 57344)
  ret void

50:                                               ; preds = %17
  %51 = load ptr, ptr %3, align 8
  %52 = load i32, ptr %4, align 4
  %53 = insertvalue { ptr, i32 } poison, ptr %51, 0
  %54 = insertvalue { ptr, i32 } %53, i32 %52, 1
  resume { ptr, i32 } %54
}

declare ptr @allocMemoryPages(i64 noundef) #1

declare ptr @__cxa_allocate_exception(i64)

declare void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

declare void @__cxa_free_exception(ptr)

; Function Attrs: nounwind
declare void @_ZNSt13runtime_errorD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2

declare void @__cxa_throw(ptr, ptr, ptr)

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

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

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

!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, !6, i64 0}
!10 = !{!"_ZTSN7randomx10CodeBufferE", !6, i64 0, !11, i64 8, !11, i64 12}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !6, i64 1072}
!14 = !{!"_ZTSN7randomx15JitCompilerRV64E", !15, i64 0, !6, i64 1072, !6, i64 1080}
!15 = !{!"_ZTSN7randomx13CompilerStateE", !10, i64 0, !7, i64 16, !7, i64 1040}
!16 = !{!14, !6, i64 1080}


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

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@_ZTISt13runtime_error = external constant ptr
@_ZN7randomxL12codeLiteralsE = external hidden local_unnamed_addr global ptr, align 8
@_ZN7randomxL12sizeLiteralsE = external hidden local_unnamed_addr global i32, align 4
@_ZN7randomxL12codeDataInitE = external hidden local_unnamed_addr global ptr, align 8
@_ZN7randomxL12sizeDataInitE = external hidden local_unnamed_addr global i32, align 4
@_ZN7randomxL12sizePrologueE = external hidden local_unnamed_addr global i32, align 4
@_ZN7randomxL13sizeLoopBeginE = external hidden local_unnamed_addr global i32, align 4
@_ZN7randomxL17offsetFixDataCallE = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7randomx15JitCompilerRV64C2Ev(ptr noundef nonnull align 8 dereferenceable(1088) %0) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = tail call ptr @allocMemoryPages(i64 noundef 114688)
  store ptr %2, ptr %0, align 8, !tbaa !5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %9

4:                                                ; preds = %1
  %5 = tail call ptr @__cxa_allocate_exception(i64 16) #4
  invoke void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull @.str)
          to label %6 unwind label %7

6:                                                ; preds = %4
  tail call void @__cxa_throw(ptr nonnull %5, ptr nonnull @_ZTISt13runtime_error, ptr nonnull @_ZNSt13runtime_errorD1Ev) #5
  unreachable

7:                                                ; preds = %4
  %8 = landingpad { ptr, i32 }
          cleanup
  tail call void @__cxa_free_exception(ptr %5) #4
  resume { ptr, i32 } %8

9:                                                ; preds = %1
  %10 = load ptr, ptr @_ZN7randomxL12codeLiteralsE, align 8, !tbaa !11
  %11 = load i32, ptr @_ZN7randomxL12sizeLiteralsE, align 4, !tbaa !12
  tail call void @_ZN7randomx10CodeBuffer6emitAtEiPKhi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef 2048, ptr noundef %10, i32 noundef %11)
  %12 = load ptr, ptr @_ZN7randomxL12codeDataInitE, align 8, !tbaa !11
  %13 = load i32, ptr @_ZN7randomxL12sizeDataInitE, align 4, !tbaa !12
  %14 = load i32, ptr @_ZN7randomxL12sizePrologueE, align 4, !tbaa !12
  %15 = add nsw i32 %14, %13
  %16 = load i32, ptr @_ZN7randomxL13sizeLoopBeginE, align 4, !tbaa !12
  %17 = add nsw i32 %15, %16
  tail call void @_ZN7randomx10CodeBuffer6emitAtEiPKhi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef 4096, ptr noundef %12, i32 noundef %17)
  %18 = load ptr, ptr %0, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 4096
  %20 = getelementptr inbounds i8, ptr %0, i64 1072
  store ptr %19, ptr %20, align 8, !tbaa !13
  %21 = load i32, ptr @_ZN7randomxL12sizeDataInitE, align 4, !tbaa !12
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i8, ptr %19, i64 %22
  %24 = getelementptr inbounds i8, ptr %0, i64 1080
  store ptr %23, ptr %24, align 8, !tbaa !16
  %25 = load i32, ptr @_ZN7randomxL17offsetFixDataCallE, align 4, !tbaa !12
  %26 = add i32 %25, 4096
  tail call void @_ZN7randomxL8emitJumpERNS_10CodeBufferEiii(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef 1, i32 noundef %26, i32 noundef 57344)
  ret void
}

declare ptr @allocMemoryPages(i64 noundef) local_unnamed_addr #1

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

declare void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

declare void @__cxa_free_exception(ptr) local_unnamed_addr

; Function Attrs: nounwind
declare void @_ZNSt13runtime_errorD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

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

; 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

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

!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 0}
!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, !7, i64 1072}
!14 = !{!"_ZTSN7randomx15JitCompilerRV64E", !15, i64 0, !7, i64 1072, !7, i64 1080}
!15 = !{!"_ZTSN7randomx13CompilerStateE", !6, i64 0, !8, i64 16, !8, i64 1040}
!16 = !{!14, !7, i64 1080}


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