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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @ippsGFpInitArbitrary(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 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
  %9 = load ptr, ptr %7, align 8, !tbaa !5
  %10 = icmp eq ptr null, %9
  br i1 %10, label %11, label %12

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

12:                                               ; preds = %3
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 2
  br i1 %14, label %18, label %15

15:                                               ; preds = %12
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = icmp sgt i32 %16, 1024
  br i1 %17, label %18, label %19

18:                                               ; preds = %15, %12
  store i32 -6, ptr %4, align 4
  br label %97

19:                                               ; preds = %15
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = icmp eq ptr null, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  store i32 -8, ptr %4, align 4
  br label %97

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

32:                                               ; preds = %23
  store i32 -13, ptr %4, align 4
  br label %97

33:                                               ; preds = %23
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._cpBigNum, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !13
  %37 = icmp ne i32 %36, 1
  br i1 %37, label %38, label %39

38:                                               ; preds = %33
  store i32 -5, ptr %4, align 4
  br label %97

39:                                               ; preds = %33
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._cpBigNum, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 8, !tbaa !14
  %43 = mul nsw i32 %42, 64
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._cpBigNum, ptr %44, i32 0, i32 4
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._cpBigNum, ptr %47, i32 0, i32 2
  %49 = load i32, ptr %48, align 8, !tbaa !14
  %50 = sub nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i64, ptr %46, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !16
  %54 = call i32 @cpNLZ_BNU(i64 noundef %53)
  %55 = sub nsw i32 %43, %54
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = icmp ne i32 %55, %56
  br i1 %57, label %58, label %59

58:                                               ; preds = %39
  store i32 -5, ptr %4, align 4
  br label %97

59:                                               ; preds = %39
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._cpBigNum, ptr %60, i32 0, i32 2
  %62 = load i32, ptr %61, align 8, !tbaa !14
  %63 = icmp eq i32 %62, 1
  br i1 %63, label %64, label %72

64:                                               ; preds = %59
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._cpBigNum, ptr %65, i32 0, i32 4
  %67 = load ptr, ptr %66, align 8, !tbaa !15
  %68 = getelementptr inbounds i64, ptr %67, i64 0
  %69 = load i64, ptr %68, align 8, !tbaa !16
  %70 = icmp ult i64 %69, 3
  br i1 %70, label %71, label %72

71:                                               ; preds = %64
  store i32 -5, ptr %4, align 4
  br label %97

72:                                               ; preds = %64, %59
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._cpBigNum, ptr %73, i32 0, i32 4
  %75 = load ptr, ptr %74, align 8, !tbaa !15
  %76 = getelementptr inbounds i64, ptr %75, i64 0
  %77 = load i64, ptr %76, align 8, !tbaa !16
  %78 = and i64 %77, 1
  %79 = icmp eq i64 0, %78
  br i1 %79, label %80, label %81

80:                                               ; preds = %72
  store i32 -5, ptr %4, align 4
  br label %97

81:                                               ; preds = %72
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %82 = load i32, ptr %6, align 4, !tbaa !9
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = call i32 @cpGFpInitGFp(i32 noundef %82, ptr noundef %83)
  store i32 %84, ptr %8, align 4, !tbaa !9
  %85 = load i32, ptr %8, align 4, !tbaa !9
  %86 = icmp eq i32 0, %85
  br i1 %86, label %87, label %95

87:                                               ; preds = %81
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct._cpBigNum, ptr %88, i32 0, i32 4
  %90 = load ptr, ptr %89, align 8, !tbaa !15
  %91 = load i32, ptr %6, align 4, !tbaa !9
  %92 = call ptr @ippsGFpMethod_pArb()
  %93 = load ptr, ptr %7, align 8, !tbaa !5
  %94 = call i32 @cpGFpSetGFp(ptr noundef %90, i32 noundef %91, ptr noundef %92, ptr noundef %93)
  br label %95

95:                                               ; preds = %87, %81
  %96 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %96, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %97

97:                                               ; preds = %95, %80, %71, %58, %38, %32, %22, %18, %11
  %98 = load i32, ptr %4, align 4
  ret i32 %98
}

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

declare i32 @cpNLZ_BNU(i64 noundef) #2

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

declare i32 @cpGFpInitGFp(i32 noundef, ptr noundef) #2

declare i32 @cpGFpSetGFp(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #2

declare ptr @ippsGFpMethod_pArb() #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"_cpBigNum", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !6, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"long long", !7, i64 0}


; 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 i32 @ippsGFpInitArbitrary(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %2, null
  br i1 %4, label %43, label %5

5:                                                ; preds = %3
  %6 = add i32 %1, -1025
  %or.cond = icmp ult i32 %6, -1023
  br i1 %or.cond, label %43, label %7

7:                                                ; preds = %5
  %8 = icmp eq ptr %0, null
  br i1 %8, label %43, label %9

9:                                                ; preds = %7
  %10 = load i32, ptr %0, align 8, !tbaa !5
  %11 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %0)
  %12 = trunc i64 %11 to i32
  %13 = xor i32 %10, %12
  %14 = icmp eq i32 %13, 1112098638
  br i1 %14, label %15, label %43

15:                                               ; preds = %9
  %16 = getelementptr inbounds i8, ptr %0, i64 4
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %.not = icmp eq i32 %17, 1
  br i1 %.not, label %18, label %43

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !12
  %21 = shl nsw i32 %20, 6
  %22 = getelementptr inbounds i8, ptr %0, i64 16
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = sext i32 %20 to i64
  %25 = getelementptr i64, ptr %23, i64 %24
  %26 = getelementptr i8, ptr %25, i64 -8
  %27 = load i64, ptr %26, align 8, !tbaa !14
  %28 = tail call i32 @cpNLZ_BNU(i64 noundef %27) #3
  %29 = sub nsw i32 %21, %28
  %.not25 = icmp eq i32 %29, %1
  br i1 %.not25, label %30, label %43

30:                                               ; preds = %18
  %31 = load i32, ptr %19, align 8, !tbaa !12
  %32 = icmp eq i32 %31, 1
  %.pre = load ptr, ptr %22, align 8, !tbaa !13
  %.pre26 = load i64, ptr %.pre, align 8, !tbaa !14
  %33 = icmp ult i64 %.pre26, 3
  %or.cond27 = select i1 %32, i1 %33, i1 false
  %34 = and i64 %.pre26, 1
  %35 = icmp eq i64 %34, 0
  %or.cond29 = select i1 %or.cond27, i1 true, i1 %35
  br i1 %or.cond29, label %43, label %36

36:                                               ; preds = %30
  %37 = tail call i32 @cpGFpInitGFp(i32 noundef %1, ptr noundef nonnull %2) #3
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %43

39:                                               ; preds = %36
  %40 = load ptr, ptr %22, align 8, !tbaa !13
  %41 = tail call ptr @ippsGFpMethod_pArb() #3
  %42 = tail call i32 @cpGFpSetGFp(ptr noundef %40, i32 noundef %1, ptr noundef %41, ptr noundef nonnull %2) #3
  br label %43

43:                                               ; preds = %30, %36, %39, %18, %15, %9, %7, %5, %3
  %.0 = phi i32 [ -8, %3 ], [ -6, %5 ], [ -8, %7 ], [ -13, %9 ], [ -5, %15 ], [ -5, %18 ], [ 0, %39 ], [ %37, %36 ], [ -5, %30 ]
  ret i32 %.0
}

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

declare i32 @cpNLZ_BNU(i64 noundef) local_unnamed_addr #2

declare i32 @cpGFpInitGFp(i32 noundef, ptr noundef) local_unnamed_addr #2

declare i32 @cpGFpSetGFp(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @ippsGFpMethod_pArb() 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 = !{!"_cpBigNum", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !10, i64 24}
!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, !10, i64 16}
!14 = !{!15, !15, i64 0}
!15 = !{!"long long", !8, i64 0}


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