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

; 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 @ippsGFpGetElement(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp eq ptr null, %14
  br i1 %15, label %16, label %17

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

17:                                               ; preds = %4
  %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 %5, align 4
  br label %86

21:                                               ; preds = %17
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = icmp eq ptr null, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  store i32 -8, ptr %5, align 4
  br label %86

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

34:                                               ; preds = %25
  store i32 -13, ptr %5, align 4
  br label %86

35:                                               ; preds = %25
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._cpGFpElement, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !13
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = call i64 @IPP_UINT_PTR(ptr noundef %39)
  %41 = trunc i64 %40 to i32
  %42 = xor i32 %38, %41
  %43 = icmp eq i32 %42, 1129136456
  br i1 %43, label %45, label %44

44:                                               ; preds = %35
  store i32 -13, ptr %5, align 4
  br label %86

45:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._cpGFp, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !15
  store ptr %48, ptr %10, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._cpGFpElement, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !16
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._gsModEngine, ptr %52, i32 0, i32 3
  %54 = load i32, ptr %53, align 8, !tbaa !17
  %55 = icmp ne i32 %51, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %45
  store i32 -11, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %85

57:                                               ; preds = %45
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = icmp slt i32 0, %58
  br i1 %59, label %60, label %66

60:                                               ; preds = %57
  %61 = load i32, ptr %8, align 4, !tbaa !9
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._gsModEngine, ptr %62, i32 0, i32 4
  %64 = load i32, ptr %63, align 4, !tbaa !20
  %65 = icmp sge i32 %61, %64
  br i1 %65, label %67, label %66

66:                                               ; preds = %60, %57
  store i32 -6, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %85

67:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._gsModEngine, ptr %68, i32 0, i32 3
  %70 = load i32, ptr %69, align 8, !tbaa !17
  store i32 %70, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = call ptr @gsModPoolAlloc(ptr noundef %71, i32 noundef 1)
  store ptr %72, ptr %13, align 8, !tbaa !5
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  %74 = load i32, ptr %12, align 4, !tbaa !9
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._cpGFpElement, ptr %75, i32 0, i32 2
  %77 = load ptr, ptr %76, align 8, !tbaa !21
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = call ptr @cpGFpxGet(ptr noundef %73, i32 noundef %74, ptr noundef %77, ptr noundef %78)
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = load ptr, ptr %13, align 8, !tbaa !5
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  %83 = call i32 @cpGFpxCopyFromChunk(ptr noundef %80, ptr noundef %81, ptr noundef %82)
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  call void @gsModPoolFree(ptr noundef %84, i32 noundef 1)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %85

85:                                               ; preds = %67, %66, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %86

86:                                               ; preds = %85, %44, %34, %24, %20, %16
  %87 = load i32, ptr %5, align 4
  ret i32 %87
}

; 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

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

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

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

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

; 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_cpGFp", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = !{!14, !10, i64 0}
!14 = !{!"_cpGFpElement", !10, i64 0, !10, i64 4, !6, i64 8}
!15 = !{!12, !6, i64 8}
!16 = !{!14, !10, i64 4}
!17 = !{!18, !10, i64 16}
!18 = !{!"_gsModEngine", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !19, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !10, i64 96, !10, i64 100, !6, i64 104}
!19 = !{!"long long", !7, i64 0}
!20 = !{!18, !10, i64 20}
!21 = !{!14, !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 -13, 1) i32 @ippsGFpGetElement(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %0, null
  %6 = icmp eq ptr %1, null
  %or.cond = or i1 %5, %6
  %7 = icmp eq ptr %3, null
  %or.cond29 = or i1 %or.cond, %7
  br i1 %or.cond29, label %38, label %8

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

14:                                               ; preds = %8
  %15 = load i32, ptr %0, align 8, !tbaa !11
  %16 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %0)
  %17 = trunc i64 %16 to i32
  %18 = xor i32 %15, %17
  %19 = icmp eq i32 %18, 1129136456
  br i1 %19, label %20, label %38

20:                                               ; preds = %14
  %21 = getelementptr inbounds i8, ptr %3, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = getelementptr inbounds i8, ptr %0, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !14
  %25 = getelementptr inbounds i8, ptr %22, i64 16
  %26 = load i32, ptr %25, align 8, !tbaa !15
  %.not = icmp eq i32 %24, %26
  br i1 %.not, label %27, label %38

27:                                               ; preds = %20
  %28 = icmp sgt i32 %2, 0
  br i1 %28, label %29, label %38

29:                                               ; preds = %27
  %30 = getelementptr inbounds i8, ptr %22, i64 20
  %31 = load i32, ptr %30, align 4, !tbaa !18
  %.not28 = icmp sgt i32 %31, %2
  br i1 %.not28, label %38, label %32

32:                                               ; preds = %29
  %33 = tail call ptr @gsModPoolAlloc(ptr noundef nonnull %22, i32 noundef 1)
  %34 = getelementptr inbounds i8, ptr %0, i64 8
  %35 = load ptr, ptr %34, align 8, !tbaa !19
  %36 = tail call ptr @cpGFpxGet(ptr noundef %33, i32 noundef %24, ptr noundef %35, ptr noundef nonnull %22) #3
  %37 = tail call i32 @cpGFpxCopyFromChunk(ptr noundef nonnull %1, ptr noundef %33, ptr noundef nonnull %22)
  tail call void @gsModPoolFree(ptr noundef nonnull %22, i32 noundef 1)
  br label %38

38:                                               ; preds = %32, %20, %29, %27, %14, %8, %4
  %.1 = phi i32 [ -8, %4 ], [ -13, %8 ], [ -13, %14 ], [ 0, %32 ], [ -11, %20 ], [ -6, %29 ], [ -6, %27 ]
  ret i32 %.1
}

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

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

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

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

; 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, !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 = !{!12, !7, i64 4}
!15 = !{!16, !7, i64 16}
!16 = !{!"_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, !17, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !7, i64 96, !7, i64 100, !10, i64 104}
!17 = !{!"long long", !8, i64 0}
!18 = !{!16, !7, i64 20}
!19 = !{!12, !10, i64 8}


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