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

; 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._cpHashCtx = type { i32, i32, i64, i64, ptr, ptr, [8 x i64], i32, [128 x i8] }

; Function Attrs: nounwind uwtable
define dso_local i32 @ippsMGF(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca %struct._cpHashCtx, align 8
  %16 = alloca [4 x i8], align 1
  %17 = alloca [64 x i8], align 16
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  %18 = load i32, ptr %11, align 4, !tbaa !9
  %19 = call i32 @cpValidHashAlg(i32 noundef %18)
  store i32 %19, ptr %11, align 4, !tbaa !9
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = icmp eq i32 0, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %5
  store i32 -14, ptr %6, align 4
  br label %105

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

26:                                               ; preds = %23
  store i32 -8, ptr %6, align 4
  br label %105

27:                                               ; preds = %23
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = icmp slt i32 %28, 0
  br i1 %29, label %33, label %30

30:                                               ; preds = %27
  %31 = load i32, ptr %10, align 4, !tbaa !9
  %32 = icmp slt i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %30, %27
  store i32 -15, ptr %6, align 4
  br label %105

34:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %35 = load i32, ptr %11, align 4, !tbaa !9
  %36 = call i32 @cpHashSize(i32 noundef %35)
  store i32 %36, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 240, ptr %15) #4
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = call i32 @ippsHashInit(ptr noundef %15, i32 noundef %37)
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %42, label %41

41:                                               ; preds = %34
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %41, %34
  store i32 0, ptr %13, align 4, !tbaa !9
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %101, %42
  %44 = load i32, ptr %14, align 4, !tbaa !9
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %47, label %104

47:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %48 = load i32, ptr %13, align 4, !tbaa !9
  %49 = ashr i32 %48, 24
  %50 = and i32 %49, 255
  %51 = trunc i32 %50 to i8
  %52 = getelementptr inbounds [4 x i8], ptr %16, i64 0, i64 0
  store i8 %51, ptr %52, align 1, !tbaa !11
  %53 = load i32, ptr %13, align 4, !tbaa !9
  %54 = ashr i32 %53, 16
  %55 = and i32 %54, 255
  %56 = trunc i32 %55 to i8
  %57 = getelementptr inbounds [4 x i8], ptr %16, i64 0, i64 1
  store i8 %56, ptr %57, align 1, !tbaa !11
  %58 = load i32, ptr %13, align 4, !tbaa !9
  %59 = ashr i32 %58, 8
  %60 = and i32 %59, 255
  %61 = trunc i32 %60 to i8
  %62 = getelementptr inbounds [4 x i8], ptr %16, i64 0, i64 2
  store i8 %61, ptr %62, align 1, !tbaa !11
  %63 = load i32, ptr %13, align 4, !tbaa !9
  %64 = and i32 %63, 255
  %65 = trunc i32 %64 to i8
  %66 = getelementptr inbounds [4 x i8], ptr %16, i64 0, i64 3
  store i8 %65, ptr %66, align 1, !tbaa !11
  %67 = load i32, ptr %11, align 4, !tbaa !9
  %68 = call i32 @cpReInitHash(ptr noundef %15, i32 noundef %67)
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = load i32, ptr %8, align 4, !tbaa !9
  %71 = call i32 @ippsHashUpdate(ptr noundef %69, i32 noundef %70, ptr noundef %15)
  %72 = getelementptr inbounds [4 x i8], ptr %16, i64 0, i64 0
  %73 = call i32 @ippsHashUpdate(ptr noundef %72, i32 noundef 4, ptr noundef %15)
  %74 = load i32, ptr %14, align 4, !tbaa !9
  %75 = load i32, ptr %12, align 4, !tbaa !9
  %76 = add nsw i32 %74, %75
  %77 = load i32, ptr %10, align 4, !tbaa !9
  %78 = icmp sle i32 %76, %77
  br i1 %78, label %79, label %88

79:                                               ; preds = %47
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = load i32, ptr %14, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds i8, ptr %80, i64 %82
  %84 = call i32 @ippsHashFinal(ptr noundef %83, ptr noundef %15)
  %85 = load i32, ptr %12, align 4, !tbaa !9
  %86 = load i32, ptr %14, align 4, !tbaa !9
  %87 = add nsw i32 %86, %85
  store i32 %87, ptr %14, align 4, !tbaa !9
  br label %100

88:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 64, ptr %17) #4
  %89 = getelementptr inbounds [64 x i8], ptr %17, i64 0, i64 0
  %90 = call i32 @ippsHashFinal(ptr noundef %89, ptr noundef %15)
  %91 = getelementptr inbounds [64 x i8], ptr %17, i64 0, i64 0
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  %93 = load i32, ptr %14, align 4, !tbaa !9
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds i8, ptr %92, i64 %94
  %96 = load i32, ptr %10, align 4, !tbaa !9
  %97 = load i32, ptr %14, align 4, !tbaa !9
  %98 = sub nsw i32 %96, %97
  call void @CopyBlock(ptr noundef %91, ptr noundef %95, i32 noundef %98)
  %99 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %99, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 64, ptr %17) #4
  br label %100

