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

; 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._cpMontgomery = type { i32, i32, ptr }
%struct._gsModEngine = type { ptr, i32, i32, i32, i32, i32, ptr, ptr, ptr, i64, ptr, ptr, ptr, ptr, i32, i32, ptr }

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

13:                                               ; preds = %3
  store i32 -8, ptr %4, align 4
  br label %67

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = icmp eq ptr null, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  store i32 -8, ptr %4, align 4
  br label %67

18:                                               ; preds = %14
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = icmp eq ptr null, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  store i32 -8, ptr %4, align 4
  br label %67

22:                                               ; preds = %18
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._cpMontgomery, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !9
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = call i64 @IPP_UINT_PTR(ptr noundef %26)
  %28 = trunc i64 %27 to i32
  %29 = xor i32 %25, %28
  %30 = icmp eq i32 %29, 1297043028
  br i1 %30, label %32, label %31

31:                                               ; preds = %22
  store i32 -13, ptr %4, align 4
  br label %67

32:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._cpMontgomery, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !12
  %36 = getelementptr inbounds %struct._gsModEngine, ptr %35, i32 0, i32 3
  %37 = load i32, ptr %36, align 8, !tbaa !13
  %38 = mul nsw i32 %37, 2
  store i32 %38, ptr %8, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._cpMontgomery, ptr %39, i32 0, i32 2
  %41 = load ptr, ptr %40, align 8, !tbaa !12
  %42 = getelementptr inbounds %struct._gsModEngine, ptr %41, i32 0, i32 8
  %43 = load ptr, ptr %42, align 8, !tbaa !17
  store ptr %43, ptr %9, align 8, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !16
  %46 = call i32 @cpFix_BNU32(ptr noundef %44, i32 noundef %45)
  store i32 %46, ptr %8, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !16
  br label %47

47:                                               ; preds = %61, %32
  %48 = load i32, ptr %10, align 4, !tbaa !16
  %49 = load i32, ptr %8, align 4, !tbaa !16
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %51, label %64

51:                                               ; preds = %47
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = load i32, ptr %10, align 4, !tbaa !16
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i32, ptr %52, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !16
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load i32, ptr %10, align 4, !tbaa !16
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i32, ptr %57, i64 %59
  store i32 %56, ptr %60, align 4, !tbaa !16
  br label %61

61:                                               ; preds = %51
  %62 = load i32, ptr %10, align 4, !tbaa !16
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %10, align 4, !tbaa !16
  br label %47, !llvm.loop !18

64:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %65 = load i32, ptr %8, align 4, !tbaa !16
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %65, ptr %66, align 4, !tbaa !16
  store i32 0, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %67

67:                                               ; preds = %64, %31, %21, %17, %13
  %68 = load i32, ptr %4, align 4
  ret i32 %68
}

; 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

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

; 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 = { 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, !11, i64 0}
!10 = !{!"_cpMontgomery", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!14, !11, i64 16}
!14 = !{!"_gsModEngine", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !15, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !11, i64 96, !11, i64 100, !6, i64 104}
!15 = !{!"long long", !7, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!14, !6, i64 48}
!18 = distinct !{!18, !19}
!19 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local range(i32 -13, 1) i32 @ippsMontGet(ptr noundef writeonly %0, ptr noundef writeonly %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = ptrtoint ptr %0 to i64
  %5 = icmp eq ptr %2, null
  %6 = icmp eq ptr %0, null
  %or.cond = or i1 %6, %5
  %7 = icmp eq ptr %1, null
  %or.cond23 = or i1 %7, %or.cond
  br i1 %or.cond23, label %48, label %8

8:                                                ; preds = %3
  %9 = load i32, ptr %2, align 8, !tbaa !5
  %10 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %2)
  %11 = trunc i64 %10 to i32
  %12 = xor i32 %9, %11
  %13 = icmp eq i32 %12, 1297043028
  br i1 %13, label %14, label %48

14:                                               ; preds = %8
  %15 = getelementptr inbounds i8, ptr %2, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  %18 = load i32, ptr %17, align 8, !tbaa !12
  %19 = shl nsw i32 %18, 1
  %20 = getelementptr inbounds i8, ptr %16, i64 48
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = tail call i32 @cpFix_BNU32(ptr noundef %21, i32 noundef %19)
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %14
  %24 = ptrtoint ptr %21 to i64
  %wide.trip.count = zext nneg i32 %22 to i64
  %min.iters.check = icmp ult i32 %22, 8
  %25 = sub i64 %4, %24
  %diff.check = icmp ult i64 %25, 32
  %or.cond27 = or i1 %min.iters.check, %diff.check
  br i1 %or.cond27, label %.lr.ph.preheader28, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count, 2147483640
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %26 = getelementptr inbounds i32, ptr %21, i64 %index
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  %wide.load = load <4 x i32>, ptr %26, align 4, !tbaa !16
  %wide.load26 = load <4 x i32>, ptr %27, align 4, !tbaa !16
  %28 = getelementptr inbounds i32, ptr %0, i64 %index
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  store <4 x i32> %wide.load, ptr %28, align 4, !tbaa !16
  store <4 x i32> %wide.load26, ptr %29, align 4, !tbaa !16
  %index.next = add nuw i64 %index, 8
  %30 = icmp eq i64 %index.next, %n.vec
  br i1 %30, label %middle.block, label %vector.body, !llvm.loop !17

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader28

.lr.ph.preheader28:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %wide.trip.count, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader28, %.lr.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.lr.ph.prol ], [ %indvars.iv.ph, %.lr.ph.preheader28 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader28 ]
  %31 = getelementptr inbounds i32, ptr %21, i64 %indvars.iv.prol
  %32 = load i32, ptr %31, align 4, !tbaa !16
  %33 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.prol
  store i32 %32, ptr %33, align 4, !tbaa !16
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !21

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader28
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %.lr.ph.preheader28 ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %34 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %35 = icmp ugt i64 %34, -4
  br i1 %35, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.lr.ph ], [ %indvars.iv.unr, %.lr.ph.prol.loopexit ]
  %36 = getelementptr inbounds i32, ptr %21, i64 %indvars.iv
  %37 = load i32, ptr %36, align 4, !tbaa !16
  %38 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  store i32 %37, ptr %38, align 4, !tbaa !16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %39 = getelementptr inbounds i32, ptr %21, i64 %indvars.iv.next
  %40 = load i32, ptr %39, align 4, !tbaa !16
  %41 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next
  store i32 %40, ptr %41, align 4, !tbaa !16
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %42 = getelementptr inbounds i32, ptr %21, i64 %indvars.iv.next.1
  %43 = load i32, ptr %42, align 4, !tbaa !16
  %44 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next.1
  store i32 %43, ptr %44, align 4, !tbaa !16
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %45 = getelementptr inbounds i32, ptr %21, i64 %indvars.iv.next.2
  %46 = load i32, ptr %45, align 4, !tbaa !16
  %47 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next.2
  store i32 %46, ptr %47, align 4, !tbaa !16
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge, label %.lr.ph, !llvm.loop !23

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %14
  store i32 %22, ptr %1, align 4, !tbaa !16
  br label %48

48:                                               ; preds = %8, %3, %._crit_edge
  %.018 = phi i32 [ 0, %._crit_edge ], [ -8, %3 ], [ -13, %8 ]
  ret i32 %.018
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cpFix_BNU32(ptr noundef, i32 noundef) local_unnamed_addr #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 = { 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, !7, i64 0}
!6 = !{!"_cpMontgomery", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!13, !7, i64 16}
!13 = !{!"_gsModEngine", !10, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !14, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !7, i64 96, !7, i64 100, !10, i64 104}
!14 = !{!"long long", !8, i64 0}
!15 = !{!13, !10, i64 48}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18, !19, !20}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!"llvm.loop.isvectorized", i32 1}
!20 = !{!"llvm.loop.unroll.runtime.disable"}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.unroll.disable"}
!23 = distinct !{!23, !18, !19}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass