; LLVM IR from tevador/RandomX :: src/tests (api-example1)

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

@__const.main.myKey = external hidden unnamed_addr constant [20 x i8], align 16
@__const.main.myInput = external hidden unnamed_addr constant [22 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [20 x i8], align 16
  %3 = alloca [22 x i8], align 16
  %4 = alloca [32 x i8], align 16
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 20, ptr %2) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %2, ptr align 16 @__const.main.myKey, i64 20, i1 false)
  call void @llvm.lifetime.start.p0(i64 22, ptr %3) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %3, ptr align 16 @__const.main.myInput, i64 22, i1 false)
  call void @llvm.lifetime.start.p0(i64 32, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %9 = call i32 @randomx_get_flags()
  store i32 %9, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = call ptr @randomx_alloc_cache(i32 noundef %10)
  store ptr %11, ptr %6, align 8, !tbaa !9
  %12 = load ptr, ptr %6, align 8, !tbaa !9
  call void @randomx_init_cache(ptr noundef %12, ptr noundef %2, i64 noundef 20)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !9
  %15 = call ptr @randomx_create_vm(i32 noundef %13, ptr noundef %14, ptr noundef null)
  store ptr %15, ptr %7, align 8, !tbaa !9
  %16 = load ptr, ptr %7, align 8, !tbaa !9
  %17 = getelementptr inbounds [32 x i8], ptr %4, i64 0, i64 0
  call void @randomx_calculate_hash(ptr noundef %16, ptr noundef %3, i64 noundef 22, ptr noundef %17)
  %18 = load ptr, ptr %7, align 8, !tbaa !9
  call void @randomx_destroy_vm(ptr noundef %18)
  %19 = load ptr, ptr %6, align 8, !tbaa !9
  call void @randomx_release_cache(ptr noundef %19)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %32, %0
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = icmp ult i32 %21, 32
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %35

24:                                               ; preds = %20
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds [32 x i8], ptr %4, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = sext i8 %28 to i32
  %30 = and i32 %29, 255
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %30)
  br label %32

32:                                               ; preds = %24
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = add i32 %33, 1
  store i32 %34, ptr %8, align 4, !tbaa !5
  br label %20, !llvm.loop !12

35:                                               ; preds = %23
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 22, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 20, ptr %2) #4
  ret i32 0
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare i32 @randomx_get_flags() #3

declare ptr @randomx_alloc_cache(i32 noundef) #3

declare void @randomx_init_cache(ptr noundef, ptr noundef, i64 noundef) #3

declare ptr @randomx_create_vm(i32 noundef, ptr noundef, ptr noundef) #3

declare void @randomx_calculate_hash(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #3

declare void @randomx_destroy_vm(ptr noundef) #3

declare void @randomx_release_cache(ptr noundef) #3

declare i32 @printf(ptr noundef, ...) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@__const.main.myKey = external hidden unnamed_addr constant [20 x i8], align 16
@__const.main.myInput = external hidden unnamed_addr constant [22 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [20 x i8], align 16
  %2 = alloca [22 x i8], align 16
  %3 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %1) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(20) %1, ptr noundef nonnull align 16 dereferenceable(20) @__const.main.myKey, i64 20, i1 false)
  call void @llvm.lifetime.start.p0(i64 22, ptr nonnull %2) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(22) %2, ptr noundef nonnull align 16 dereferenceable(22) @__const.main.myInput, i64 22, i1 false)
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #5
  %4 = tail call i32 @randomx_get_flags() #5
  %5 = tail call ptr @randomx_alloc_cache(i32 noundef %4) #5
  call void @randomx_init_cache(ptr noundef %5, ptr noundef nonnull %1, i64 noundef 20) #5
  %6 = call ptr @randomx_create_vm(i32 noundef %4, ptr noundef %5, ptr noundef null) #5
  call void @randomx_calculate_hash(ptr noundef %6, ptr noundef nonnull %2, i64 noundef 22, ptr noundef nonnull %3) #5
  call void @randomx_destroy_vm(ptr noundef %6) #5
  call void @randomx_release_cache(ptr noundef %5) #5
  %7 = load i8, ptr %3, align 16, !tbaa !5
  %8 = zext i8 %7 to i32
  %9 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %8)
  %10 = getelementptr inbounds i8, ptr %3, i64 1
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = zext i8 %11 to i32
  %13 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %12)
  %14 = getelementptr inbounds i8, ptr %3, i64 2
  %15 = load i8, ptr %14, align 2, !tbaa !5
  %16 = zext i8 %15 to i32
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %16)
  %18 = getelementptr inbounds i8, ptr %3, i64 3
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = zext i8 %19 to i32
  %21 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %20)
  %22 = getelementptr inbounds i8, ptr %3, i64 4
  %23 = load i8, ptr %22, align 4, !tbaa !5
  %24 = zext i8 %23 to i32
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %24)
  %26 = getelementptr inbounds i8, ptr %3, i64 5
  %27 = load i8, ptr %26, align 1, !tbaa !5
  %28 = zext i8 %27 to i32
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %28)
  %30 = getelementptr inbounds i8, ptr %3, i64 6
  %31 = load i8, ptr %30, align 2, !tbaa !5
  %32 = zext i8 %31 to i32
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %32)
  %34 = getelementptr inbounds i8, ptr %3, i64 7
  %35 = load i8, ptr %34, align 1, !tbaa !5
  %36 = zext i8 %35 to i32
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %36)
  %38 = getelementptr inbounds i8, ptr %3, i64 8
  %39 = load i8, ptr %38, align 8, !tbaa !5
  %40 = zext i8 %39 to i32
  %41 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %40)
  %42 = getelementptr inbounds i8, ptr %3, i64 9
  %43 = load i8, ptr %42, align 1, !tbaa !5
  %44 = zext i8 %43 to i32
  %45 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %44)
  %46 = getelementptr inbounds i8, ptr %3, i64 10
  %47 = load i8, ptr %46, align 2, !tbaa !5
  %48 = zext i8 %47 to i32
  %49 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %48)
  %50 = getelementptr inbounds i8, ptr %3, i64 11
  %51 = load i8, ptr %50, align 1, !tbaa !5
  %52 = zext i8 %51 to i32
  %53 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %52)
  %54 = getelementptr inbounds i8, ptr %3, i64 12
  %55 = load i8, ptr %54, align 4, !tbaa !5
  %56 = zext i8 %55 to i32
  %57 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %56)
  %58 = getelementptr inbounds i8, ptr %3, i64 13
  %59 = load i8, ptr %58, align 1, !tbaa !5
  %60 = zext i8 %59 to i32
  %61 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %60)
  %62 = getelementptr inbounds i8, ptr %3, i64 14
  %63 = load i8, ptr %62, align 2, !tbaa !5
  %64 = zext i8 %63 to i32
  %65 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %64)
  %66 = getelementptr inbounds i8, ptr %3, i64 15
  %67 = load i8, ptr %66, align 1, !tbaa !5
  %68 = zext i8 %67 to i32
  %69 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %68)
  %70 = getelementptr inbounds i8, ptr %3, i64 16
  %71 = load i8, ptr %70, align 16, !tbaa !5
  %72 = zext i8 %71 to i32
  %73 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %72)
  %74 = getelementptr inbounds i8, ptr %3, i64 17
  %75 = load i8, ptr %74, align 1, !tbaa !5
  %76 = zext i8 %75 to i32
  %77 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %76)
  %78 = getelementptr inbounds i8, ptr %3, i64 18
  %79 = load i8, ptr %78, align 2, !tbaa !5
  %80 = zext i8 %79 to i32
  %81 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %80)
  %82 = getelementptr inbounds i8, ptr %3, i64 19
  %83 = load i8, ptr %82, align 1, !tbaa !5
  %84 = zext i8 %83 to i32
  %85 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %84)
  %86 = getelementptr inbounds i8, ptr %3, i64 20
  %87 = load i8, ptr %86, align 4, !tbaa !5
  %88 = zext i8 %87 to i32
  %89 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %88)
  %90 = getelementptr inbounds i8, ptr %3, i64 21
  %91 = load i8, ptr %90, align 1, !tbaa !5
  %92 = zext i8 %91 to i32
  %93 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %92)
  %94 = getelementptr inbounds i8, ptr %3, i64 22
  %95 = load i8, ptr %94, align 2, !tbaa !5
  %96 = zext i8 %95 to i32
  %97 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %96)
  %98 = getelementptr inbounds i8, ptr %3, i64 23
  %99 = load i8, ptr %98, align 1, !tbaa !5
  %100 = zext i8 %99 to i32
  %101 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %100)
  %102 = getelementptr inbounds i8, ptr %3, i64 24
  %103 = load i8, ptr %102, align 8, !tbaa !5
  %104 = zext i8 %103 to i32
  %105 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %104)
  %106 = getelementptr inbounds i8, ptr %3, i64 25
  %107 = load i8, ptr %106, align 1, !tbaa !5
  %108 = zext i8 %107 to i32
  %109 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %108)
  %110 = getelementptr inbounds i8, ptr %3, i64 26
  %111 = load i8, ptr %110, align 2, !tbaa !5
  %112 = zext i8 %111 to i32
  %113 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %112)
  %114 = getelementptr inbounds i8, ptr %3, i64 27
  %115 = load i8, ptr %114, align 1, !tbaa !5
  %116 = zext i8 %115 to i32
  %117 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %116)
  %118 = getelementptr inbounds i8, ptr %3, i64 28
  %119 = load i8, ptr %118, align 4, !tbaa !5
  %120 = zext i8 %119 to i32
  %121 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %120)
  %122 = getelementptr inbounds i8, ptr %3, i64 29
  %123 = load i8, ptr %122, align 1, !tbaa !5
  %124 = zext i8 %123 to i32
  %125 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %124)
  %126 = getelementptr inbounds i8, ptr %3, i64 30
  %127 = load i8, ptr %126, align 2, !tbaa !5
  %128 = zext i8 %127 to i32
  %129 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %128)
  %130 = getelementptr inbounds i8, ptr %3, i64 31
  %131 = load i8, ptr %130, align 1, !tbaa !5
  %132 = zext i8 %131 to i32
  %133 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %132)
  %134 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 22, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %1) #5
  ret i32 0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare i32 @randomx_get_flags() local_unnamed_addr #3

declare ptr @randomx_alloc_cache(i32 noundef) local_unnamed_addr #3

declare void @randomx_init_cache(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

declare ptr @randomx_create_vm(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @randomx_calculate_hash(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

declare void @randomx_destroy_vm(ptr noundef) local_unnamed_addr #3

declare void @randomx_release_cache(ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 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 #5 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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