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

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

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

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

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

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

31:                                               ; preds = %22
  store i32 -13, ptr %5, align 4
  br label %121

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

41:                                               ; preds = %32
  store i32 -13, ptr %5, align 4
  br label %121

42:                                               ; preds = %32
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %49, label %45

45:                                               ; preds = %42
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = icmp slt i32 0, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %45
  store i32 -8, ptr %5, align 4
  br label %121

49:                                               ; preds = %45, %42
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %64

52:                                               ; preds = %49
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = icmp sle i32 0, %53
  br i1 %54, label %55, label %63

55:                                               ; preds = %52
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._cpGFp, ptr %57, i32 0, i32 2
  %59 = load ptr, ptr %58, align 8, !tbaa !15
  %60 = getelementptr inbounds %struct._gsModEngine, ptr %59, i32 0, i32 4
  %61 = load i32, ptr %60, align 4, !tbaa !16
  %62 = icmp sle i32 %56, %61
  br i1 %62, label %64, label %63

63:                                               ; preds = %55, %52
  store i32 -6, ptr %5, align 4
  br label %121

64:                                               ; preds = %55, %49
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._cpGFpElement, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 4, !tbaa !19
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._cpGFp, ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !15
  %71 = getelementptr inbounds %struct._gsModEngine, ptr %70, i32 0, i32 3
  %72 = load i32, ptr %71, align 8, !tbaa !20
  %73 = icmp ne i32 %67, %72
  br i1 %73, label %74, label %75

74:                                               ; preds = %64
  store i32 -11, ptr %5, align 4
  br label %121

75:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct._cpGFp, ptr %76, i32 0, i32 2
  %78 = load ptr, ptr %77, align 8, !tbaa !15
  store ptr %78, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %79 = load ptr, ptr %11, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct._gsModEngine, ptr %79, i32 0, i32 3
  %81 = load i32, ptr %80, align 8, !tbaa !20
  store i32 %81, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %82 = load ptr, ptr %11, align 8, !tbaa !5
  %83 = call ptr @gsModPoolAlloc(ptr noundef %82, i32 noundef 1)
  store ptr %83, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %84

84:                                               ; preds = %93, %75
  %85 = load i32, ptr %14, align 4, !tbaa !9
  %86 = load i32, ptr %12, align 4, !tbaa !9
  %87 = icmp slt i32 %85, %86
  br i1 %87, label %88, label %96

88:                                               ; preds = %84
  %89 = load ptr, ptr %13, align 8, !tbaa !5
  %90 = load i32, ptr %14, align 4, !tbaa !9
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds i64, ptr %89, i64 %91
  store i64 0, ptr %92, align 8, !tbaa !21
  br label %93

93:                                               ; preds = %88
  %94 = load i32, ptr %14, align 4, !tbaa !9
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %14, align 4, !tbaa !9
  br label %84, !llvm.loop !22

96:                                               ; preds = %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  %98 = icmp ne ptr %97, null
  br i1 %98, label %99, label %108

99:                                               ; preds = %96
  %100 = load i32, ptr %7, align 4, !tbaa !9
  %101 = icmp ne i32 %100, 0
  br i1 %101, label %102, label %108

102:                                              ; preds = %99
  %103 = load ptr, ptr %13, align 8, !tbaa !5
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  %105 = load i32, ptr %7, align 4, !tbaa !9
  %106 = load ptr, ptr %11, align 8, !tbaa !5
  %107 = call i32 @cpGFpxCopyToChunk(ptr noundef %103, ptr noundef %104, i32 noundef %105, ptr noundef %106)
  br label %108

108:                                              ; preds = %102, %99, %96
  %109 = load ptr, ptr %8, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct._cpGFpElement, ptr %109, i32 0, i32 2
  %111 = load ptr, ptr %110, align 8, !tbaa !24
  %112 = load ptr, ptr %13, align 8, !tbaa !5
  %113 = load i32, ptr %12, align 4, !tbaa !9
  %114 = load ptr, ptr %11, align 8, !tbaa !5
  %115 = call ptr @cpGFpxSet(ptr noundef %111, ptr noundef %112, i32 noundef %113, ptr noundef %114)
  %116 = icmp ne ptr %115, null
  br i1 %116, label %118, label %117

117:                                              ; preds = %108
  store i32 -11, ptr %10, align 4, !tbaa !9
  br label %118

118:                                              ; preds = %117, %108
  %119 = load ptr, ptr %11, align 8, !tbaa !5
  call void @gsModPoolFree(ptr noundef %119, i32 noundef 1)
  %120 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %120, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  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 4, ptr %10) #4
  br label %121

121:                                              ; preds = %118, %74, %63, %48, %41, %31, %21, %17
  %122 = load i32, ptr %5, align 4
  ret i32 %122
}

; 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

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @gsModPoolFree(ptr noundef, i32 noundef) #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 = { 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 = !{!17, !10, i64 20}
!17 = !{!"_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, !18, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !10, i64 96, !10, i64 100, !6, i64 104}
!18 = !{!"long long", !7, i64 0}
!19 = !{!14, !10, i64 4}
!20 = !{!17, !10, i64 16}
!21 = !{!18, !18, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!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 @ippsGFpSetElement(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %2, null
  %6 = icmp eq ptr %3, null
  %or.cond46 = or i1 %5, %6
  br i1 %or.cond46, label %49, label %7

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

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

19:                                               ; preds = %13
  %20 = icmp eq ptr %0, null
  %21 = icmp sgt i32 %1, 0
  %or.cond = and i1 %20, %21
  br i1 %or.cond, label %49, label %22

22:                                               ; preds = %19
  %23 = icmp ne ptr %0, null
  br i1 %23, label %24, label %._crit_edge49

._crit_edge49:                                    ; preds = %22
  %.phi.trans.insert = getelementptr inbounds i8, ptr %3, i64 8
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !13
  br label %31

24:                                               ; preds = %22
  %25 = icmp sgt i32 %1, -1
  br i1 %25, label %26, label %49

26:                                               ; preds = %24
  %27 = getelementptr inbounds i8, ptr %3, i64 8
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %28, i64 20
  %30 = load i32, ptr %29, align 4, !tbaa !14
  %.not = icmp slt i32 %30, %1
  br i1 %.not, label %49, label %31

31:                                               ; preds = %._crit_edge49, %26
  %32 = phi ptr [ %.pre, %._crit_edge49 ], [ %28, %26 ]
  %33 = getelementptr inbounds i8, ptr %2, i64 4
  %34 = load i32, ptr %33, align 4, !tbaa !17
  %35 = getelementptr inbounds i8, ptr %32, i64 16
  %36 = load i32, ptr %35, align 8, !tbaa !18
  %.not44 = icmp eq i32 %34, %36
  br i1 %.not44, label %37, label %49

37:                                               ; preds = %31
  %38 = tail call ptr @gsModPoolAlloc(ptr noundef nonnull %32, i32 noundef 1)
  %39 = icmp sgt i32 %34, 0
  br i1 %39, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %37
  %40 = zext nneg i32 %34 to i64
  %41 = shl nuw nsw i64 %40, 3
  tail call void @llvm.memset.p0.i64(ptr align 8 %38, i8 0, i64 %41, i1 false), !tbaa !19
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %37
  %42 = icmp ne i32 %1, 0
  %or.cond3 = and i1 %23, %42
  br i1 %or.cond3, label %43, label %45

43:                                               ; preds = %._crit_edge
  %44 = tail call i32 @cpGFpxCopyToChunk(ptr noundef %38, ptr noundef nonnull %0, i32 noundef %1, ptr noundef nonnull %32)
  br label %45

45:                                               ; preds = %43, %._crit_edge
  %46 = getelementptr inbounds i8, ptr %2, i64 8
  %47 = load ptr, ptr %46, align 8, !tbaa !20
  %48 = tail call ptr @cpGFpxSet(ptr noundef %47, ptr noundef %38, i32 noundef %34, ptr noundef nonnull %32) #4
  %.not45 = icmp eq ptr %48, null
  %spec.select = select i1 %.not45, i32 -11, i32 0
  tail call void @gsModPoolFree(ptr noundef nonnull %32, i32 noundef 1)
  br label %49

49:                                               ; preds = %31, %24, %26, %19, %13, %7, %4, %45
  %.037 = phi i32 [ %spec.select, %45 ], [ -8, %4 ], [ -13, %7 ], [ -13, %13 ], [ -8, %19 ], [ -6, %26 ], [ -6, %24 ], [ -11, %31 ]
  ret i32 %.037
}

; 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

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }
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, !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, !7, i64 20}
!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 = !{!16, !16, i64 0}
!20 = !{!12, !10, i64 8}


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