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

; 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._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 ptr @cpGFpxSet(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %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 ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  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
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._gsModEngine, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %27

21:                                               ; preds = %4
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = call ptr @cpGFpSet(ptr noundef %22, ptr noundef %23, i32 noundef %24, ptr noundef %25)
  store ptr %26, ptr %5, align 8
  br label %86

27:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = call ptr @cpGFpBasic(ptr noundef %28)
  store ptr %29, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._gsModEngine, ptr %30, i32 0, i32 3
  %32 = load i32, ptr %31, align 8, !tbaa !14
  store i32 %32, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %33, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = call i32 @cpGFpBasicDegreeExtension(ptr noundef %34)
  store i32 %35, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 0, ptr %14, align 4, !tbaa !9
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %74, %27
  %37 = load i32, ptr %14, align 4, !tbaa !9
  %38 = load i32, ptr %13, align 4, !tbaa !9
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %44

40:                                               ; preds = %36
  %41 = load i32, ptr %15, align 4, !tbaa !9
  %42 = icmp ne i32 %41, 0
  %43 = xor i1 %42, true
  br label %44

44:                                               ; preds = %40, %36
  %45 = phi i1 [ false, %36 ], [ %43, %40 ]
  br i1 %45, label %46, label %77

46:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = load i32, ptr %11, align 4, !tbaa !9
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %46
  %51 = load i32, ptr %8, align 4, !tbaa !9
  br label %54

52:                                               ; preds = %46
  %53 = load i32, ptr %11, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %52, %50
  %55 = phi i32 [ %51, %50 ], [ %53, %52 ]
  store i32 %55, ptr %16, align 4, !tbaa !9
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = load i32, ptr %16, align 4, !tbaa !9
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = call ptr @cpGFpSet(ptr noundef %56, ptr noundef %57, i32 noundef %58, ptr noundef %59)
  %61 = icmp eq ptr null, %60
  %62 = zext i1 %61 to i32
  store i32 %62, ptr %15, align 4, !tbaa !9
  %63 = load i32, ptr %11, align 4, !tbaa !9
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = sext i32 %63 to i64
  %66 = getelementptr inbounds i64, ptr %64, i64 %65
  store ptr %66, ptr %12, align 8, !tbaa !5
  %67 = load i32, ptr %16, align 4, !tbaa !9
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = sext i32 %67 to i64
  %70 = getelementptr inbounds i64, ptr %68, i64 %69
  store ptr %70, ptr %7, align 8, !tbaa !5
  %71 = load i32, ptr %16, align 4, !tbaa !9
  %72 = load i32, ptr %8, align 4, !tbaa !9
  %73 = sub nsw i32 %72, %71
  store i32 %73, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %74

74:                                               ; preds = %54
  %75 = load i32, ptr %14, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %14, align 4, !tbaa !9
  br label %36, !llvm.loop !15

77:                                               ; preds = %44
  %78 = load i32, ptr %14, align 4, !tbaa !9
  %79 = load i32, ptr %13, align 4, !tbaa !9
  %80 = icmp slt i32 %78, %79
  br i1 %80, label %81, label %82

81:                                               ; preds = %77
  br label %84

82:                                               ; preds = %77
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  br label %84

84:                                               ; preds = %82, %81
  %85 = phi ptr [ null, %81 ], [ %83, %82 ]
  store ptr %85, ptr %5, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %86

86:                                               ; preds = %84, %21
  %87 = load ptr, ptr %5, align 8
  ret ptr %87
}

declare ptr @cpGFpSet(ptr noundef, ptr noundef, i32 noundef, 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 @cpGFpBasic(ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cpGFpBasicDegreeExtension(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 = { "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 = { 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 #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, !6, i64 0}
!12 = !{!"_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, !13, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !10, i64 96, !10, i64 100, !6, i64 104}
!13 = !{!"long long", !7, i64 0}
!14 = !{!12, !10, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; 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 ptr @cpGFpxSet(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %9

7:                                                ; preds = %4
  %8 = tail call ptr @cpGFpSet(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef nonnull %3) #4
  br label %._crit_edge

9:                                                ; preds = %4
  %10 = tail call ptr @cpGFpBasic(ptr noundef nonnull %3)
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %12 = load i32, ptr %11, align 8, !tbaa !12
  %13 = tail call i32 @cpGFpBasicDegreeExtension(ptr noundef nonnull %3)
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %9
  %15 = sext i32 %12 to i64
  br label %16

16:                                               ; preds = %.lr.ph, %16
  %.03138 = phi i32 [ 0, %.lr.ph ], [ %24, %16 ]
  %.03237 = phi ptr [ %1, %.lr.ph ], [ %22, %16 ]
  %.03336 = phi ptr [ %0, %.lr.ph ], [ %20, %16 ]
  %.03435 = phi i32 [ %2, %.lr.ph ], [ %23, %16 ]
  %17 = tail call i32 @llvm.smin.i32(i32 %.03435, i32 %12)
  %18 = tail call ptr @cpGFpSet(ptr noundef %.03336, ptr noundef %.03237, i32 noundef %17, ptr noundef %10) #4
  %19 = icmp ne ptr %18, null
  %20 = getelementptr inbounds i64, ptr %.03336, i64 %15
  %21 = sext i32 %17 to i64
  %22 = getelementptr inbounds i64, ptr %.03237, i64 %21
  %23 = sub nsw i32 %.03435, %17
  %24 = add nuw nsw i32 %.03138, 1
  %25 = icmp slt i32 %24, %13
  %26 = select i1 %25, i1 %19, i1 false
  br i1 %26, label %16, label %._crit_edge.loopexit, !llvm.loop !13

._crit_edge.loopexit:                             ; preds = %16
  %27 = select i1 %25, ptr null, ptr %0
  br label %._crit_edge

._crit_edge:                                      ; preds = %9, %._crit_edge.loopexit, %7
  %.0 = phi ptr [ %8, %7 ], [ %0, %9 ], [ %27, %._crit_edge.loopexit ]
  ret ptr %.0
}

declare ptr @cpGFpSet(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #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 = { "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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"_gsModEngine", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !11, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !10, i64 96, !10, i64 100, !7, i64 104}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long long", !8, i64 0}
!12 = !{!6, !10, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass