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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gfec_CheckPrivateKey(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._cpGFpEC, ptr %13, i32 0, i32 13
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct._gsModEngine, ptr %15, i32 0, i32 8
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  store ptr %17, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._cpGFpEC, ptr %18, i32 0, i32 5
  %20 = load i32, ptr %19, align 8, !tbaa !15
  %21 = add nsw i32 %20, 64
  %22 = sub nsw i32 %21, 1
  %23 = sdiv i32 %22, 64
  store i32 %23, ptr %6, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._cpBigNum, ptr %24, i32 0, i32 4
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  store ptr %26, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._cpBigNum, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %28, align 8, !tbaa !19
  store i32 %29, ptr %8, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._cpGFpEC, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !20
  store ptr %32, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._cpGFp, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !21
  store ptr %35, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = call ptr @gsModPoolAlloc(ptr noundef %36, i32 noundef 1)
  store ptr %37, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._cpBigNum, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !23
  %41 = icmp eq i32 %40, 1
  %42 = zext i1 %41 to i32
  store i32 %42, ptr %12, align 4, !tbaa !16
  %43 = load i32, ptr %12, align 4, !tbaa !16
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %51

45:                                               ; preds = %2
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = call i32 @IsZero_BN(ptr noundef %46)
  %48 = icmp ne i32 %47, 0
  %49 = xor i1 %48, true
  %50 = zext i1 %49 to i32
  store i32 %50, ptr %12, align 4, !tbaa !16
  br label %51

51:                                               ; preds = %45, %2
  %52 = load i32, ptr %12, align 4, !tbaa !16
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %62

54:                                               ; preds = %51
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._cpGFpEC, ptr %55, i32 0, i32 5
  %57 = load i32, ptr %56, align 8, !tbaa !15
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = call i32 @cpBN_bitsize(ptr noundef %58)
  %60 = icmp sge i32 %57, %59
  %61 = zext i1 %60 to i32
  store i32 %61, ptr %12, align 4, !tbaa !16
  br label %62

62:                                               ; preds = %54, %51
  %63 = load i32, ptr %12, align 4, !tbaa !16
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %78

65:                                               ; preds = %62
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = load i32, ptr %6, align 4, !tbaa !16
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load i32, ptr %8, align 4, !tbaa !16
  %70 = call ptr @cpGFpElementCopyPad(ptr noundef %66, i32 noundef %67, ptr noundef %68, i32 noundef %69)
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  %72 = load ptr, ptr %11, align 8, !tbaa !5
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = load i32, ptr %6, align 4, !tbaa !16
  %75 = call i64 @cpSub_BNU(ptr noundef %71, ptr noundef %72, ptr noundef %73, i32 noundef %74)
  %76 = icmp ne i64 0, %75
  %77 = zext i1 %76 to i32
  store i32 %77, ptr %12, align 4, !tbaa !16
  br label %78

78:                                               ; preds = %65, %62
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  call void @gsModPoolFree(ptr noundef %79, i32 noundef 1)
  %80 = load i32, ptr %12, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret i32 %80
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @IsZero_BN(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cpBN_bitsize(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @cpGFpElementCopyPad(ptr noundef, i32 noundef, ptr noundef, i32 noundef) #2

declare i64 @cpSub_BNU(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @gsModPoolFree(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, !6, i64 80}
!10 = !{!"_cpGFpEC", !11, i64 0, !11, i64 4, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !11, i64 64, !11, i64 68, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 48}
!13 = !{!"_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, !14, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !11, i64 96, !11, i64 100, !6, i64 104}
!14 = !{!"long long", !7, i64 0}
!15 = !{!10, !11, i64 24}
!16 = !{!11, !11, i64 0}
!17 = !{!18, !6, i64 16}
!18 = !{!"_cpBigNum", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24}
!19 = !{!18, !11, i64 8}
!20 = !{!10, !6, i64 8}
!21 = !{!22, !6, i64 8}
!22 = !{!"_cpGFp", !11, i64 0, !11, i64 4, !6, i64 8}
!23 = !{!18, !11, 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 0, 2) i32 @gfec_CheckPrivateKey(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 80
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 48
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %1, i64 24
  %8 = load i32, ptr %7, align 8, !tbaa !14
  %9 = add nsw i32 %8, 63
  %10 = sdiv i32 %9, 64
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load i32, ptr %13, align 8, !tbaa !17
  %15 = getelementptr inbounds i8, ptr %1, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !19
  %19 = tail call ptr @gsModPoolAlloc(ptr noundef %18, i32 noundef 1)
  %20 = getelementptr inbounds i8, ptr %0, i64 4
  %21 = load i32, ptr %20, align 4, !tbaa !21
  %22 = icmp eq i32 %21, 1
  br i1 %22, label %23, label %.critedge

23:                                               ; preds = %2
  %24 = tail call i32 @IsZero_BN(ptr noundef nonnull %0)
  %.not = icmp eq i32 %24, 0
  br i1 %.not, label %25, label %.critedge

25:                                               ; preds = %23
  %26 = load i32, ptr %7, align 8, !tbaa !14
  %27 = tail call i32 @cpBN_bitsize(ptr noundef nonnull %0)
  %.not24 = icmp slt i32 %26, %27
  br i1 %.not24, label %.critedge, label %28

28:                                               ; preds = %25
  %29 = tail call ptr @cpGFpElementCopyPad(ptr noundef %19, i32 noundef %10, ptr noundef %12, i32 noundef %14)
  %30 = tail call i64 @cpSub_BNU(ptr noundef %19, ptr noundef %19, ptr noundef %6, i32 noundef %10) #3
  %31 = icmp ne i64 %30, 0
  %32 = zext i1 %31 to i32
  br label %.critedge

.critedge:                                        ; preds = %2, %23, %28, %25
  %.2 = phi i32 [ %32, %28 ], [ 0, %25 ], [ 0, %23 ], [ 0, %2 ]
  tail call void @gsModPoolFree(ptr noundef %18, i32 noundef 1)
  ret i32 %.2
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @gsModPoolAlloc(ptr noundef, i32 noundef) local_unnamed_addr #1

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @cpGFpElementCopyPad(ptr noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare i64 @cpSub_BNU(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @gsModPoolFree(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, !10, i64 80}
!6 = !{!"_cpGFpEC", !7, i64 0, !7, i64 4, !10, i64 8, !7, i64 16, !7, i64 20, !7, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !7, i64 64, !7, i64 68, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !10, i64 48}
!12 = !{!"_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, !13, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !7, i64 96, !7, i64 100, !10, i64 104}
!13 = !{!"long long", !8, i64 0}
!14 = !{!6, !7, i64 24}
!15 = !{!16, !10, i64 16}
!16 = !{!"_cpBigNum", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !10, i64 24}
!17 = !{!16, !7, i64 8}
!18 = !{!6, !10, i64 8}
!19 = !{!20, !10, i64 8}
!20 = !{!"_cpGFp", !7, i64 0, !7, i64 4, !10, i64 8}
!21 = !{!16, !7, i64 4}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass