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

; 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._cpPRNG = type { i32, i32, [3 x i64], [3 x i64], [8 x i64], [8 x i64] }
%struct._cpBigNum = type { i32, i32, i32, i32, ptr, ptr }

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

9:                                                ; preds = %2
  store i32 -8, ptr %3, align 4
  br label %90

10:                                               ; preds = %2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._cpPRNG, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call i64 @IPP_UINT_PTR(ptr noundef %14)
  %16 = trunc i64 %15 to i32
  %17 = xor i32 %13, %16
  %18 = icmp eq i32 %17, 1347571271
  br i1 %18, label %20, label %19

19:                                               ; preds = %10
  store i32 -13, ptr %3, align 4
  br label %90

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

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

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

33:                                               ; preds = %24
  store i32 -13, ptr %3, align 4
  br label %90

34:                                               ; preds = %24
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._cpBigNum, ptr %35, i32 0, i32 2
  %37 = load i32, ptr %36, align 8, !tbaa !14
  %38 = mul nsw i32 %37, 64
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._cpBigNum, ptr %39, i32 0, i32 4
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._cpBigNum, ptr %42, i32 0, i32 2
  %44 = load i32, ptr %43, align 8, !tbaa !14
  %45 = sub nsw i32 %44, 1
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i64, ptr %41, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !16
  %49 = call i32 @cpNLZ_BNU(i64 noundef %48)
  %50 = sub nsw i32 %38, %49
  %51 = icmp ne i32 160, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %34
  store i32 -5, ptr %3, align 4
  br label %90

53:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !18
  br label %54

54:                                               ; preds = %73, %53
  %55 = load i32, ptr %6, align 4, !tbaa !18
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._cpBigNum, ptr %56, i32 0, i32 2
  %58 = load i32, ptr %57, align 8, !tbaa !14
  %59 = icmp slt i32 %55, %58
  br i1 %59, label %60, label %76

60:                                               ; preds = %54
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._cpBigNum, ptr %61, i32 0, i32 4
  %63 = load ptr, ptr %62, align 8, !tbaa !15
  %64 = load i32, ptr %6, align 4, !tbaa !18
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i64, ptr %63, i64 %65
  %67 = load i64, ptr %66, align 8, !tbaa !16
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._cpPRNG, ptr %68, i32 0, i32 2
  %70 = load i32, ptr %6, align 4, !tbaa !18
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [3 x i64], ptr %69, i64 0, i64 %71
  store i64 %67, ptr %72, align 8, !tbaa !16
  br label %73

73:                                               ; preds = %60
  %74 = load i32, ptr %6, align 4, !tbaa !18
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %6, align 4, !tbaa !18
  br label %54, !llvm.loop !19

76:                                               ; preds = %54
  br label %77

77:                                               ; preds = %86, %76
  %78 = load i32, ptr %6, align 4, !tbaa !18
  %79 = icmp slt i32 %78, 3
  br i1 %79, label %80, label %89

80:                                               ; preds = %77
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct._cpPRNG, ptr %81, i32 0, i32 2
  %83 = load i32, ptr %6, align 4, !tbaa !18
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [3 x i64], ptr %82, i64 0, i64 %84
  store i64 0, ptr %85, align 8, !tbaa !16
  br label %86

86:                                               ; preds = %80
  %87 = load i32, ptr %6, align 4, !tbaa !18
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %6, align 4, !tbaa !18
  br label %77, !llvm.loop !21

89:                                               ; preds = %77
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  store i32 0, ptr %3, align 4
  br label %90

90:                                               ; preds = %89, %52, %33, %23, %19, %9
  %91 = load i32, ptr %3, align 4
  ret i32 %91
}

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

declare i32 @cpNLZ_BNU(i64 noundef) #2

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"_cpPRNG", !11, i64 0, !11, i64 4, !7, i64 8, !7, i64 32, !7, i64 56, !7, i64 120}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"_cpBigNum", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24}
!14 = !{!13, !11, i64 8}
!15 = !{!13, !6, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"long long", !7, i64 0}
!18 = !{!11, !11, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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 @ippsPRNGSetModulus(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = ptrtoint ptr %1 to i64
  %4 = icmp eq ptr %1, null
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %2
  %6 = load i32, ptr %1, align 8, !tbaa !5
  %7 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %1)
  %8 = trunc i64 %7 to i32
  %9 = xor i32 %6, %8
  %10 = icmp eq i32 %9, 1347571271
  br i1 %10, label %11, label %.loopexit

11:                                               ; preds = %5
  %12 = icmp eq ptr %0, null
  br i1 %12, label %.loopexit, label %13

13:                                               ; preds = %11
  %14 = load i32, ptr %0, align 8, !tbaa !10
  %15 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %0)
  %16 = trunc i64 %15 to i32
  %17 = xor i32 %14, %16
  %18 = icmp eq i32 %17, 1112098638
  br i1 %18, label %19, label %.loopexit

19:                                               ; preds = %13
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = shl nsw i32 %21, 6
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = sext i32 %21 to i64
  %26 = getelementptr i64, ptr %24, i64 %25
  %27 = getelementptr i8, ptr %26, i64 -8
  %28 = load i64, ptr %27, align 8, !tbaa !15
  %29 = tail call i32 @cpNLZ_BNU(i64 noundef %28) #4
  %30 = sub nsw i32 %22, %29
  %.not = icmp eq i32 %30, 160
  br i1 %.not, label %.preheader23, label %.loopexit

.preheader23:                                     ; preds = %19
  %31 = load i32, ptr %20, align 8, !tbaa !13
  %32 = icmp sgt i32 %31, 0
  br i1 %32, label %.lr.ph, label %.lr.ph26

.lr.ph:                                           ; preds = %.preheader23
  %33 = load ptr, ptr %23, align 8, !tbaa !14
  %34 = getelementptr inbounds i8, ptr %1, i64 8
  %wide.trip.count = zext nneg i32 %31 to i64
  %min.iters.check = icmp ult i32 %31, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 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 ]
  %35 = getelementptr inbounds i64, ptr %33, i64 %indvars.iv.prol
  %36 = load i64, ptr %35, align 8, !tbaa !15
  %37 = getelementptr inbounds [3 x i64], ptr %34, i64 0, i64 %indvars.iv.prol
  store i64 %36, ptr %37, align 8, !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 !17

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 ]
  %38 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %39 = icmp ugt i64 %38, -4
  br i1 %39, label %.preheader, label %scalar.ph

vector.memcheck:                                  ; preds = %.lr.ph
  %40 = ptrtoint ptr %33 to i64
  %41 = add i64 %3, 8
  %42 = sub i64 %41, %40
  %diff.check = icmp ult i64 %42, 32
  br i1 %diff.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %wide.trip.count, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %43 = getelementptr inbounds i64, ptr %33, i64 %index
  %44 = getelementptr inbounds i8, ptr %43, i64 16
  %wide.load = load <2 x i64>, ptr %43, align 8, !tbaa !15
  %wide.load33 = load <2 x i64>, ptr %44, align 8, !tbaa !15
  %45 = getelementptr inbounds [3 x i64], ptr %34, i64 0, i64 %index
  %46 = getelementptr inbounds i8, ptr %45, i64 16
  store <2 x i64> %wide.load, ptr %45, align 8, !tbaa !15
  store <2 x i64> %wide.load33, ptr %46, align 8, !tbaa !15
  %index.next = add nuw i64 %index, 4
  %47 = icmp eq i64 %index.next, %n.vec
  br i1 %47, label %middle.block, label %vector.body, !llvm.loop !19

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

.preheader:                                       ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %48 = icmp ult i32 %31, 3
  br i1 %48, label %.lr.ph26, label %.loopexit

.lr.ph26:                                         ; preds = %.preheader23, %.preheader
  %.0.lcssa32 = phi i32 [ %31, %.preheader ], [ 0, %.preheader23 ]
  %49 = shl nuw nsw i32 %.0.lcssa32, 3
  %50 = zext nneg i32 %49 to i64
  %51 = getelementptr i8, ptr %1, i64 %50
  %scevgep = getelementptr i8, ptr %51, i64 8
  %52 = shl nuw nsw i32 %.0.lcssa32, 3
  %53 = sub nsw i32 16, %52
  %54 = zext i32 %53 to i64
  %55 = add nuw nsw i64 %54, 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %scevgep, i8 0, i64 %55, i1 false), !tbaa !15
  br label %.loopexit

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 ]
  %56 = getelementptr inbounds i64, ptr %33, i64 %indvars.iv
  %57 = load i64, ptr %56, align 8, !tbaa !15
  %58 = getelementptr inbounds [3 x i64], ptr %34, i64 0, i64 %indvars.iv
  store i64 %57, ptr %58, align 8, !tbaa !15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %59 = getelementptr inbounds i64, ptr %33, i64 %indvars.iv.next
  %60 = load i64, ptr %59, align 8, !tbaa !15
  %61 = getelementptr inbounds [3 x i64], ptr %34, i64 0, i64 %indvars.iv.next
  store i64 %60, ptr %61, align 8, !tbaa !15
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %62 = getelementptr inbounds i64, ptr %33, i64 %indvars.iv.next.1
  %63 = load i64, ptr %62, align 8, !tbaa !15
  %64 = getelementptr inbounds [3 x i64], ptr %34, i64 0, i64 %indvars.iv.next.1
  store i64 %63, ptr %64, align 8, !tbaa !15
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %65 = getelementptr inbounds i64, ptr %33, i64 %indvars.iv.next.2
  %66 = load i64, ptr %65, align 8, !tbaa !15
  %67 = getelementptr inbounds [3 x i64], ptr %34, i64 0, i64 %indvars.iv.next.2
  store i64 %66, ptr %67, align 8, !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 %.preheader, label %scalar.ph, !llvm.loop !23

.loopexit:                                        ; preds = %.lr.ph26, %.preheader, %19, %13, %11, %5, %2
  %.020 = phi i32 [ -8, %2 ], [ -13, %5 ], [ -8, %11 ], [ -13, %13 ], [ -5, %19 ], [ 0, %.preheader ], [ 0, %.lr.ph26 ]
  ret i32 %.020
}

; 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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 0}
!6 = !{!"_cpPRNG", !7, i64 0, !7, i64 4, !8, i64 8, !8, i64 32, !8, i64 56, !8, i64 120}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"_cpBigNum", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !12, i64 16, !12, i64 24}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!11, !7, i64 8}
!14 = !{!11, !12, i64 16}
!15 = !{!16, !16, i64 0}
!16 = !{!"long long", !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = distinct !{!19, !20, !21, !22}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!"llvm.loop.isvectorized", i32 1}
!22 = !{!"llvm.loop.unroll.runtime.disable"}
!23 = distinct !{!23, !20, !21}


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