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

; 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._cpRSA_public_key = type { i32, i32, i32, i32, i32, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @ippsRSA_InitPublicKey(i32 noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !5
  %15 = load ptr, ptr %8, align 8, !tbaa !9
  %16 = icmp eq ptr null, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %4
  store i32 -8, ptr %5, align 4
  br label %111

18:                                               ; preds = %4
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = icmp sgt i32 8, %19
  br i1 %20, label %24, label %21

21:                                               ; preds = %18
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = icmp sgt i32 %22, 16384
  br i1 %23, label %24, label %25

24:                                               ; preds = %21, %18
  store i32 -14, ptr %5, align 4
  br label %111

25:                                               ; preds = %21
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = icmp slt i32 0, %26
  br i1 %27, label %28, label %32

28:                                               ; preds = %25
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = icmp sle i32 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28, %25
  store i32 -5, ptr %5, align 4
  br label %111

33:                                               ; preds = %28
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = call i32 @cpSizeof_RSA_publicKey(i32 noundef %35, i32 noundef %36)
  %38 = icmp slt i32 %34, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %33
  store i32 -9, ptr %5, align 4
  br label %111

40:                                               ; preds = %33
  %41 = load ptr, ptr %8, align 8, !tbaa !9
  %42 = call i64 @IPP_UINT_PTR(ptr noundef %41)
  %43 = trunc i64 %42 to i32
  %44 = xor i32 1381187888, %43
  %45 = load ptr, ptr %8, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct._cpRSA_public_key, ptr %45, i32 0, i32 0
  store i32 %44, ptr %46, align 8, !tbaa !11
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct._cpRSA_public_key, ptr %48, i32 0, i32 1
  store i32 %47, ptr %49, align 4, !tbaa !13
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = load ptr, ptr %8, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct._cpRSA_public_key, ptr %51, i32 0, i32 2
  store i32 %50, ptr %52, align 8, !tbaa !14
  %53 = load ptr, ptr %8, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct._cpRSA_public_key, ptr %53, i32 0, i32 3
  store i32 0, ptr %54, align 4, !tbaa !15
  %55 = load ptr, ptr %8, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct._cpRSA_public_key, ptr %55, i32 0, i32 4
  store i32 0, ptr %56, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %57 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %57, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %58 = load i32, ptr %7, align 4, !tbaa !5
  %59 = add nsw i32 %58, 64
  %60 = sub nsw i32 %59, 1
  %61 = sdiv i32 %60, 64
  store i32 %61, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = add nsw i32 %62, 31
  %64 = ashr i32 %63, 5
  store i32 %64, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %65 = load i32, ptr %12, align 4, !tbaa !5
  call void @rsaMontExpGetSize(i32 noundef %65, ptr noundef %13)
  %66 = load ptr, ptr %10, align 8, !tbaa !9
  %67 = getelementptr inbounds i8, ptr %66, i64 40
  store ptr %67, ptr %10, align 8, !tbaa !9
  %68 = load ptr, ptr %10, align 8, !tbaa !9
  %69 = load ptr, ptr %10, align 8, !tbaa !9
  %70 = call i64 @IPP_INT_PTR(ptr noundef %69)
  %71 = and i64 %70, 7
  %72 = xor i64 %71, -1
  %73 = add nsw i64 %72, 1
  %74 = and i64 %73, 7
  %75 = getelementptr inbounds i8, ptr %68, i64 %74
  %76 = load ptr, ptr %8, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct._cpRSA_public_key, ptr %76, i32 0, i32 5
  store ptr %75, ptr %77, align 8, !tbaa !17
  %78 = load i32, ptr %11, align 4, !tbaa !5
  %79 = mul nsw i32 %78, 8
  %80 = load ptr, ptr %10, align 8, !tbaa !9
  %81 = sext i32 %79 to i64
  %82 = getelementptr inbounds i8, ptr %80, i64 %81
  store ptr %82, ptr %10, align 8, !tbaa !9
  %83 = load ptr, ptr %10, align 8, !tbaa !9
  %84 = load ptr, ptr %8, align 8, !tbaa !9
  %85 = getelementptr inbounds %struct._cpRSA_public_key, ptr %84, i32 0, i32 6
  store ptr %83, ptr %85, align 8, !tbaa !18
  %86 = load i32, ptr %13, align 4, !tbaa !5
  %87 = load ptr, ptr %10, align 8, !tbaa !9
  %88 = sext i32 %86 to i64
  %89 = getelementptr inbounds i8, ptr %87, i64 %88
  store ptr %89, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !5
  br label %90

90:                                               ; preds = %101, %40
  %91 = load i32, ptr %14, align 4, !tbaa !5
  %92 = load i32, ptr %11, align 4, !tbaa !5
  %93 = icmp slt i32 %91, %92
  br i1 %93, label %94, label %104

94:                                               ; preds = %90
  %95 = load ptr, ptr %8, align 8, !tbaa !9
  %96 = getelementptr inbounds %struct._cpRSA_public_key, ptr %95, i32 0, i32 5
  %97 = load ptr, ptr %96, align 8, !tbaa !17
  %98 = load i32, ptr %14, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds i64, ptr %97, i64 %99
  store i64 0, ptr %100, align 8, !tbaa !19
  br label %101

101:                                              ; preds = %94
  %102 = load i32, ptr %14, align 4, !tbaa !5
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %14, align 4, !tbaa !5
  br label %90, !llvm.loop !21

104:                                              ; preds = %90
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  %105 = load ptr, ptr %8, align 8, !tbaa !9
  %106 = getelementptr inbounds %struct._cpRSA_public_key, ptr %105, i32 0, i32 6
  %107 = load ptr, ptr %106, align 8, !tbaa !18
  %108 = load i32, ptr %6, align 4, !tbaa !5
  %109 = call ptr @gsModArithRSA()
  %110 = call i32 @gsModEngineInit(ptr noundef %107, ptr noundef null, i32 noundef %108, i32 noundef 2, ptr noundef %109)
  store i32 0, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, 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 %111

111:                                              ; preds = %104, %39, %32, %24, %17
  %112 = load i32, ptr %5, align 4
  ret i32 %112
}

; Function Attrs: nounwind uwtable
declare hidden i32 @cpSizeof_RSA_publicKey(i32 noundef, i32 noundef) #0

; 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

declare void @rsaMontExpGetSize(i32 noundef, ptr noundef) #3

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

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

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

declare ptr @gsModArithRSA() #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 willreturn memory(argmem: readwrite) }
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 = !{!"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 = !{!12, !6, i64 0}
!12 = !{!"_cpRSA_public_key", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !10, i64 24, !10, i64 32}
!13 = !{!12, !6, i64 4}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !6, i64 12}
!16 = !{!12, !6, i64 16}
!17 = !{!12, !10, i64 24}
!18 = !{!12, !10, i64 32}
!19 = !{!20, !20, i64 0}
!20 = !{!"long long", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; 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 -14, 1) i32 @ippsRSA_InitPublicKey(i32 noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  %6 = icmp eq ptr %2, null
  br i1 %6, label %41, label %7

7:                                                ; preds = %4
  %8 = add i32 %0, -16385
  %or.cond = icmp ult i32 %8, -16377
  br i1 %or.cond, label %41, label %9

9:                                                ; preds = %7
  %10 = icmp slt i32 %1, 1
  %.not = icmp sgt i32 %1, %0
  %or.cond42 = or i1 %10, %.not
  br i1 %or.cond42, label %41, label %11

11:                                               ; preds = %9
  %12 = tail call i32 @cpSizeof_RSA_publicKey(i32 noundef %0, i32 noundef %1)
  %13 = icmp sgt i32 %12, %3
  br i1 %13, label %41, label %._crit_edge

._crit_edge:                                      ; preds = %11
  %14 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %2)
  %15 = trunc i64 %14 to i32
  %16 = xor i32 %15, 1381187888
  store i32 %16, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 %0, ptr %17, align 4, !tbaa !11
  %18 = getelementptr inbounds i8, ptr %2, i64 8
  store i32 %1, ptr %18, align 8, !tbaa !12
  %19 = getelementptr inbounds i8, ptr %2, i64 12
  store i32 0, ptr %19, align 4, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %2, i64 16
  store i32 0, ptr %20, align 8, !tbaa !14
  %21 = add nuw nsw i32 %1, 63
  %22 = lshr i32 %21, 6
  %23 = add nuw nsw i32 %0, 31
  %24 = lshr i32 %23, 5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #5
  call void @rsaMontExpGetSize(i32 noundef %24, ptr noundef nonnull %5) #5
  %25 = getelementptr inbounds i8, ptr %2, i64 40
  %26 = call i64 @IPP_INT_PTR(ptr noundef nonnull %25)
  %27 = sub i64 0, %26
  %28 = and i64 %27, 7
  %29 = getelementptr i8, ptr %25, i64 %28
  %30 = getelementptr inbounds i8, ptr %2, i64 24
  store ptr %29, ptr %30, align 8, !tbaa !15
  %31 = shl nuw nsw i32 %22, 3
  %32 = zext nneg i32 %31 to i64
  %33 = getelementptr inbounds i8, ptr %25, i64 %32
  %34 = getelementptr inbounds i8, ptr %2, i64 32
  store ptr %33, ptr %34, align 8, !tbaa !16
  %35 = add nsw i32 %22, -1
  %36 = zext nneg i32 %35 to i64
  %37 = shl nuw nsw i64 %36, 3
  %38 = add nuw nsw i64 %37, 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %29, i8 0, i64 %38, i1 false), !tbaa !17
  %39 = call ptr @gsModArithRSA() #5
  %40 = call i32 @gsModEngineInit(ptr noundef nonnull %33, ptr noundef null, i32 noundef %0, i32 noundef 2, ptr noundef %39) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #5
  br label %41

41:                                               ; preds = %11, %9, %7, %4, %._crit_edge
  %.038 = phi i32 [ 0, %._crit_edge ], [ -8, %4 ], [ -14, %7 ], [ -5, %9 ], [ -9, %11 ]
  ret i32 %.038
}

; Function Attrs: nounwind uwtable
declare hidden i32 @cpSizeof_RSA_publicKey(i32 noundef, i32 noundef) local_unnamed_addr #0

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

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

declare void @rsaMontExpGetSize(i32 noundef, ptr noundef) local_unnamed_addr #3

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

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

declare i32 @gsModEngineInit(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

declare ptr @gsModArithRSA() local_unnamed_addr #3

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 = !{!"_cpRSA_public_key", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 24, !10, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !7, i64 12}
!14 = !{!6, !7, i64 16}
!15 = !{!6, !10, i64 24}
!16 = !{!6, !10, i64 32}
!17 = !{!18, !18, i64 0}
!18 = !{!"long long", !8, i64 0}


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