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

; 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 @ippsExtGet_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 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
  %12 = load ptr, ptr %9, align 8, !tbaa !5
  %13 = icmp eq ptr null, %12
  br i1 %13, label %14, label %15

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

15:                                               ; preds = %4
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._cpBigNum, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = call i64 @IPP_UINT_PTR(ptr noundef %19)
  %21 = trunc i64 %20 to i32
  %22 = xor i32 %18, %21
  %23 = icmp eq i32 %22, 1112098638
  br i1 %23, label %25, label %24

24:                                               ; preds = %15
  store i32 -13, ptr %5, align 4
  br label %86

25:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._cpBigNum, ptr %26, i32 0, i32 2
  %28 = load i32, ptr %27, align 8, !tbaa !12
  %29 = mul nsw i32 %28, 64
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._cpBigNum, ptr %30, i32 0, i32 4
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._cpBigNum, ptr %33, i32 0, i32 2
  %35 = load i32, ptr %34, align 8, !tbaa !12
  %36 = sub nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i64, ptr %32, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !14
  %40 = call i32 @cpNLZ_BNU(i64 noundef %39)
  %41 = sub nsw i32 %29, %40
  store i32 %41, ptr %10, align 4, !tbaa !16
  %42 = load i32, ptr %10, align 4, !tbaa !16
  %43 = icmp eq i32 0, %42
  br i1 %43, label %44, label %45

44:                                               ; preds = %25
  store i32 1, ptr %10, align 4, !tbaa !16
  br label %45

45:                                               ; preds = %44, %25
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %71

48:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !16
  br label %49

49:                                               ; preds = %67, %48
  %50 = load i32, ptr %11, align 4, !tbaa !16
  %51 = load i32, ptr %10, align 4, !tbaa !16
  %52 = add nsw i32 %51, 31
  %53 = ashr i32 %52, 5
  %54 = icmp slt i32 %50, %53
  br i1 %54, label %55, label %70

55:                                               ; preds = %49
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._cpBigNum, ptr %56, i32 0, i32 4
  %58 = load ptr, ptr %57, align 8, !tbaa !13
  %59 = load i32, ptr %11, align 4, !tbaa !16
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i32, ptr %58, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !16
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load i32, ptr %11, align 4, !tbaa !16
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i32, ptr %63, i64 %65
  store i32 %62, ptr %66, align 4, !tbaa !16
  br label %67

67:                                               ; preds = %55
  %68 = load i32, ptr %11, align 4, !tbaa !16
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %11, align 4, !tbaa !16
  br label %49, !llvm.loop !17

70:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %71

71:                                               ; preds = %70, %45
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = icmp ne ptr %72, null
  br i1 %73, label %74, label %79

74:                                               ; preds = %71
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._cpBigNum, ptr %75, i32 0, i32 1
  %77 = load i32, ptr %76, align 4, !tbaa !19
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %77, ptr %78, align 4, !tbaa !16
  br label %79

79:                                               ; preds = %74, %71
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = icmp ne ptr %80, null
  br i1 %81, label %82, label %85

82:                                               ; preds = %79
  %83 = load i32, ptr %10, align 4, !tbaa !16
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %83, ptr %84, align 4, !tbaa !16
  br label %85

85:                                               ; preds = %82, %79
  store i32 0, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %86

86:                                               ; preds = %85, %24, %14
  %87 = load i32, ptr %5, align 4
  ret i32 %87
}

