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

; 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 @ippsPRNGen_BN(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 ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  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
  %13 = load ptr, ptr %7, 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 %87

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

26:                                               ; preds = %16
  store i32 -13, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %87

27:                                               ; preds = %16
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = icmp eq ptr null, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  store i32 -8, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %87

31:                                               ; preds = %27
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._cpBigNum, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !13
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = call i64 @IPP_UINT_PTR(ptr noundef %35)
  %37 = trunc i64 %36 to i32
  %38 = xor i32 %34, %37
  %39 = icmp eq i32 %38, 1112098638
  br i1 %39, label %41, label %40

40:                                               ; preds = %31
  store i32 -13, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %87

41:                                               ; preds = %31
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = icmp slt i32 %42, 1
  br i1 %43, label %44, label %45

44:                                               ; preds = %41
  store i32 -15, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %87

45:                                               ; preds = %41
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._cpBigNum, ptr %47, i32 0, i32 3
  %49 = load i32, ptr %48, align 4, !tbaa !15
  %50 = mul nsw i32 %49, 64
  %51 = icmp sgt i32 %46, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %45
  store i32 -15, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %87

53:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._cpBigNum, ptr %54, i32 0, i32 4
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  store ptr %56, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = add nsw i32 %57, 64
  %59 = sub nsw i32 %58, 1
  %60 = sdiv i32 %59, 64
  store i32 %60, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = and i32 %61, 63
  %63 = sub nsw i32 64, %62
  %64 = and i32 %63, 63
  %65 = zext i32 %64 to i64
  %66 = lshr i64 -1, %65
  store i64 %66, ptr %12, align 8, !tbaa !17
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = load i32, ptr %6, align 4, !tbaa !9
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = call i32 @cpPRNGen(ptr noundef %67, i32 noundef %68, ptr noundef %69)
  %71 = load i64, ptr %12, align 8, !tbaa !17
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = load i32, ptr %11, align 4, !tbaa !9
  %74 = sub nsw i32 %73, 1
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds i64, ptr %72, i64 %75
  %77 = load i64, ptr %76, align 8, !tbaa !17
  %78 = and i64 %77, %71
  store i64 %78, ptr %76, align 8, !tbaa !17
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = load i32, ptr %11, align 4, !tbaa !9
  %81 = call i32 @cpFix_BNU(ptr noundef %79, i32 noundef %80)
  store i32 %81, ptr %11, align 4, !tbaa !9
  %82 = load i32, ptr %11, align 4, !tbaa !9
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct._cpBigNum, ptr %83, i32 0, i32 2
  store i32 %82, ptr %84, align 8, !tbaa !19
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct._cpBigNum, ptr %85, i32 0, i32 1
  store i32 1, ptr %86, align 4, !tbaa !20
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %87

87:                                               ; preds = %53, %52, %44, %40, %30, %26, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %88 = load i32, ptr %4, align 4
  ret i32 %88
}

; 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: inlinehint nounwind uwtable
declare hidden i32 @cpFix_BNU(ptr noundef, i32 noundef) #2

; 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}
!13 = !{!14, !10, i64 0}
!14 = !{!"_cpBigNum", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24}
!15 = !{!14, !10, i64 12}
!16 = !{!14, !6, i64 16}
!17 = !{!18, !18, i64 0}
!18 = !{!"long long", !7, i64 0}
!19 = !{!14, !10, i64 8}
!20 = !{!14, !10, 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 -15, 1) i32 @ippsPRNGen_BN(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %2, null
  br i1 %4, label %44, label %5

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

11:                                               ; preds = %5
  %12 = icmp eq ptr %0, null
  br i1 %12, label %44, 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 %44

19:                                               ; preds = %13
  %20 = icmp slt i32 %1, 1
  br i1 %20, label %44, label %21

21:                                               ; preds = %19
  %22 = getelementptr inbounds i8, ptr %0, i64 12
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = shl nsw i32 %23, 6
  %25 = icmp slt i32 %24, %1
  br i1 %25, label %44, label %26

26:                                               ; preds = %21
  %27 = getelementptr inbounds i8, ptr %0, i64 16
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = add nuw nsw i32 %1, 63
  %30 = lshr i32 %29, 6
  %31 = sub nsw i32 0, %1
  %32 = and i32 %31, 63
  %33 = zext nneg i32 %32 to i64
  %34 = lshr i64 -1, %33
  %35 = tail call i32 @cpPRNGen(ptr noundef %28, i32 noundef %1, ptr noundef nonnull %2) #3
  %36 = zext nneg i32 %30 to i64
  %37 = getelementptr i64, ptr %28, i64 %36
  %38 = getelementptr i8, ptr %37, i64 -8
  %39 = load i64, ptr %38, align 8, !tbaa !15
  %40 = and i64 %39, %34
  store i64 %40, ptr %38, align 8, !tbaa !15
  %41 = tail call i32 @cpFix_BNU(ptr noundef %28, i32 noundef %30)
  %42 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %41, ptr %42, align 8, !tbaa !17
  %43 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 1, ptr %43, align 4, !tbaa !18
  br label %44

44:                                               ; preds = %21, %19, %13, %11, %5, %3, %26
  %.0 = phi i32 [ 0, %26 ], [ -8, %3 ], [ -13, %5 ], [ -8, %11 ], [ -13, %13 ], [ -15, %19 ], [ -15, %21 ]
  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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cpFix_BNU(ptr noundef, i32 noundef) local_unnamed_addr #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 = { 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 = !{!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 12}
!14 = !{!11, !12, i64 16}
!15 = !{!16, !16, i64 0}
!16 = !{!"long long", !8, i64 0}
!17 = !{!11, !7, i64 8}
!18 = !{!11, !7, i64 4}


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