100:                                              ; preds = %88, %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %101

101:                                              ; preds = %100
  %102 = load i32, ptr %13, align 4, !tbaa !9
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %13, align 4, !tbaa !9
  br label %43, !llvm.loop !12

104:                                              ; preds = %43
  store i32 0, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 240, 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 4, ptr %12) #4
  br label %105

105:                                              ; preds = %104, %33, %26, %22
  %106 = load i32, ptr %6, align 4
  ret i32 %106
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cpValidHashAlg(i32 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 i32 @cpHashSize(i32 noundef) #1

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

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @CopyBlock(ptr noundef, 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

%struct._cpHashCtx = type { i32, i32, i64, i64, ptr, ptr, [8 x i64], i32, [128 x i8] }

; Function Attrs: nounwind uwtable
define dso_local range(i32 -15, 1) i32 @ippsMGF(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = alloca %struct._cpHashCtx, align 8
  %7 = alloca [4 x i8], align 1
  %8 = alloca [64 x i8], align 16
  %9 = tail call i32 @cpValidHashAlg(i32 noundef %4)
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %44, label %11

11:                                               ; preds = %5
  %12 = icmp eq ptr %2, null
  br i1 %12, label %44, label %13

13:                                               ; preds = %11
  %14 = or i32 %3, %1
  %or.cond.not = icmp sgt i32 %14, -1
  br i1 %or.cond.not, label %15, label %44

15:                                               ; preds = %13
  %16 = tail call i32 @cpHashSize(i32 noundef %9)
  call void @llvm.lifetime.start.p0(i64 240, ptr nonnull %6) #4
  %17 = call i32 @ippsHashInit(ptr noundef nonnull %6, i32 noundef %9) #4
  %.not = icmp eq ptr %0, null
  %spec.select = select i1 %.not, i32 0, i32 %1
  %18 = icmp sgt i32 %3, 0
  br i1 %18, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %15
  %19 = getelementptr inbounds i8, ptr %7, i64 1
  %20 = getelementptr inbounds i8, ptr %7, i64 2
  %21 = getelementptr inbounds i8, ptr %7, i64 3
  br label %22

22:                                               ; preds = %.lr.ph, %38
  %.041 = phi i32 [ 0, %.lr.ph ], [ %33, %38 ]
  %.03140 = phi i32 [ 0, %.lr.ph ], [ %42, %38 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #4
  %23 = lshr i32 %.03140, 24
  %24 = trunc nuw nsw i32 %23 to i8
  store i8 %24, ptr %7, align 1, !tbaa !5
  %25 = lshr i32 %.03140, 16
  %26 = trunc i32 %25 to i8
  store i8 %26, ptr %19, align 1, !tbaa !5
  %27 = lshr i32 %.03140, 8
  %28 = trunc i32 %27 to i8
  store i8 %28, ptr %20, align 1, !tbaa !5
  %29 = trunc i32 %.03140 to i8
  store i8 %29, ptr %21, align 1, !tbaa !5
  %30 = call i32 @cpReInitHash(ptr noundef nonnull %6, i32 noundef %9) #4
  %31 = call i32 @ippsHashUpdate(ptr noundef %0, i32 noundef %spec.select, ptr noundef nonnull %6) #4
  %32 = call i32 @ippsHashUpdate(ptr noundef nonnull %7, i32 noundef 4, ptr noundef nonnull %6) #4
  %33 = add nsw i32 %.041, %16
  %.not39 = icmp sgt i32 %33, %3
  br i1 %.not39, label %.thread, label %38

.thread:                                          ; preds = %22
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %8) #4
  %34 = call i32 @ippsHashFinal(ptr noundef nonnull %8, ptr noundef nonnull %6) #4
  %35 = sext i32 %.041 to i64
  %36 = getelementptr inbounds i8, ptr %2, i64 %35
  %37 = sub nsw i32 %3, %.041
  call void @CopyBlock(ptr noundef nonnull %8, ptr noundef nonnull %36, i32 noundef %37)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #4
  br label %._crit_edge

38:                                               ; preds = %22
  %39 = sext i32 %.041 to i64
  %40 = getelementptr inbounds i8, ptr %2, i64 %39
  %41 = call i32 @ippsHashFinal(ptr noundef nonnull %40, ptr noundef nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #4
  %42 = add nuw nsw i32 %.03140, 1
  %43 = icmp slt i32 %33, %3
  br i1 %43, label %22, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %38, %.thread, %15
  call void @llvm.lifetime.end.p0(i64 240, ptr nonnull %6) #4
  br label %44

44:                                               ; preds = %13, %11, %5, %._crit_edge
  %.032 = phi i32 [ 0, %._crit_edge ], [ -14, %5 ], [ -8, %11 ], [ -15, %13 ]
  ret i32 %.032
}

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

; Function Attrs: mustprogress 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 i32 @cpHashSize(i32 noundef) local_unnamed_addr #1

declare i32 @ippsHashInit(ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @cpReInitHash(ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @ippsHashUpdate(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

declare i32 @ippsHashFinal(ptr noundef, ptr noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress 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 = { mustprogress 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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