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

; 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 @cpGFpxGet(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %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
  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
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = call ptr @cpGFpElementPad(ptr noundef %16, i32 noundef %17, i64 noundef 0)
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._gsModEngine, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %29

23:                                               ; preds = %4
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = call ptr @cpGFpGet(ptr noundef %24, i32 noundef %25, ptr noundef %26, ptr noundef %27)
  store ptr %28, ptr %5, align 8
  br label %78

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

38:                                               ; preds = %73, %29
  %39 = load i32, ptr %14, align 4, !tbaa !9
  %40 = load i32, ptr %13, align 4, !tbaa !9
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %42, label %45

42:                                               ; preds = %38
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = icmp sgt i32 %43, 0
  br label %45

45:                                               ; preds = %42, %38
  %46 = phi i1 [ false, %38 ], [ %44, %42 ]
  br i1 %46, label %47, label %76

47:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %51, label %53

51:                                               ; preds = %47
  %52 = load i32, ptr %7, align 4, !tbaa !9
  br label %55

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

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

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

76:                                               ; preds = %45
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %77, ptr %5, align 8
  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 %78

78:                                               ; preds = %76, %23
  %79 = load ptr, ptr %5, align 8
  ret ptr %79
}

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

declare ptr @cpGFpGet(ptr noundef, i32 noundef, 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: inlinehint nounwind uwtable
declare hidden ptr @cpGFpBasic(ptr noundef) #1

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

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

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

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

.lr.ph:                                           ; preds = %10
  %18 = sext i32 %13 to i64
  br label %19

19:                                               ; preds = %.lr.ph, %19
  %.03037 = phi i32 [ 0, %.lr.ph ], [ %26, %19 ]
  %.03136 = phi i32 [ %1, %.lr.ph ], [ %25, %19 ]
  %.03235 = phi ptr [ %0, %.lr.ph ], [ %24, %19 ]
  %.03334 = phi ptr [ %2, %.lr.ph ], [ %22, %19 ]
  %20 = tail call i32 @llvm.smin.i32(i32 %.03136, i32 %13)
  %21 = tail call ptr @cpGFpGet(ptr noundef %.03235, i32 noundef %20, ptr noundef %.03334, ptr noundef %11) #4
  %22 = getelementptr inbounds i64, ptr %.03334, i64 %18
  %23 = sext i32 %20 to i64
  %24 = getelementptr inbounds i64, ptr %.03235, i64 %23
  %25 = sub nsw i32 %.03136, %20
  %26 = add nuw nsw i32 %.03037, 1
  %27 = icmp slt i32 %26, %14
  %28 = icmp sgt i32 %25, 0
  %29 = select i1 %27, i1 %28, i1 false
  br i1 %29, label %19, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %19, %10, %8
  %.0 = phi ptr [ %9, %8 ], [ %0, %10 ], [ %0, %19 ]
  ret ptr %.0
}

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

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

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

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

; 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 = { 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 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,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass