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

%struct.randomx_dataset = type { ptr, ptr }

@_ZTISt9exception = external constant ptr

; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Zan13randomx_flagsS_(i32 noundef, i32 noundef) #3

declare noundef ptr @_ZN7randomx16AlignedAllocatorILm64EE11allocMemoryEm(i64 noundef) #4

declare noundef ptr @_ZN7randomx18LargePageAllocator11allocMemoryEm(i64 noundef) #4

; Function Attrs: nounwind memory(none)
declare i32 @llvm.eh.typeid.for.p0(ptr) #5

declare ptr @__cxa_begin_catch(ptr)

declare void @__cxa_end_catch()

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #6

; Function Attrs: mustprogress uwtable
define dso_local ptr @randomx_alloc_dataset(i32 noundef %0) #7 personality ptr @__gxx_personality_v0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #8
  store ptr null, ptr %3, align 8, !tbaa !9
  %7 = invoke noalias noundef nonnull ptr @_Znwm(i64 noundef 16) #9
          to label %8 unwind label %20

8:                                                ; preds = %1
  call void @llvm.memset.p0.i64(ptr align 16 %7, i8 0, i64 16, i1 false)
  call void @_ZN15randomx_datasetC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %7) #8
  store ptr %7, ptr %3, align 8, !tbaa !9
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = invoke noundef i32 @_Zan13randomx_flagsS_(i32 noundef %9, i32 noundef 1)
          to label %11 unwind label %20

11:                                               ; preds = %8
  %12 = icmp ne i32 %10, 0
  br i1 %12, label %13, label %36

13:                                               ; preds = %11
  %14 = load ptr, ptr %3, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.randomx_dataset, ptr %14, i32 0, i32 1
  store ptr @_ZN7randomx14deallocDatasetINS_18LargePageAllocatorEEEvP15randomx_dataset, ptr %15, align 8, !tbaa !11
  %16 = invoke noundef ptr @_ZN7randomx18LargePageAllocator11allocMemoryEm(i64 noundef 2181038016)
          to label %17 unwind label %20

17:                                               ; preds = %13
  %18 = load ptr, ptr %3, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.randomx_dataset, ptr %18, i32 0, i32 0
  store ptr %16, ptr %19, align 8, !tbaa !13
  br label %43

20:                                               ; preds = %36, %13, %8, %1
  %21 = landingpad { ptr, i32 }
          cleanup
          catch ptr @_ZTISt9exception
  %22 = extractvalue { ptr, i32 } %21, 0
  store ptr %22, ptr %4, align 8
  %23 = extractvalue { ptr, i32 } %21, 1
  store i32 %23, ptr %5, align 4
  br label %24

24:                                               ; preds = %20
  %25 = load i32, ptr %5, align 4
  %26 = call i32 @llvm.eh.typeid.for.p0(ptr @_ZTISt9exception) #8
  %27 = icmp eq i32 %25, %26
  br i1 %27, label %28, label %62

28:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #8
  %29 = load ptr, ptr %4, align 8
  %30 = call ptr @__cxa_begin_catch(ptr %29) #8
  store ptr %30, ptr %6, align 8
  %31 = load ptr, ptr %3, align 8, !tbaa !9
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %48

33:                                               ; preds = %28
  %34 = load ptr, ptr %3, align 8, !tbaa !9
  invoke void @randomx_release_dataset(ptr noundef %34)
          to label %35 unwind label %44

35:                                               ; preds = %33
  store ptr null, ptr %3, align 8, !tbaa !9
  br label %48

36:                                               ; preds = %11
  %37 = load ptr, ptr %3, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.randomx_dataset, ptr %37, i32 0, i32 1
  store ptr @_ZN7randomx14deallocDatasetINS_16AlignedAllocatorILm64EEEEEvP15randomx_dataset, ptr %38, align 8, !tbaa !11
  %39 = invoke noundef ptr @_ZN7randomx16AlignedAllocatorILm64EE11allocMemoryEm(i64 noundef 2181038016)
          to label %40 unwind label %20

40:                                               ; preds = %36
  %41 = load ptr, ptr %3, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.randomx_dataset, ptr %41, i32 0, i32 0
  store ptr %39, ptr %42, align 8, !tbaa !13
  br label %43

43:                                               ; preds = %40, %17
  br label %49

44:                                               ; preds = %33
  %45 = landingpad { ptr, i32 }
          cleanup
  %46 = extractvalue { ptr, i32 } %45, 0
  store ptr %46, ptr %4, align 8
  %47 = extractvalue { ptr, i32 } %45, 1
  store i32 %47, ptr %5, align 4
  invoke void @__cxa_end_catch()
          to label %59 unwind label %68

48:                                               ; preds = %35, %28
  call void @__cxa_end_catch()
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #8
  br label %49

49:                                               ; preds = %48, %43
  %50 = load ptr, ptr %3, align 8, !tbaa !9
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %60

52:                                               ; preds = %49
  %53 = load ptr, ptr %3, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.randomx_dataset, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !13
  %56 = icmp eq ptr %55, null
  br i1 %56, label %57, label %60

57:                                               ; preds = %52
  %58 = load ptr, ptr %3, align 8, !tbaa !9
  call void @randomx_release_dataset(ptr noundef %58)
  store ptr null, ptr %3, align 8, !tbaa !9
  br label %60

59:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #8
  br label %62

60:                                               ; preds = %57, %52, %49
  %61 = load ptr, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #8
  ret ptr %61

62:                                               ; preds = %59, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #8
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr %4, align 8
  %65 = load i32, ptr %5, align 4
  %66 = insertvalue { ptr, i32 } poison, ptr %64, 0
  %67 = insertvalue { ptr, i32 } %66, i32 %65, 1
  resume { ptr, i32 } %67

68:                                               ; preds = %44
  %69 = landingpad { ptr, i32 }
          catch ptr null
  %70 = extractvalue { ptr, i32 } %69, 0
  call void @__clang_call_terminate(ptr %70) #10
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN15randomx_datasetC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7randomx14deallocDatasetINS_18LargePageAllocatorEEEvP15randomx_dataset(ptr noundef) #7

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7randomx14deallocDatasetINS_16AlignedAllocatorILm64EEEEEvP15randomx_dataset(ptr noundef) #7

; Function Attrs: mustprogress uwtable
declare dso_local void @randomx_release_dataset(ptr noundef) #7

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nobuiltin allocsize(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 memory(none) }
attributes #6 = { noinline noreturn nounwind uwtable "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 #7 = { 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 #8 = { nounwind }
attributes #9 = { builtin allocsize(0) }
attributes #10 = { noreturn 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 = !{!"_ZTS13randomx_flags", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTS15randomx_dataset", !10, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 0}


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

@_ZTISt9exception = external constant ptr

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Zan13randomx_flagsS_(i32 noundef, i32 noundef) local_unnamed_addr #2

declare noundef ptr @_ZN7randomx16AlignedAllocatorILm64EE11allocMemoryEm(i64 noundef) local_unnamed_addr #3

declare noundef ptr @_ZN7randomx18LargePageAllocator11allocMemoryEm(i64 noundef) local_unnamed_addr #3

; Function Attrs: nofree nosync nounwind memory(none)
declare i32 @llvm.eh.typeid.for.p0(ptr) #4

declare ptr @__cxa_begin_catch(ptr) local_unnamed_addr

declare void @__cxa_end_catch() local_unnamed_addr

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #5

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @randomx_alloc_dataset(i32 noundef %0) local_unnamed_addr #6 personality ptr @__gxx_personality_v0 {
  %2 = invoke noalias noundef nonnull dereferenceable(16) ptr @_Znwm(i64 noundef 16) #7
          to label %3 unwind label %8

3:                                                ; preds = %1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  tail call void @_ZN15randomx_datasetC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %2) #8
  %4 = tail call noundef i32 @_Zan13randomx_flagsS_(i32 noundef %0, i32 noundef 1)
  %.not = icmp eq i32 %4, 0
  %5 = getelementptr inbounds i8, ptr %2, i64 8
  br i1 %.not, label %17, label %6

6:                                                ; preds = %3
  store ptr @_ZN7randomx14deallocDatasetINS_18LargePageAllocatorEEEvP15randomx_dataset, ptr %5, align 8, !tbaa !5
  %7 = invoke noundef ptr @_ZN7randomx18LargePageAllocator11allocMemoryEm(i64 noundef 2181038016)
          to label %22 unwind label %8

8:                                                ; preds = %17, %6, %1
  %.0 = phi ptr [ %2, %6 ], [ %2, %17 ], [ null, %1 ]
  %9 = landingpad { ptr, i32 }
          cleanup
          catch ptr @_ZTISt9exception
  %10 = extractvalue { ptr, i32 } %9, 1
  %11 = tail call i32 @llvm.eh.typeid.for.p0(ptr nonnull @_ZTISt9exception) #8
  %12 = icmp eq i32 %10, %11
  br i1 %12, label %13, label %27

13:                                               ; preds = %8
  %14 = extractvalue { ptr, i32 } %9, 0
  %15 = tail call ptr @__cxa_begin_catch(ptr %14) #8
  %.not17 = icmp eq ptr %.0, null
  br i1 %.not17, label %21, label %16

16:                                               ; preds = %13
  invoke void @randomx_release_dataset(ptr noundef nonnull %.0)
          to label %21 unwind label %19

17:                                               ; preds = %3
  store ptr @_ZN7randomx14deallocDatasetINS_16AlignedAllocatorILm64EEEEEvP15randomx_dataset, ptr %5, align 8, !tbaa !5
  %18 = invoke noundef ptr @_ZN7randomx16AlignedAllocatorILm64EE11allocMemoryEm(i64 noundef 2181038016)
          to label %22 unwind label %8

19:                                               ; preds = %16
  %20 = landingpad { ptr, i32 }
          cleanup
  invoke void @__cxa_end_catch()
          to label %27 unwind label %28

21:                                               ; preds = %13, %16
  tail call void @__cxa_end_catch()
  br label %26

22:                                               ; preds = %17, %6
  %23 = phi ptr [ %7, %6 ], [ %18, %17 ]
  store ptr %23, ptr %2, align 8, !tbaa !10
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  tail call void @randomx_release_dataset(ptr noundef nonnull %2)
  br label %26

26:                                               ; preds = %21, %25, %22
  %.3 = phi ptr [ null, %25 ], [ %2, %22 ], [ null, %21 ]
  ret ptr %.3

27:                                               ; preds = %19, %8
  %.merged = phi { ptr, i32 } [ %9, %8 ], [ %20, %19 ]
  resume { ptr, i32 } %.merged

28:                                               ; preds = %19
  %29 = landingpad { ptr, i32 }
          catch ptr null
  %30 = extractvalue { ptr, i32 } %29, 0
  tail call void @__clang_call_terminate(ptr %30) #9
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN15randomx_datasetC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7randomx14deallocDatasetINS_18LargePageAllocatorEEEvP15randomx_dataset(ptr noundef) #6

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7randomx14deallocDatasetINS_16AlignedAllocatorILm64EEEEEvP15randomx_dataset(ptr noundef) #6

; Function Attrs: mustprogress uwtable
declare dso_local void @randomx_release_dataset(ptr noundef) local_unnamed_addr #6

attributes #0 = { nobuiltin allocsize(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 nocallback nofree nounwind willreturn memory(argmem: write) }
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" }
attributes #4 = { nofree nosync nounwind memory(none) }
attributes #5 = { noinline noreturn nounwind uwtable "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 #6 = { 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 #7 = { builtin allocsize(0) }
attributes #8 = { nounwind }
attributes #9 = { noreturn 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, !7, i64 8}
!6 = !{!"_ZTS15randomx_dataset", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass