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

; 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 @ippsPRNGSetH0(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
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp eq ptr null, %9
  br i1 %10, label %11, label %12

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

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

21:                                               ; preds = %12
  store i32 -13, ptr %3, align 4
  br label %99

22:                                               ; preds = %12
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = icmp eq ptr null, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  store i32 -8, ptr %3, align 4
  br label %99

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

35:                                               ; preds = %26
  store i32 -13, ptr %3, align 4
  br label %99

36:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._cpBigNum, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !14
  %40 = mul nsw i32 %39, 2
  %41 = icmp slt i32 5, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %36
  br label %48

43:                                               ; preds = %36
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._cpBigNum, ptr %44, i32 0, i32 2
  %46 = load i32, ptr %45, align 8, !tbaa !14
  %47 = mul nsw i32 %46, 2
  br label %48

48:                                               ; preds = %43, %42
  %49 = phi i32 [ 5, %42 ], [ %47, %43 ]
  store i32 %49, ptr %6, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !15
  br label %50

50:                                               ; preds = %59, %48
  %51 = load i32, ptr %7, align 4, !tbaa !15
  %52 = icmp slt i32 %51, 3
  br i1 %52, label %53, label %62

53:                                               ; preds = %50
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._cpPRNG, ptr %54, i32 0, i32 3
  %56 = load i32, ptr %7, align 4, !tbaa !15
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [3 x i64], ptr %55, i64 0, i64 %57
  store i64 0, ptr %58, align 8, !tbaa !16
  br label %59

59:                                               ; preds = %53
  %60 = load i32, ptr %7, align 4, !tbaa !15
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %7, align 4, !tbaa !15
  br label %50, !llvm.loop !18

62:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !15
  br label %63

63:                                               ; preds = %81, %62
  %64 = load i32, ptr %8, align 4, !tbaa !15
  %65 = load i32, ptr %6, align 4, !tbaa !15
  %66 = icmp slt i32 %64, %65
  br i1 %66, label %67, label %84

67:                                               ; preds = %63
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._cpBigNum, ptr %68, i32 0, i32 4
  %70 = load ptr, ptr %69, align 8, !tbaa !20
  %71 = load i32, ptr %8, align 4, !tbaa !15
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i32, ptr %70, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !15
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._cpPRNG, ptr %75, i32 0, i32 3
  %77 = getelementptr inbounds [3 x i64], ptr %76, i64 0, i64 0
  %78 = load i32, ptr %8, align 4, !tbaa !15
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds i32, ptr %77, i64 %79
  store i32 %74, ptr %80, align 4, !tbaa !15
  br label %81

81:                                               ; preds = %67
  %82 = load i32, ptr %8, align 4, !tbaa !15
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %8, align 4, !tbaa !15
  br label %63, !llvm.loop !21

84:                                               ; preds = %63
  br label %85

85:                                               ; preds = %95, %84
  %86 = load i32, ptr %8, align 4, !tbaa !15
  %87 = icmp slt i32 %86, 6
  br i1 %87, label %88, label %98

88:                                               ; preds = %85
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct._cpPRNG, ptr %89, i32 0, i32 3
  %91 = getelementptr inbounds [3 x i64], ptr %90, i64 0, i64 0
  %92 = load i32, ptr %8, align 4, !tbaa !15
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds i32, ptr %91, i64 %93
  store i32 0, ptr %94, align 4, !tbaa !15
  br label %95

95:                                               ; preds = %88
  %96 = load i32, ptr %8, align 4, !tbaa !15
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %8, align 4, !tbaa !15
  br label %85, !llvm.loop !22

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

99:                                               ; preds = %98, %35, %25, %21, %11
  %100 = load i32, ptr %3, align 4
  ret i32 %100
}

