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

; 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] }

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

15:                                               ; preds = %3
  store i32 -8, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %55

16:                                               ; preds = %3
  %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 %4, align 4
  store i32 1, ptr %9, align 4
  br label %55

20:                                               ; preds = %16
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._cpPRNG, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = call i64 @IPP_UINT_PTR(ptr noundef %24)
  %26 = trunc i64 %25 to i32
  %27 = xor i32 %23, %26
  %28 = icmp eq i32 %27, 1347571271
  br i1 %28, label %30, label %29

29:                                               ; preds = %20
  store i32 -13, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %55

30:                                               ; preds = %20
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = icmp slt i32 %31, 1
  br i1 %32, label %33, label %34

33:                                               ; preds = %30
  store i32 -15, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %55

34:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = add nsw i32 %35, 31
  %37 = ashr i32 %36, 5
  store i32 %37, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = and i32 %38, 31
  %40 = sub nsw i32 32, %39
  %41 = and i32 %40, 31
  %42 = lshr i32 -1, %41
  store i32 %42, ptr %11, align 4, !tbaa !9
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = call i32 @cpPRNGen(ptr noundef %43, i32 noundef %44, ptr noundef %45)
  %47 = load i32, ptr %11, align 4, !tbaa !9
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load i32, ptr %10, align 4, !tbaa !9
  %50 = sub nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i32, ptr %48, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = and i32 %53, %47
  store i32 %54, ptr %52, align 4, !tbaa !9
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %55

55:                                               ; preds = %34, %33, %29, %19, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %56 = load i32, ptr %4, align 4
  ret i32 %56
}

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

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

declare i32 @cpPRNGen(ptr noundef, i32 noundef, ptr noundef) #3

; 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 = { 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_cpPRNG", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 32, !7, i64 56, !7, i64 120}


; 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 -15, 1) i32 @ippsPRNGen(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, null
  %5 = icmp eq ptr %2, null
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %26, label %6

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

12:                                               ; preds = %6
  %13 = icmp slt i32 %1, 1
  br i1 %13, label %26, label %14

14:                                               ; preds = %12
  %15 = add nuw nsw i32 %1, 31
  %16 = lshr i32 %15, 5
  %17 = sub nsw i32 0, %1
  %18 = and i32 %17, 31
  %19 = lshr i32 -1, %18
  %20 = tail call i32 @cpPRNGen(ptr noundef nonnull %0, i32 noundef %1, ptr noundef nonnull %2) #3
  %21 = zext nneg i32 %16 to i64
  %22 = getelementptr i32, ptr %0, i64 %21
  %23 = getelementptr i8, ptr %22, i64 -4
  %24 = load i32, ptr %23, align 4, !tbaa !10
  %25 = and i32 %24, %19
  store i32 %25, ptr %23, align 4, !tbaa !10
  br label %26

26:                                               ; preds = %12, %6, %3, %14
  %.0 = phi i32 [ 0, %14 ], [ -8, %3 ], [ -13, %6 ], [ -15, %12 ]
  ret i32 %.0
}

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

declare i32 @cpPRNGen(ptr noundef, i32 noundef, ptr 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 = !{!"_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 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass