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

; 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._cpStateECES_SM2 = type { i32, ptr, i32, i32, i32, [32 x i8], i8, i8, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @ippsGFpECESFinal_SM2(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 [32 x i8], align 16
  %9 = 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
  %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 %99

13:                                               ; preds = %3
  %14 = load ptr, ptr %7, 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 %99

17:                                               ; preds = %13
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._cpStateECES_SM2, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = load ptr, ptr %7, 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, 1129136468
  br i1 %25, label %27, label %26

26:                                               ; preds = %17
  store i32 -13, ptr %4, align 4
  br label %99

27:                                               ; preds = %17
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._cpStateECES_SM2, ptr %28, i32 0, i32 3
  %30 = load i32, ptr %29, align 4, !tbaa !13
  %31 = icmp ne i32 %30, 2
  br i1 %31, label %32, label %33

32:                                               ; preds = %27
  store i32 -1013, ptr %4, align 4
  br label %99

33:                                               ; preds = %27
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %39, label %36

36:                                               ; preds = %33
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = icmp sgt i32 %37, 32
  br i1 %38, label %39, label %40

39:                                               ; preds = %36, %33
  store i32 -6, ptr %4, align 4
  br label %99

40:                                               ; preds = %36
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._cpStateECES_SM2, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._cpStateECES_SM2, ptr %44, i32 0, i32 2
  %46 = load i32, ptr %45, align 8, !tbaa !15
  %47 = sdiv i32 %46, 2
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %43, i64 %48
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._cpStateECES_SM2, ptr %50, i32 0, i32 2
  %52 = load i32, ptr %51, align 8, !tbaa !15
  %53 = sdiv i32 %52, 2
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._cpStateECES_SM2, ptr %54, i32 0, i32 9
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = call i32 @ippsHashUpdate_rmf(ptr noundef %49, i32 noundef %53, ptr noundef %56)
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = icmp eq i32 %58, 32
  br i1 %59, label %60, label %66

60:                                               ; preds = %40
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._cpStateECES_SM2, ptr %62, i32 0, i32 9
  %64 = load ptr, ptr %63, align 8, !tbaa !16
  %65 = call i32 @ippsHashFinal_rmf(ptr noundef %61, ptr noundef %64)
  br label %89

66:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %67 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._cpStateECES_SM2, ptr %68, i32 0, i32 9
  %70 = load ptr, ptr %69, align 8, !tbaa !16
  %71 = call i32 @ippsHashFinal_rmf(ptr noundef %67, ptr noundef %70)
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %72

72:                                               ; preds = %85, %66
  %73 = load i32, ptr %9, align 4, !tbaa !9
  %74 = load i32, ptr %6, align 4, !tbaa !9
  %75 = icmp slt i32 %73, %74
  br i1 %75, label %76, label %88

76:                                               ; preds = %72
  %77 = load i32, ptr %9, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 %78
  %80 = load i8, ptr %79, align 1, !tbaa !17
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load i32, ptr %9, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds i8, ptr %81, i64 %83
  store i8 %80, ptr %84, align 1, !tbaa !17
  br label %85

85:                                               ; preds = %76
  %86 = load i32, ptr %9, align 4, !tbaa !9
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %9, align 4, !tbaa !9
  br label %72, !llvm.loop !18

88:                                               ; preds = %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #4
  br label %89

89:                                               ; preds = %88, %60
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct._cpStateECES_SM2, ptr %90, i32 0, i32 3
  store i32 3, ptr %91, align 4, !tbaa !13
  %92 = load ptr, ptr %7, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct._cpStateECES_SM2, ptr %92, i32 0, i32 6
  %94 = load i8, ptr %93, align 4, !tbaa !20
  %95 = zext i8 %94 to i32
  %96 = icmp ne i32 %95, 0
  %97 = zext i1 %96 to i64
  %98 = select i1 %96, i32 0, i32 -1009
  store i32 %98, ptr %4, align 4
  br label %99

99:                                               ; preds = %89, %39, %32, %26, %16, %12
  %100 = load i32, ptr %4, align 4
  ret i32 %100
}

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

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

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

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

; 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 = !{!"_cpStateECES_SM2", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !7, i64 28, !7, i64 60, !7, i64 61, !6, i64 64, !6, i64 72}
!13 = !{!12, !10, i64 20}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !10, i64 16}
!16 = !{!12, !6, i64 72}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!12, !7, i64 60}


; 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 -1013, 1) i32 @ippsGFpECESFinal_SM2(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca [32 x i8], align 16
  %5 = icmp eq ptr %0, null
  %6 = icmp eq ptr %2, null
  %or.cond29 = or i1 %5, %6
  br i1 %or.cond29, label %40, 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, 1129136468
  br i1 %12, label %13, label %40

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %2, i64 20
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %.not = icmp eq i32 %15, 2
  br i1 %.not, label %16, label %40

16:                                               ; preds = %13
  %or.cond = icmp ugt i32 %1, 32
  br i1 %or.cond, label %40, label %17

17:                                               ; preds = %16
  %18 = getelementptr inbounds i8, ptr %2, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %2, i64 16
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = sdiv i32 %21, 2
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %19, i64 %23
  %25 = getelementptr inbounds i8, ptr %2, i64 72
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = tail call i32 @ippsHashUpdate_rmf(ptr noundef %24, i32 noundef %22, ptr noundef %26) #5
  %28 = icmp eq i32 %1, 32
  br i1 %28, label %29, label %32

29:                                               ; preds = %17
  %30 = load ptr, ptr %25, align 8, !tbaa !14
  %31 = tail call i32 @ippsHashFinal_rmf(ptr noundef nonnull %0, ptr noundef %30) #5
  br label %36

32:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #5
  %33 = load ptr, ptr %25, align 8, !tbaa !14
  %34 = call i32 @ippsHashFinal_rmf(ptr noundef nonnull %4, ptr noundef %33) #5
  %.not31 = icmp eq i32 %1, 0
  br i1 %.not31, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %32
  %35 = zext nneg i32 %1 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %0, ptr nonnull align 16 %4, i64 %35, i1 false), !tbaa !15
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %32
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #5
  br label %36

36:                                               ; preds = %._crit_edge, %29
  store i32 3, ptr %14, align 4, !tbaa !11
  %37 = getelementptr inbounds i8, ptr %2, i64 60
  %38 = load i8, ptr %37, align 4, !tbaa !16
  %.not28 = icmp eq i8 %38, 0
  %39 = select i1 %.not28, i32 -1009, i32 0
  br label %40

40:                                               ; preds = %16, %13, %7, %3, %36
  %.024 = phi i32 [ %39, %36 ], [ -8, %3 ], [ -13, %7 ], [ -1013, %13 ], [ -6, %16 ]
  ret i32 %.024
}

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

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

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, 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 = { "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"_cpStateECES_SM2", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 20, !7, i64 24, !8, i64 28, !8, i64 60, !8, i64 61, !10, i64 64, !10, i64 72}
!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 20}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !7, i64 16}
!14 = !{!6, !10, i64 72}
!15 = !{!8, !8, i64 0}
!16 = !{!6, !8, i64 60}


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