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

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

@cpHashIV = external global [0 x ptr], align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @ippsPRNGInit(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %9 = load ptr, ptr %5, align 8, !tbaa !9
  %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 %79

12:                                               ; preds = %2
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp sgt i32 1, %13
  br i1 %14, label %22, label %15

15:                                               ; preds = %12
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp sgt i32 %16, 512
  br i1 %17, label %22, label %18

18:                                               ; preds = %15
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = and i32 %19, 7
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %18, %15, %12
  store i32 -15, ptr %3, align 4
  br label %79

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %24 = call i32 @cpHashIvSize(i32 noundef 1)
  store i32 %24, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %25 = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @cpHashIV, i64 0, i64 1), align 8, !tbaa !9
  store ptr %25, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %34, %23
  %27 = load i32, ptr %8, align 4, !tbaa !5
  %28 = icmp slt i32 %27, 184
  br i1 %28, label %29, label %37

29:                                               ; preds = %26
  %30 = load ptr, ptr %5, align 8, !tbaa !9
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i8, ptr %30, i64 %32
  store i8 0, ptr %33, align 1, !tbaa !11
  br label %34

34:                                               ; preds = %29
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %8, align 4, !tbaa !5
  br label %26, !llvm.loop !12

37:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %38 = load ptr, ptr %5, align 8, !tbaa !9
  %39 = call i64 @IPP_UINT_PTR(ptr noundef %38)
  %40 = trunc i64 %39 to i32
  %41 = xor i32 1347571271, %40
  %42 = load ptr, ptr %5, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct._cpPRNG, ptr %42, i32 0, i32 0
  store i32 %41, ptr %43, align 8, !tbaa !14
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct._cpPRNG, ptr %45, i32 0, i32 1
  store i32 %44, ptr %46, align 4, !tbaa !16
  %47 = load ptr, ptr %5, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct._cpPRNG, ptr %47, i32 0, i32 2
  %49 = getelementptr inbounds [3 x i64], ptr %48, i64 0, i64 0
  %50 = getelementptr inbounds i32, ptr %49, i64 0
  store i32 -1, ptr %50, align 8, !tbaa !5
  %51 = load ptr, ptr %5, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct._cpPRNG, ptr %51, i32 0, i32 2
  %53 = getelementptr inbounds [3 x i64], ptr %52, i64 0, i64 0
  %54 = getelementptr inbounds i32, ptr %53, i64 1
  store i32 -1, ptr %54, align 4, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct._cpPRNG, ptr %55, i32 0, i32 2
  %57 = getelementptr inbounds [3 x i64], ptr %56, i64 0, i64 0
  %58 = getelementptr inbounds i32, ptr %57, i64 2
  store i32 -1, ptr %58, align 8, !tbaa !5
  %59 = load ptr, ptr %5, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct._cpPRNG, ptr %59, i32 0, i32 2
  %61 = getelementptr inbounds [3 x i64], ptr %60, i64 0, i64 0
  %62 = getelementptr inbounds i32, ptr %61, i64 3
  store i32 -1, ptr %62, align 4, !tbaa !5
  %63 = load ptr, ptr %5, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct._cpPRNG, ptr %63, i32 0, i32 2
  %65 = getelementptr inbounds [3 x i64], ptr %64, i64 0, i64 0
  %66 = getelementptr inbounds i32, ptr %65, i64 4
  store i32 -1, ptr %66, align 8, !tbaa !5
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = icmp slt i32 %67, 20
  br i1 %68, label %69, label %71

69:                                               ; preds = %37
  %70 = load i32, ptr %6, align 4, !tbaa !5
  br label %72

71:                                               ; preds = %37
  br label %72

72:                                               ; preds = %71, %69
  %73 = phi i32 [ %70, %69 ], [ 20, %71 ]
  store i32 %73, ptr %6, align 4, !tbaa !5
  %74 = load ptr, ptr %7, align 8, !tbaa !9
  %75 = load ptr, ptr %5, align 8, !tbaa !9
  %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 %6, align 4, !tbaa !5
  call void @CopyBlock(ptr noundef %74, ptr noundef %77, i32 noundef %78)
  store i32 0, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %79

79:                                               ; preds = %72, %22, %11
  %80 = load i32, ptr %3, align 4
  ret i32 %80
}

; 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 i32 @cpHashIvSize(i32 noundef) #2

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @CopyBlock(ptr noundef, ptr noundef, i32 noundef) #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 = { 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !6, i64 0}
!15 = !{!"_cpPRNG", !6, i64 0, !6, i64 4, !7, i64 8, !7, i64 32, !7, i64 56, !7, i64 120}
!16 = !{!15, !6, 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"

@cpHashIV = external local_unnamed_addr global [0 x ptr], align 8

; Function Attrs: nounwind uwtable
define dso_local range(i32 -15, 1) i32 @ippsPRNGInit(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %1, null
  br i1 %3, label %17, label %4

4:                                                ; preds = %2
  %5 = add i32 %0, -1
  %or.cond = icmp ult i32 %5, 512
  %6 = and i32 %0, 7
  %.not = icmp eq i32 %6, 0
  %or.cond26 = and i1 %or.cond, %.not
  br i1 %or.cond26, label %7, label %17

7:                                                ; preds = %4
  %8 = tail call i32 @cpHashIvSize(i32 noundef 1)
  %9 = load ptr, ptr getelementptr inbounds (i8, ptr @cpHashIV, i64 8), align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(184) %1, i8 0, i64 184, i1 false), !tbaa !9
  %10 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %1)
  %11 = trunc i64 %10 to i32
  %12 = xor i32 %11, 1347571271
  store i32 %12, ptr %1, align 8, !tbaa !10
  %13 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %0, ptr %13, align 4, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %1, i64 8
  %15 = tail call i32 @llvm.smin.i32(i32 %8, i32 20)
  %16 = getelementptr inbounds i8, ptr %1, i64 32
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(20) %14, i8 -1, i64 20, i1 false)
  tail call void @CopyBlock(ptr noundef %9, ptr noundef nonnull %16, i32 noundef %15)
  br label %17

17:                                               ; preds = %4, %2, %7
  %.023 = phi i32 [ 0, %7 ], [ -8, %2 ], [ -15, %4 ]
  ret i32 %.023
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cpHashIvSize(i32 noundef) local_unnamed_addr #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @CopyBlock(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"_cpPRNG", !12, i64 0, !12, i64 4, !7, i64 8, !7, i64 32, !7, i64 56, !7, i64 120}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !12, i64 4}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass