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

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

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

11:                                               ; preds = %38, %4
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %14, label %41

14:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = zext i32 %16 to i64
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds i32, ptr %18, i32 1
  store ptr %19, ptr %6, align 8, !tbaa !5
  %20 = load i32, ptr %18, align 4, !tbaa !9
  %21 = zext i32 %20 to i64
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = mul i64 %21, %23
  %25 = sub i64 %17, %24
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = sub i64 %25, %27
  store i64 %28, ptr %10, align 8, !tbaa !11
  %29 = load i64, ptr %10, align 8, !tbaa !11
  %30 = trunc i64 %29 to i32
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds i32, ptr %31, i32 1
  store ptr %32, ptr %5, align 8, !tbaa !5
  store i32 %30, ptr %31, align 4, !tbaa !9
  %33 = load i64, ptr %10, align 8, !tbaa !11
  %34 = lshr i64 %33, 32
  %35 = and i64 %34, 4294967295
  %36 = trunc i64 %35 to i32
  %37 = sub i32 0, %36
  store i32 %37, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %38

38:                                               ; preds = %14
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = add nsw i32 %39, -1
  store i32 %40, ptr %7, align 4, !tbaa !9
  br label %11, !llvm.loop !13

41:                                               ; preds = %11
  %42 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret i32 %42
}

; 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 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 = { 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, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local i32 @cpSubMulDgt_BNU32(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %2, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %6 = zext i32 %3 to i64
  %xtraiter = and i32 %2, 1
  %7 = icmp eq i32 %2, 1
  br i1 %7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i32 %2, 2147483646
  br label %8

8:                                                ; preds = %8, %.lr.ph.new
  %.017 = phi ptr [ %0, %.lr.ph.new ], [ %32, %8 ]
  %.0916 = phi i32 [ 0, %.lr.ph.new ], [ %35, %8 ]
  %.01015 = phi ptr [ %1, %.lr.ph.new ], [ %24, %8 ]
  %niter = phi i32 [ 0, %.lr.ph.new ], [ %niter.next.1, %8 ]
  %9 = load i32, ptr %.017, align 4, !tbaa !5
  %10 = zext i32 %9 to i64
  %11 = getelementptr inbounds i8, ptr %.01015, i64 4
  %12 = load i32, ptr %.01015, align 4, !tbaa !5
  %13 = zext i32 %12 to i64
  %14 = mul nuw i64 %6, %13
  %15 = zext i32 %.0916 to i64
  %16 = add nuw i64 %14, %15
  %17 = sub i64 %10, %16
  %18 = trunc i64 %17 to i32
  %19 = getelementptr inbounds i8, ptr %.017, i64 4
  store i32 %18, ptr %.017, align 4, !tbaa !5
  %20 = lshr i64 %17, 32
  %21 = sub nsw i64 0, %20
  %22 = load i32, ptr %19, align 4, !tbaa !5
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %.01015, i64 8
  %25 = load i32, ptr %11, align 4, !tbaa !5
  %26 = zext i32 %25 to i64
  %27 = mul nuw i64 %6, %26
  %28 = and i64 %21, 4294967295
  %29 = add nuw i64 %27, %28
  %30 = sub i64 %23, %29
  %31 = trunc i64 %30 to i32
  %32 = getelementptr inbounds i8, ptr %.017, i64 8
  store i32 %31, ptr %19, align 4, !tbaa !5
  %33 = lshr i64 %30, 32
  %34 = trunc nuw i64 %33 to i32
  %35 = sub i32 0, %34
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1.not = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1.not, label %._crit_edge.loopexit.unr-lcssa.loopexit, label %8, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa.loopexit:          ; preds = %8
  %36 = zext i32 %35 to i64
  br label %._crit_edge.loopexit.unr-lcssa

._crit_edge.loopexit.unr-lcssa:                   ; preds = %._crit_edge.loopexit.unr-lcssa.loopexit, %.lr.ph
  %.lcssa.ph = phi i32 [ poison, %.lr.ph ], [ %35, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.017.unr = phi ptr [ %0, %.lr.ph ], [ %32, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.0916.unr = phi i64 [ 0, %.lr.ph ], [ %36, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.01015.unr = phi ptr [ %1, %.lr.ph ], [ %24, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %37 = load i32, ptr %.017.unr, align 4, !tbaa !5
  %38 = zext i32 %37 to i64
  %39 = load i32, ptr %.01015.unr, align 4, !tbaa !5
  %40 = zext i32 %39 to i64
  %41 = mul nuw i64 %6, %40
  %42 = add nuw i64 %41, %.0916.unr
  %43 = sub i64 %38, %42
  %44 = trunc i64 %43 to i32
  store i32 %44, ptr %.017.unr, align 4, !tbaa !5
  %45 = lshr i64 %43, 32
  %46 = trunc nuw i64 %45 to i32
  %47 = sub i32 0, %46
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %4
  %.09.lcssa = phi i32 [ 0, %4 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %47, %._crit_edge.loopexit.epilog-lcssa ]
  ret i32 %.09.lcssa
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass