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

; 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._cpGFp = type { i32, i32, ptr }
%struct._cpGFpElement = type { i32, i32, ptr }
%struct._gsModEngine = type { ptr, i32, i32, i32, i32, i32, ptr, ptr, ptr, i64, ptr, ptr, ptr, ptr, i32, i32, ptr }

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

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

13:                                               ; preds = %3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp eq ptr null, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  store i32 -8, ptr %4, align 4
  br label %90

17:                                               ; preds = %13
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp eq ptr null, %18
  br i1 %19, label %20, label %21

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

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

30:                                               ; preds = %21
  store i32 -13, ptr %4, align 4
  br label %90

31:                                               ; preds = %21
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._cpGFpElement, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !12
  %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, 1129136456
  br i1 %39, label %41, label %40

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

41:                                               ; preds = %31
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._cpGFpElement, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !12
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = call i64 @IPP_UINT_PTR(ptr noundef %45)
  %47 = trunc i64 %46 to i32
  %48 = xor i32 %44, %47
  %49 = icmp eq i32 %48, 1129136456
  br i1 %49, label %51, label %50

50:                                               ; preds = %41
  store i32 -13, ptr %4, align 4
  br label %90

51:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._cpGFp, ptr %52, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  store ptr %54, ptr %8, align 8, !tbaa !5
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._gsModEngine, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !15
  %58 = icmp eq ptr %57, null
  br i1 %58, label %60, label %59

59:                                               ; preds = %51
  store i32 -5, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %89

60:                                               ; preds = %51
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._cpGFpElement, ptr %61, i32 0, i32 1
  %63 = load i32, ptr %62, align 4, !tbaa !18
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._gsModEngine, ptr %64, i32 0, i32 3
  %66 = load i32, ptr %65, align 8, !tbaa !19
  %67 = icmp ne i32 %63, %66
  br i1 %67, label %76, label %68

68:                                               ; preds = %60
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct._cpGFpElement, ptr %69, i32 0, i32 1
  %71 = load i32, ptr %70, align 4, !tbaa !18
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct._gsModEngine, ptr %72, i32 0, i32 3
  %74 = load i32, ptr %73, align 8, !tbaa !19
  %75 = icmp ne i32 %71, %74
  br i1 %75, label %76, label %77

76:                                               ; preds = %68, %60
  store i32 -11, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %89

77:                                               ; preds = %68
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct._cpGFpElement, ptr %78, i32 0, i32 2
  %80 = load ptr, ptr %79, align 8, !tbaa !20
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct._cpGFpElement, ptr %81, i32 0, i32 2
  %83 = load ptr, ptr %82, align 8, !tbaa !20
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  %85 = call i32 @cpGFpSqrt(ptr noundef %80, ptr noundef %83, ptr noundef %84)
  %86 = icmp ne i32 %85, 0
  %87 = zext i1 %86 to i64
  %88 = select i1 %86, i32 0, i32 -1016
  store i32 %88, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %89

89:                                               ; preds = %77, %76, %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %90

90:                                               ; preds = %89, %50, %40, %30, %20, %16, %12
  %91 = load i32, ptr %4, align 4
  ret i32 %91
}

; 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 i32 @cpGFpSqrt(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_cpGFp", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"_cpGFpElement", !11, i64 0, !11, i64 4, !6, i64 8}
!14 = !{!10, !6, i64 8}
!15 = !{!16, !6, i64 0}
!16 = !{!"_gsModEngine", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !17, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !11, i64 96, !11, i64 100, !6, i64 104}
!17 = !{!"long long", !7, i64 0}
!18 = !{!13, !11, i64 4}
!19 = !{!16, !11, i64 16}
!20 = !{!13, !6, i64 8}


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

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

13:                                               ; preds = %7
  %14 = load i32, ptr %0, align 8, !tbaa !11
  %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, 1129136456
  br i1 %18, label %19, label %45

19:                                               ; preds = %13
  %20 = load i32, ptr %1, align 8, !tbaa !11
  %21 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %1)
  %22 = trunc i64 %21 to i32
  %23 = xor i32 %20, %22
  %24 = icmp eq i32 %23, 1129136456
  br i1 %24, label %25, label %45

25:                                               ; preds = %19
  %26 = getelementptr inbounds i8, ptr %2, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = icmp eq ptr %28, null
  br i1 %29, label %30, label %45

30:                                               ; preds = %25
  %31 = getelementptr inbounds i8, ptr %0, i64 4
  %32 = load i32, ptr %31, align 4, !tbaa !17
  %33 = getelementptr inbounds i8, ptr %27, i64 16
  %34 = load i32, ptr %33, align 8, !tbaa !18
  %.not = icmp eq i32 %32, %34
  br i1 %.not, label %35, label %45

35:                                               ; preds = %30
  %36 = getelementptr inbounds i8, ptr %1, i64 4
  %37 = load i32, ptr %36, align 4, !tbaa !17
  %.not22 = icmp eq i32 %37, %32
  br i1 %.not22, label %38, label %45

38:                                               ; preds = %35
  %39 = getelementptr inbounds i8, ptr %1, i64 8
  %40 = load ptr, ptr %39, align 8, !tbaa !19
  %41 = getelementptr inbounds i8, ptr %0, i64 8
  %42 = load ptr, ptr %41, align 8, !tbaa !19
  %43 = tail call i32 @cpGFpSqrt(ptr noundef %40, ptr noundef %42, ptr noundef nonnull %27) #3
  %.not23 = icmp eq i32 %43, 0
  %44 = select i1 %.not23, i32 -1016, i32 0
  br label %45

45:                                               ; preds = %38, %25, %35, %30, %19, %13, %7, %3
  %.1 = phi i32 [ -8, %3 ], [ -13, %7 ], [ -13, %13 ], [ -13, %19 ], [ %44, %38 ], [ -5, %25 ], [ -11, %35 ], [ -11, %30 ]
  ret i32 %.1
}

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

declare i32 @cpGFpSqrt(ptr noundef, ptr 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 = !{!"_cpGFp", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"_cpGFpElement", !7, i64 0, !7, i64 4, !10, i64 8}
!13 = !{!6, !10, i64 8}
!14 = !{!15, !10, i64 0}
!15 = !{!"_gsModEngine", !10, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !16, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !7, i64 96, !7, i64 100, !10, i64 104}
!16 = !{!"long long", !8, i64 0}
!17 = !{!12, !7, i64 4}
!18 = !{!15, !7, i64 16}
!19 = !{!12, !10, i64 8}


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