; 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 @cpNLZ_BNU(i64 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, !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 = !{!10, !6, i64 16}
!14 = !{!15, !15, i64 0}
!15 = !{!"long long", !7, i64 0}
!16 = !{!11, !11, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!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 @ippsExtGet_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 = icmp eq ptr %3, null
  br i1 %6, label %59, label %7

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

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %3, i64 8
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = shl nsw i32 %15, 6
  %17 = getelementptr inbounds i8, ptr %3, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = sext i32 %15 to i64
  %20 = getelementptr i64, ptr %18, i64 %19
  %21 = getelementptr i8, ptr %20, i64 -8
  %22 = load i64, ptr %21, align 8, !tbaa !13
  %23 = tail call i32 @cpNLZ_BNU(i64 noundef %22) #3
  %24 = sub nsw i32 %16, %23
  %25 = icmp eq i32 %16, %23
  %spec.store.select = select i1 %25, i32 1, i32 %24
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %13
  %26 = add nsw i32 %spec.store.select, 31
  %27 = ashr i32 %26, 5
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %29 = load ptr, ptr %17, align 8, !tbaa !12
  %wide.trip.count = zext nneg i32 %27 to i64
  %min.iters.check = icmp ult i32 %27, 8
  %30 = ptrtoint ptr %29 to i64
  %31 = sub i64 %5, %30
  %diff.check = icmp ult i64 %31, 32
  %or.cond = select i1 %min.iters.check, i1 true, i1 %diff.check
  br i1 %or.cond, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph
  %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 ]
  %32 = getelementptr inbounds i32, ptr %29, i64 %index
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  %wide.load = load <4 x i32>, ptr %32, align 4, !tbaa !15
  %wide.load30 = load <4 x i32>, ptr %33, align 4, !tbaa !15
  %34 = getelementptr inbounds i32, ptr %2, i64 %index
  %35 = getelementptr inbounds i8, ptr %34, i64 16
  store <4 x i32> %wide.load, ptr %34, align 4, !tbaa !15
  store <4 x i32> %wide.load30, ptr %35, align 4, !tbaa !15
  %index.next = add nuw i64 %index, 8
  %36 = icmp eq i64 %index.next, %n.vec
  br i1 %36, label %middle.block, label %vector.body, !llvm.loop !16

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

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph ], [ %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 %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %37 = getelementptr inbounds i32, ptr %29, i64 %indvars.iv.prol
  %38 = load i32, ptr %37, align 4, !tbaa !15
  %39 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv.prol
  store i32 %38, ptr %39, align 4, !tbaa !15
  %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 %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !20

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %40 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %41 = icmp ugt i64 %40, -4
  br i1 %41, label %.loopexit, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %42 = getelementptr inbounds i32, ptr %29, i64 %indvars.iv
  %43 = load i32, ptr %42, align 4, !tbaa !15
  %44 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv
  store i32 %43, ptr %44, align 4, !tbaa !15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %45 = getelementptr inbounds i32, ptr %29, i64 %indvars.iv.next
  %46 = load i32, ptr %45, align 4, !tbaa !15
  %47 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv.next
  store i32 %46, ptr %47, align 4, !tbaa !15
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %48 = getelementptr inbounds i32, ptr %29, i64 %indvars.iv.next.1
  %49 = load i32, ptr %48, align 4, !tbaa !15
  %50 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv.next.1
  store i32 %49, ptr %50, align 4, !tbaa !15
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %51 = getelementptr inbounds i32, ptr %29, i64 %indvars.iv.next.2
  %52 = load i32, ptr %51, align 4, !tbaa !15
  %53 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv.next.2
  store i32 %52, ptr %53, align 4, !tbaa !15
  %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 %.loopexit, label %scalar.ph, !llvm.loop !22

.loopexit:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %.preheader, %13
  %.not26 = icmp eq ptr %0, null
  br i1 %.not26, label %57, label %54

54:                                               ; preds = %.loopexit
  %55 = getelementptr inbounds i8, ptr %3, i64 4
  %56 = load i32, ptr %55, align 4, !tbaa !23
  store i32 %56, ptr %0, align 4, !tbaa !15
  br label %57

57:                                               ; preds = %54, %.loopexit
  %.not27 = icmp eq ptr %1, null
  br i1 %.not27, label %59, label %58

58:                                               ; preds = %57
  store i32 %spec.store.select, ptr %1, align 4, !tbaa !15
  br label %59

59:                                               ; preds = %57, %58, %7, %4
  %.021 = phi i32 [ -8, %4 ], [ -13, %7 ], [ 0, %58 ], [ 0, %57 ]
  ret i32 %.021
}

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

declare i32 @cpNLZ_BNU(i64 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 = !{!"_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 = !{!14, !14, i64 0}
!14 = !{!"long long", !8, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17, !18, !19}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.isvectorized", i32 1}
!19 = !{!"llvm.loop.unroll.runtime.disable"}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.unroll.disable"}
!22 = distinct !{!22, !17, !18}
!23 = !{!6, !7, i64 4}


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