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

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

@PrimeList = external hidden global [2048 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @cpMimimalPrimeTest(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = call i32 @cpFix_BNU32(ptr noundef %8, i32 noundef %9)
  store i32 %10, ptr %5, align 4, !tbaa !9
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = icmp eq i32 1, %11
  br i1 %12, label %13, label %32

13:                                               ; preds = %2
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %28, %13
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp slt i32 %15, 2048
  br i1 %16, label %17, label %31

17:                                               ; preds = %14
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds i32, ptr %18, i64 0
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2048 x i32], ptr @PrimeList, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = icmp eq i32 %20, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %17
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %51

27:                                               ; preds = %17
  br label %28

28:                                               ; preds = %27
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %6, align 4, !tbaa !9
  br label %14, !llvm.loop !11

31:                                               ; preds = %14
  br label %32

32:                                               ; preds = %31, %2
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %47, %32
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = icmp slt i32 %34, 2048
  br i1 %35, label %36, label %50

36:                                               ; preds = %33
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [2048 x i32], ptr @PrimeList, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = call i32 @cpMod32(ptr noundef %37, i32 noundef %38, i32 noundef %42)
  %44 = icmp eq i32 0, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %36
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %51

46:                                               ; preds = %36
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %6, align 4, !tbaa !9
  br label %33, !llvm.loop !13

50:                                               ; preds = %33
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %51

51:                                               ; preds = %50, %45, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %52 = load i32, ptr %3, align 4
  ret i32 %52
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cpFix_BNU32(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @cpMod32(ptr noundef, i32 noundef, i32 noundef) #0

; 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 = { 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 #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, !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@PrimeList = external hidden local_unnamed_addr global [2048 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @cpMimimalPrimeTest(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @cpFix_BNU32(ptr noundef %0, i32 noundef %1)
  %4 = icmp eq i32 %3, 1
  br i1 %4, label %.preheader, label %.loopexit13.preheader

.loopexit13.preheader:                            ; preds = %18, %2
  br label %.loopexit13

.preheader:                                       ; preds = %2
  %5 = load i32, ptr %0, align 4, !tbaa !5
  br label %19

6:                                                ; preds = %19
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %7 = getelementptr inbounds [2048 x i32], ptr @PrimeList, i64 0, i64 %indvars.iv.next
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = icmp eq i32 %5, %8
  br i1 %9, label %.loopexit, label %10

10:                                               ; preds = %6
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %11 = getelementptr inbounds [2048 x i32], ptr @PrimeList, i64 0, i64 %indvars.iv.next.1
  %12 = load i32, ptr %11, align 8, !tbaa !5
  %13 = icmp eq i32 %5, %12
  br i1 %13, label %.loopexit, label %14

14:                                               ; preds = %10
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %15 = getelementptr inbounds [2048 x i32], ptr @PrimeList, i64 0, i64 %indvars.iv.next.2
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = icmp eq i32 %5, %16
  br i1 %17, label %.loopexit, label %18

18:                                               ; preds = %14
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 2048
  br i1 %exitcond.not.3, label %.loopexit13.preheader, label %19, !llvm.loop !9

19:                                               ; preds = %18, %.preheader
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next.3, %18 ]
  %20 = getelementptr inbounds [2048 x i32], ptr @PrimeList, i64 0, i64 %indvars.iv
  %21 = load i32, ptr %20, align 16, !tbaa !5
  %22 = icmp eq i32 %5, %21
  br i1 %22, label %.loopexit, label %6

23:                                               ; preds = %.loopexit13
  %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
  %exitcond22.not = icmp eq i64 %indvars.iv.next20, 2048
  br i1 %exitcond22.not, label %.loopexit, label %.loopexit13, !llvm.loop !11

.loopexit13:                                      ; preds = %.loopexit13.preheader, %23
  %indvars.iv19 = phi i64 [ %indvars.iv.next20, %23 ], [ 0, %.loopexit13.preheader ]
  %24 = getelementptr inbounds [2048 x i32], ptr @PrimeList, i64 0, i64 %indvars.iv19
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = tail call i32 @cpMod32(ptr noundef %0, i32 noundef %3, i32 noundef %25)
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %.loopexit, label %23

.loopexit:                                        ; preds = %19, %6, %10, %14, %23, %.loopexit13
  %.012 = phi i32 [ 1, %23 ], [ 0, %.loopexit13 ], [ 1, %14 ], [ 1, %10 ], [ 1, %6 ], [ 1, %19 ]
  ret i32 %.012
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cpFix_BNU32(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @cpMod32(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass