; LLVM IR from intel/cryptography-primitives :: sources/ippcp (pcpprimetest_bn)

; 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._cpPrime = type { i32, i32, ptr, ptr, ptr, ptr, ptr }
%struct._cpBigNum = type { i32, i32, i32, i32, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @ippsPrimeTest_BN(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #0 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = icmp eq ptr null, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %6
  store i32 -8, ptr %7, align 4
  br label %81

21:                                               ; preds = %6
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = icmp eq ptr null, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  store i32 -8, ptr %7, align 4
  br label %81

25:                                               ; preds = %21
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = icmp eq ptr null, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %25
  store i32 -8, ptr %7, align 4
  br label %81

29:                                               ; preds = %25
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = icmp eq ptr null, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  store i32 -8, ptr %7, align 4
  br label %81

33:                                               ; preds = %29
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = icmp slt i32 %34, 1
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  store i32 -5, ptr %7, align 4
  br label %81

37:                                               ; preds = %33
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._cpPrime, ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 8, !tbaa !11
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = call i64 @IPP_UINT_PTR(ptr noundef %41)
  %43 = trunc i64 %42 to i32
  %44 = xor i32 %40, %43
  %45 = icmp eq i32 %44, 1347569997
  br i1 %45, label %47, label %46

46:                                               ; preds = %37
  store i32 -13, ptr %7, align 4
  br label %81

47:                                               ; preds = %37
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._cpBigNum, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !13
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = call i64 @IPP_UINT_PTR(ptr noundef %51)
  %53 = trunc i64 %52 to i32
  %54 = xor i32 %50, %53
  %55 = icmp eq i32 %54, 1112098638
  br i1 %55, label %57, label %56

56:                                               ; preds = %47
  store i32 -13, ptr %7, align 4
  br label %81

57:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._cpBigNum, ptr %58, i32 0, i32 4
  %60 = load ptr, ptr %59, align 8, !tbaa !15
  store ptr %60, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._cpBigNum, ptr %61, i32 0, i32 2
  %63 = load i32, ptr %62, align 8, !tbaa !16
  store i32 %63, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %64 = load ptr, ptr %14, align 8, !tbaa !5
  %65 = load i32, ptr %15, align 4, !tbaa !9
  %66 = load i32, ptr %9, align 4, !tbaa !9
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = load ptr, ptr %12, align 8, !tbaa !5
  %69 = load ptr, ptr %13, align 8, !tbaa !5
  %70 = call i32 @cpPrimeTest(ptr noundef %64, i32 noundef %65, i32 noundef %66, ptr noundef %67, ptr noundef %68, ptr noundef %69)
  store i32 %70, ptr %16, align 4, !tbaa !9
  %71 = load i32, ptr %16, align 4, !tbaa !9
  %72 = icmp eq i32 -1, %71
  br i1 %72, label %73, label %74

73:                                               ; preds = %57
  store i32 -2, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %80

74:                                               ; preds = %57
  %75 = load i32, ptr %16, align 4, !tbaa !9
  %76 = icmp ne i32 %75, 0
  %77 = zext i1 %76 to i64
  %78 = select i1 %76, i32 5, i32 6
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 %78, ptr %79, align 4, !tbaa !9
  store i32 0, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %80

80:                                               ; preds = %74, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %81

81:                                               ; preds = %80, %56, %46, %36, %32, %28, %24, %20
  %82 = load i32, ptr %7, align 4
  ret i32 %82
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @IPP_UINT_PTR(ptr noundef) #1

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

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

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

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 = { inlinehint 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 = { nocallback nofree nosync 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_cpPrime", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!13 = !{!14, !10, i64 0}
!14 = !{!"_cpBigNum", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24}
!15 = !{!14, !6, i64 16}
!16 = !{!14, !10, 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"

; Function Attrs: nounwind uwtable
define dso_local range(i32 -13, 1) i32 @ippsPrimeTest_BN(ptr noundef %0, i32 noundef %1, ptr noundef writeonly %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %7 = insertelement <4 x ptr> poison, ptr %0, i64 0
  %8 = insertelement <4 x ptr> %7, ptr %2, i64 1
  %9 = insertelement <4 x ptr> %8, ptr %3, i64 2
  %10 = insertelement <4 x ptr> %9, ptr %4, i64 3
  %11 = icmp eq <4 x ptr> %10, zeroinitializer
  %12 = bitcast <4 x i1> %11 to i4
  %.not28 = icmp eq i4 %12, 0
  br i1 %.not28, label %13, label %36

13:                                               ; preds = %6
  %14 = icmp slt i32 %1, 1
  br i1 %14, label %36, label %15

15:                                               ; preds = %13
  %16 = load i32, ptr %3, align 8, !tbaa !5
  %17 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %3)
  %18 = trunc i64 %17 to i32
  %19 = xor i32 %16, %18
  %20 = icmp eq i32 %19, 1347569997
  br i1 %20, label %21, label %36

21:                                               ; preds = %15
  %22 = load i32, ptr %0, align 8, !tbaa !11
  %23 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %0)
  %24 = trunc i64 %23 to i32
  %25 = xor i32 %22, %24
  %26 = icmp eq i32 %25, 1112098638
  br i1 %26, label %27, label %36

27:                                               ; preds = %21
  %28 = getelementptr inbounds i8, ptr %0, i64 16
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = getelementptr inbounds i8, ptr %0, i64 8
  %31 = load i32, ptr %30, align 8, !tbaa !14
  %32 = tail call i32 @cpPrimeTest(ptr noundef %29, i32 noundef %31, i32 noundef %1, ptr noundef nonnull %3, ptr noundef nonnull %4, ptr noundef %5) #3
  %33 = icmp eq i32 %32, -1
  br i1 %33, label %36, label %34

34:                                               ; preds = %27
  %.not = icmp eq i32 %32, 0
  %35 = select i1 %.not, i32 6, i32 5
  store i32 %35, ptr %2, align 4, !tbaa !15
  br label %36

36:                                               ; preds = %34, %27, %21, %15, %13, %6
  %.1 = phi i32 [ -8, %6 ], [ -5, %13 ], [ -13, %15 ], [ -13, %21 ], [ 0, %34 ], [ -2, %27 ]
  ret i32 %.1
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @IPP_UINT_PTR(ptr noundef) local_unnamed_addr #1

declare i32 @cpPrimeTest(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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 = { inlinehint 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 = { "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 = { 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 0}
!6 = !{!"_cpPrime", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"_cpBigNum", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !10, i64 24}
!13 = !{!12, !10, i64 16}
!14 = !{!12, !7, i64 8}
!15 = !{!7, !7, i64 0}


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