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

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

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

15:                                               ; preds = %4
  store i32 -8, ptr %5, align 4
  br label %73

16:                                               ; preds = %4
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp eq ptr null, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  store i32 -8, ptr %5, align 4
  br label %73

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

23:                                               ; preds = %20
  store i32 -8, ptr %5, align 4
  br label %73

24:                                               ; preds = %20
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = icmp eq ptr null, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %24
  store i32 -8, ptr %5, align 4
  br label %73

28:                                               ; preds = %24
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._cpBigNum, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !9
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = call i64 @IPP_UINT_PTR(ptr noundef %32)
  %34 = trunc i64 %33 to i32
  %35 = xor i32 %31, %34
  %36 = icmp eq i32 %35, 1112098638
  br i1 %36, label %38, label %37

37:                                               ; preds = %28
  store i32 -13, ptr %5, align 4
  br label %73

38:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._cpBigNum, ptr %39, i32 0, i32 2
  %41 = load i32, ptr %40, align 8, !tbaa !12
  %42 = mul nsw i32 %41, 2
  store i32 %42, ptr %10, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._cpBigNum, ptr %43, i32 0, i32 4
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  store ptr %45, ptr %11, align 8, !tbaa !5
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = load i32, ptr %10, align 4, !tbaa !13
  %48 = call i32 @cpFix_BNU32(ptr noundef %46, i32 noundef %47)
  store i32 %48, ptr %10, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !13
  br label %49

49:                                               ; preds = %63, %38
  %50 = load i32, ptr %12, align 4, !tbaa !13
  %51 = load i32, ptr %10, align 4, !tbaa !13
  %52 = icmp slt i32 %50, %51
  br i1 %52, label %53, label %66

53:                                               ; preds = %49
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = load i32, ptr %12, align 4, !tbaa !13
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i32, ptr %54, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !13
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = load i32, ptr %12, align 4, !tbaa !13
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i32, ptr %59, i64 %61
  store i32 %58, ptr %62, align 4, !tbaa !13
  br label %63

63:                                               ; preds = %53
  %64 = load i32, ptr %12, align 4, !tbaa !13
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %12, align 4, !tbaa !13
  br label %49, !llvm.loop !15

66:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._cpBigNum, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %68, align 4, !tbaa !17
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %69, ptr %70, align 4, !tbaa !13
  %71 = load i32, ptr %10, align 4, !tbaa !13
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %71, ptr %72, align 4, !tbaa !13
  store i32 0, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %73

73:                                               ; preds = %66, %37, %27, %23, %19, %15
  %74 = load i32, ptr %5, align 4
  ret i32 %74
}

; 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 = !{!"_cpBigNum", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!10, !11, i64 4}


; 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 @ippsGet_BN(ptr noundef writeonly %0, ptr noundef writeonly %1, ptr noundef writeonly %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = ptrtoint ptr %2 to i64
  %6 = insertelement <4 x ptr> poison, ptr %0, i64 0
  %7 = insertelement <4 x ptr> %6, ptr %1, i64 1
  %8 = insertelement <4 x ptr> %7, ptr %2, i64 2
  %9 = insertelement <4 x ptr> %8, ptr %3, i64 3
  %10 = icmp eq <4 x ptr> %9, zeroinitializer
  %11 = bitcast <4 x i1> %10 to i4
  %.not = icmp eq i4 %11, 0
  br i1 %.not, label %12, label %52

12:                                               ; preds = %4
  %13 = load i32, ptr %3, align 8, !tbaa !5
  %14 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %3)
  %15 = trunc i64 %14 to i32
  %16 = xor i32 %13, %15
  %17 = icmp eq i32 %16, 1112098638
  br i1 %17, label %18, label %52

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

.lr.ph.preheader:                                 ; preds = %18
  %26 = ptrtoint ptr %23 to i64
  %wide.trip.count = zext nneg i32 %24 to i64
  %min.iters.check = icmp ult i32 %24, 8
  %27 = sub i64 %5, %26
  %diff.check = icmp ult i64 %27, 32
  %or.cond32 = or i1 %min.iters.check, %diff.check
  br i1 %or.cond32, label %.lr.ph.preheader33, 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 ]
  %28 = getelementptr inbounds i32, ptr %23, i64 %index
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  %wide.load = load <4 x i32>, ptr %28, align 4, !tbaa !13
  %wide.load31 = load <4 x i32>, ptr %29, align 4, !tbaa !13
  %30 = getelementptr inbounds i32, ptr %2, i64 %index
  %31 = getelementptr inbounds i8, ptr %30, i64 16
  store <4 x i32> %wide.load, ptr %30, align 4, !tbaa !13
  store <4 x i32> %wide.load31, ptr %31, align 4, !tbaa !13
  %index.next = add nuw i64 %index, 8
  %32 = icmp eq i64 %index.next, %n.vec
  br i1 %32, label %middle.block, label %vector.body, !llvm.loop !14

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.preheader33

.lr.ph.preheader33:                               ; 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.preheader33, %.lr.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.lr.ph.prol ], [ %indvars.iv.ph, %.lr.ph.preheader33 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader33 ]
  %33 = getelementptr inbounds i32, ptr %23, i64 %indvars.iv.prol
  %34 = load i32, ptr %33, align 4, !tbaa !13
  %35 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv.prol
  store i32 %34, ptr %35, align 4, !tbaa !13
  %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 !18

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader33
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %.lr.ph.preheader33 ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %36 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %37 = icmp ugt i64 %36, -4
  br i1 %37, 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 ]
  %38 = getelementptr inbounds i32, ptr %23, i64 %indvars.iv
  %39 = load i32, ptr %38, align 4, !tbaa !13
  %40 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv
  store i32 %39, ptr %40, align 4, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %41 = getelementptr inbounds i32, ptr %23, i64 %indvars.iv.next
  %42 = load i32, ptr %41, align 4, !tbaa !13
  %43 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv.next
  store i32 %42, ptr %43, align 4, !tbaa !13
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %44 = getelementptr inbounds i32, ptr %23, i64 %indvars.iv.next.1
  %45 = load i32, ptr %44, align 4, !tbaa !13
  %46 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv.next.1
  store i32 %45, ptr %46, align 4, !tbaa !13
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %47 = getelementptr inbounds i32, ptr %23, i64 %indvars.iv.next.2
  %48 = load i32, ptr %47, align 4, !tbaa !13
  %49 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv.next.2
  store i32 %48, ptr %49, align 4, !tbaa !13
  %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 !20

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %18
  %50 = getelementptr inbounds i8, ptr %3, i64 4
  %51 = load i32, ptr %50, align 4, !tbaa !21
  store i32 %51, ptr %0, align 4, !tbaa !13
  store i32 %24, ptr %1, align 4, !tbaa !13
  br label %52

52:                                               ; preds = %12, %4, %._crit_edge
  %.021 = phi i32 [ 0, %._crit_edge ], [ -8, %4 ], [ -13, %12 ]
  ret i32 %.021
}

; 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 = !{!"_cpBigNum", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !10, i64 16}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}
!20 = distinct !{!20, !15, !16}
!21 = !{!6, !7, i64 4}


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