; 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_cache = type { ptr, ptr, ptr, ptr, ptr, [8 x %"class.randomx::SuperscalarProgram"], %"class.std::vector", %"class.std::__cxx11::basic_string", ptr }
%"class.randomx::SuperscalarProgram" = type { [512 x %"class.randomx::Instruction"], i32, i32, double, i32, i32, i32, i32, i32, i32, [8 x i32], [8 x i32] }
%"class.randomx::Instruction" = type { i8, i8, i8, i8, i32 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl_data" = type { ptr, ptr, 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] }
%struct.randomx_dataset = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@__PRETTY_FUNCTION__.randomx_init_dataset = external hidden unnamed_addr constant [92 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [62 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [42 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @randomx_init_dataset(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  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 i64 %3, ptr %8, align 8, !tbaa !9
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %4
  br label %14

12:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 188, ptr noundef @__PRETTY_FUNCTION__.randomx_init_dataset) #2
  unreachable

13:                                               ; No predecessors!
  br label %14

14:                                               ; preds = %13, %11
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  br label %20

18:                                               ; preds = %14
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 189, ptr noundef @__PRETTY_FUNCTION__.randomx_init_dataset) #2
  unreachable

19:                                               ; No predecessors!
  br label %20

20:                                               ; preds = %19, %17
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = icmp ult i64 %21, 34078719
  br i1 %22, label %23, label %26

23:                                               ; preds = %20
  %24 = load i64, ptr %8, align 8, !tbaa !9
  %25 = icmp ule i64 %24, 34078719
  br label %26

26:                                               ; preds = %23, %20
  %27 = phi i1 [ false, %20 ], [ %25, %23 ]
  br i1 %27, label %28, label %29

28:                                               ; preds = %26
  br label %31

29:                                               ; preds = %26
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 190, ptr noundef @__PRETTY_FUNCTION__.randomx_init_dataset) #2
  unreachable

30:                                               ; No predecessors!
  br label %31

31:                                               ; preds = %30, %28
  %32 = load i64, ptr %7, align 8, !tbaa !9
  %33 = load i64, ptr %8, align 8, !tbaa !9
  %34 = add i64 %32, %33
  %35 = icmp ule i64 %34, 34078719
  br i1 %35, label %36, label %37

36:                                               ; preds = %31
  br label %39

37:                                               ; preds = %31
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 191, ptr noundef @__PRETTY_FUNCTION__.randomx_init_dataset) #2
  unreachable

38:                                               ; No predecessors!
  br label %39

39:                                               ; preds = %38, %36
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.randomx_cache, ptr %40, i32 0, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.randomx_dataset, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !19
  %47 = load i64, ptr %7, align 8, !tbaa !9
  %48 = mul i64 %47, 64
  %49 = getelementptr inbounds i8, ptr %46, i64 %48
  %50 = load i64, ptr %7, align 8, !tbaa !9
  %51 = trunc i64 %50 to i32
  %52 = load i64, ptr %7, align 8, !tbaa !9
  %53 = load i64, ptr %8, align 8, !tbaa !9
  %54 = add i64 %52, %53
  %55 = trunc i64 %54 to i32
  call void %42(ptr noundef %43, ptr noundef %49, i32 noundef %51, i32 noundef %55)
  ret void
}

attributes #0 = { noreturn 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 #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 = { 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 = !{!"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, !6, i64 32}
!12 = !{!"_ZTS13randomx_cache", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40, !13, i64 33640, !17, i64 33664, !6, i64 33696}
!13 = !{!"_ZTSSt6vectorImSaImEE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseImSaImEE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseImSaImEE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseImSaImEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !18, i64 0, !10, i64 8, !7, i64 16}
!18 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!19 = !{!20, !6, i64 0}
!20 = !{!"_ZTS15randomx_dataset", !6, i64 0, !6, i64 8}


; 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
@.str.1 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@__PRETTY_FUNCTION__.randomx_init_dataset = external hidden unnamed_addr constant [92 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [62 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [42 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @randomx_init_dataset(ptr noundef readonly %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %5, label %6

5:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 188, ptr noundef nonnull @__PRETTY_FUNCTION__.randomx_init_dataset) #2
  unreachable

6:                                                ; preds = %4
  %.not16 = icmp eq ptr %1, null
  br i1 %.not16, label %7, label %8

7:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 189, ptr noundef nonnull @__PRETTY_FUNCTION__.randomx_init_dataset) #2
  unreachable

8:                                                ; preds = %6
  %9 = icmp ult i64 %2, 34078719
  %10 = icmp ult i64 %3, 34078720
  %11 = and i1 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 190, ptr noundef nonnull @__PRETTY_FUNCTION__.randomx_init_dataset) #2
  unreachable

13:                                               ; preds = %8
  %14 = add nuw nsw i64 %3, %2
  %15 = icmp ult i64 %14, 34078720
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 191, ptr noundef nonnull @__PRETTY_FUNCTION__.randomx_init_dataset) #2
  unreachable

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %1, i64 32
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = load ptr, ptr %0, align 8, !tbaa !17
  %21 = shl nuw nsw i64 %2, 6
  %22 = getelementptr inbounds i8, ptr %20, i64 %21
  %23 = trunc nuw nsw i64 %2 to i32
  %24 = trunc nuw nsw i64 %14 to i32
  tail call void %19(ptr noundef nonnull %1, ptr noundef %22, i32 noundef %23, i32 noundef %24)
  ret void
}

attributes #0 = { noreturn 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 #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 = { 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 32}
!6 = !{!"_ZTS13randomx_cache", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !8, i64 40, !10, i64 33640, !14, i64 33664, !7, i64 33696}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorImSaImEE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseImSaImEE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseImSaImEE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseImSaImEE17_Vector_impl_dataE", !7, i64 0, !7, i64 8, !7, i64 16}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !15, i64 0, !16, i64 8, !8, i64 16}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !7, i64 0}
!16 = !{!"long", !8, i64 0}
!17 = !{!18, !7, i64 0}
!18 = !{!"_ZTS15randomx_dataset", !7, i64 0, !7, i64 8}


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