; 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: 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 = !{!"_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 = !{!11, !11, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"long long", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!13, !6, i64 16}
!21 = distinct !{!21, !19}
!22 = distinct !{!22, !19}


; 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 @ippsPRNGSetH0(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 %.preheader28, label %.loopexit

.preheader28:                                     ; preds = %13
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !13
  %21 = shl nsw i32 %20, 1
  %22 = getelementptr i8, ptr %1, i64 32
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %22, i8 0, i64 24, i1 false), !tbaa !14
  %23 = icmp sgt i32 %20, 2
  %spec.select = select i1 %23, i32 5, i32 %21
  %24 = icmp sgt i32 %spec.select, 0
  br i1 %24, label %.lr.ph, label %.lr.ph32

.lr.ph:                                           ; preds = %.preheader28
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %wide.trip.count = zext nneg i32 %spec.select to i64
  %min.iters.check = icmp ult i32 %spec.select, 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 ]
  %27 = getelementptr inbounds i32, ptr %26, i64 %indvars.iv.prol
  %28 = load i32, ptr %27, align 4, !tbaa !17
  %29 = getelementptr inbounds i32, ptr %22, i64 %indvars.iv.prol
  store i32 %28, ptr %29, align 4, !tbaa !17
  %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 !18

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

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

vector.ph:                                        ; preds = %vector.memcheck
  %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 ]
  %35 = getelementptr inbounds i32, ptr %26, i64 %index
  %36 = getelementptr inbounds i8, ptr %35, i64 16
  %wide.load = load <4 x i32>, ptr %35, align 4, !tbaa !17
  %wide.load40 = load <4 x i32>, ptr %36, align 4, !tbaa !17
  %37 = getelementptr inbounds i32, ptr %22, i64 %index
  %38 = getelementptr inbounds i8, ptr %37, i64 16
  store <4 x i32> %wide.load, ptr %37, align 4, !tbaa !17
  store <4 x i32> %wide.load40, ptr %38, align 4, !tbaa !17
  %index.next = add nuw i64 %index, 8
  %39 = icmp eq i64 %index.next, %n.vec
  br i1 %39, label %middle.block, label %vector.body, !llvm.loop !20

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
  %40 = icmp ult i32 %spec.select, 6
  br i1 %40, label %.lr.ph32, label %.loopexit

.lr.ph32:                                         ; preds = %.preheader28, %.preheader
  %.0.lcssa39 = phi i32 [ %spec.select, %.preheader ], [ 0, %.preheader28 ]
  %41 = shl nuw nsw i32 %.0.lcssa39, 2
  %42 = or disjoint i32 %41, 32
  %43 = zext nneg i32 %42 to i64
  %scevgep = getelementptr i8, ptr %1, i64 %43
  %44 = shl nuw nsw i32 %.0.lcssa39, 2
  %45 = sub nsw i32 20, %44
  %46 = zext i32 %45 to i64
  %47 = add nuw nsw i64 %46, 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1) %scevgep, i8 0, i64 %47, i1 false), !tbaa !17
  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 ]
  %48 = getelementptr inbounds i32, ptr %26, i64 %indvars.iv
  %49 = load i32, ptr %48, align 4, !tbaa !17
  %50 = getelementptr inbounds i32, ptr %22, i64 %indvars.iv
  store i32 %49, ptr %50, align 4, !tbaa !17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %51 = getelementptr inbounds i32, ptr %26, i64 %indvars.iv.next
  %52 = load i32, ptr %51, align 4, !tbaa !17
  %53 = getelementptr inbounds i32, ptr %22, i64 %indvars.iv.next
  store i32 %52, ptr %53, align 4, !tbaa !17
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %54 = getelementptr inbounds i32, ptr %26, i64 %indvars.iv.next.1
  %55 = load i32, ptr %54, align 4, !tbaa !17
  %56 = getelementptr inbounds i32, ptr %22, i64 %indvars.iv.next.1
  store i32 %55, ptr %56, align 4, !tbaa !17
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %57 = getelementptr inbounds i32, ptr %26, i64 %indvars.iv.next.2
  %58 = load i32, ptr %57, align 4, !tbaa !17
  %59 = getelementptr inbounds i32, ptr %22, i64 %indvars.iv.next.2
  store i32 %58, ptr %59, align 4, !tbaa !17
  %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 !24

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }

!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 = !{!15, !15, i64 0}
!15 = !{!"long long", !8, i64 0}
!16 = !{!11, !12, i64 16}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}
!20 = distinct !{!20, !21, !22, !23}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!"llvm.loop.isvectorized", i32 1}
!23 = !{!"llvm.loop.unroll.runtime.disable"}
!24 = distinct !{!24, !21, !22}


; 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