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

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

@KDF_sm3.ctx = external hidden global %struct._cpHashCtx_rmf, align 8

declare i32 @ippsHashInit_rmf(ptr noundef, ptr noundef) #0

declare ptr @ippsHashMethod_SM3_TT() #0

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

declare i32 @ippsHashUpdate_rmf(ptr noundef, i32 noundef, ptr noundef) #0

declare i32 @ippsHashFinal_rmf(ptr noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @KDF_sm3(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca [32 x i8], align 16
  %11 = alloca [4 x i8], align 1
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %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 i32 %3, ptr %9, align 4, !tbaa !9
  %15 = load ptr, ptr %6, 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 %85

18:                                               ; preds = %4
  %19 = load ptr, ptr %8, 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 %85

22:                                               ; preds = %18
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = icmp sge i32 %23, 0
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  store i32 -5, ptr %5, align 4
  br label %85

26:                                               ; preds = %22
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  store i32 -5, ptr %5, align 4
  br label %85

30:                                               ; preds = %26
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = icmp sgt i32 %31, 0
  br i1 %32, label %33, label %84

33:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = add nsw i32 %34, 32
  %36 = sub nsw i32 %35, 1
  %37 = sdiv i32 %36, 32
  %38 = add i32 %37, 1
  store i32 %38, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 32, ptr %13, align 4, !tbaa !9
  %39 = call ptr @ippsHashMethod_SM3_TT()
  %40 = call i32 @ippsHashInit_rmf(ptr noundef @KDF_sm3.ctx, ptr noundef %39)
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 1, ptr %14, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %78, %33
  %42 = load i32, ptr %14, align 4, !tbaa !9
  %43 = load i32, ptr %12, align 4, !tbaa !9
  %44 = icmp ult i32 %42, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %81

46:                                               ; preds = %41
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = call i32 @ippsHashUpdate_rmf(ptr noundef %47, i32 noundef %48, ptr noundef @KDF_sm3.ctx)
  %50 = getelementptr inbounds [4 x i8], ptr %11, i64 0, i64 0
  %51 = load i32, ptr %14, align 4, !tbaa !9
  call void @convert_ct_to_big_endian(ptr noundef %50, i32 noundef %51)
  %52 = getelementptr inbounds [4 x i8], ptr %11, i64 0, i64 0
  %53 = call i32 @ippsHashUpdate_rmf(ptr noundef %52, i32 noundef 4, ptr noundef @KDF_sm3.ctx)
  %54 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %55 = call i32 @ippsHashFinal_rmf(ptr noundef %54, ptr noundef @KDF_sm3.ctx)
  %56 = load i32, ptr %14, align 4, !tbaa !9
  %57 = load i32, ptr %12, align 4, !tbaa !9
  %58 = sub i32 %57, 1
  %59 = icmp eq i32 %56, %58
  br i1 %59, label %60, label %67

60:                                               ; preds = %46
  %61 = load i32, ptr %7, align 4, !tbaa !9
  %62 = srem i32 %61, 32
  %63 = icmp ne i32 0, %62
  br i1 %63, label %64, label %67

64:                                               ; preds = %60
  %65 = load i32, ptr %7, align 4, !tbaa !9
  %66 = srem i32 %65, 32
  store i32 %66, ptr %13, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %64, %60, %46
  %68 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load i32, ptr %13, align 4, !tbaa !9
  call void @CopyBlock(ptr noundef %68, ptr noundef %69, i32 noundef %70)
  %71 = load i32, ptr %13, align 4, !tbaa !9
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = sext i32 %71 to i64
  %74 = getelementptr inbounds i8, ptr %72, i64 %73
  store ptr %74, ptr %6, align 8, !tbaa !5
  %75 = load i32, ptr %13, align 4, !tbaa !9
  %76 = load i32, ptr %7, align 4, !tbaa !9
  %77 = sub nsw i32 %76, %75
  store i32 %77, ptr %7, align 4, !tbaa !9
  br label %78

78:                                               ; preds = %67
  %79 = load i32, ptr %14, align 4, !tbaa !9
  %80 = add i32 %79, 1
  store i32 %80, ptr %14, align 4, !tbaa !9
  br label %41, !llvm.loop !11

81:                                               ; preds = %45
  %82 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  call void @PurgeBlock(ptr noundef %82, i32 noundef 32)
  %83 = getelementptr inbounds [4 x i8], ptr %11, i64 0, i64 0
  call void @PurgeBlock(ptr noundef %83, i32 noundef 4)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #4
  br label %84

84:                                               ; preds = %81, %30
  store i32 0, ptr %5, align 4
  br label %85

85:                                               ; preds = %84, %29, %25, %21, %17
  %86 = load i32, ptr %5, align 4
  ret i32 %86
}

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

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

attributes #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = distinct !{!11, !12}
!12 = !{!"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_rmf = type { i32, ptr, i32, [128 x i8], i64, i64, [8 x i64] }

@KDF_sm3.ctx = external hidden global %struct._cpHashCtx_rmf, align 8

declare i32 @ippsHashInit_rmf(ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @ippsHashMethod_SM3_TT() local_unnamed_addr #0

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

declare i32 @ippsHashUpdate_rmf(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare i32 @ippsHashFinal_rmf(ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -8, 1) i32 @KDF_sm3(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #3 {
  %5 = alloca [32 x i8], align 16
  %6 = alloca [4 x i8], align 1
  %7 = icmp eq ptr %0, null
  %8 = icmp eq ptr %2, null
  %or.cond = or i1 %7, %8
  br i1 %or.cond, label %28, label %9

9:                                                ; preds = %4
  %10 = icmp sgt i32 %1, -1
  %11 = icmp sgt i32 %3, 0
  %or.cond33 = and i1 %10, %11
  br i1 %or.cond33, label %12, label %28

12:                                               ; preds = %9
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %28, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %12
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #4
  %13 = add nuw i32 %1, 31
  %14 = lshr i32 %13, 5
  %15 = tail call ptr @ippsHashMethod_SM3_TT() #4
  %16 = tail call i32 @ippsHashInit_rmf(ptr noundef nonnull @KDF_sm3.ctx, ptr noundef %15) #4
  br label %.lr.ph

._crit_edge:                                      ; preds = %23
  call void @PurgeBlock(ptr noundef nonnull %5, i32 noundef 32)
  call void @PurgeBlock(ptr noundef nonnull %6, i32 noundef 4)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  br label %28

.lr.ph:                                           ; preds = %.lr.ph.preheader, %23
  %.038 = phi i32 [ %27, %23 ], [ 1, %.lr.ph.preheader ]
  %.02237 = phi i32 [ %.1, %23 ], [ 32, %.lr.ph.preheader ]
  %.02436 = phi ptr [ %25, %23 ], [ %0, %.lr.ph.preheader ]
  %.02535 = phi i32 [ %26, %23 ], [ %1, %.lr.ph.preheader ]
  %17 = call i32 @ippsHashUpdate_rmf(ptr noundef nonnull %2, i32 noundef %3, ptr noundef nonnull @KDF_sm3.ctx) #4
  call void @convert_ct_to_big_endian(ptr noundef nonnull %6, i32 noundef %.038)
  %18 = call i32 @ippsHashUpdate_rmf(ptr noundef nonnull %6, i32 noundef 4, ptr noundef nonnull @KDF_sm3.ctx) #4
  %19 = call i32 @ippsHashFinal_rmf(ptr noundef nonnull %5, ptr noundef nonnull @KDF_sm3.ctx) #4
  %20 = icmp eq i32 %.038, %14
  br i1 %20, label %21, label %23

21:                                               ; preds = %.lr.ph
  %22 = srem i32 %.02535, 32
  %.not32 = icmp eq i32 %22, 0
  %spec.select = select i1 %.not32, i32 %.02237, i32 %22
  br label %23

23:                                               ; preds = %21, %.lr.ph
  %.1 = phi i32 [ %.02237, %.lr.ph ], [ %spec.select, %21 ]
  call void @CopyBlock(ptr noundef nonnull %5, ptr noundef %.02436, i32 noundef %.1)
  %24 = sext i32 %.1 to i64
  %25 = getelementptr inbounds i8, ptr %.02436, i64 %24
  %26 = sub nsw i32 %.02535, %.1
  %27 = add nuw nsw i32 %.038, 1
  %exitcond.not = icmp eq i32 %.038, %14
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

28:                                               ; preds = %12, %._crit_edge, %9, %4
  %.023 = phi i32 [ -8, %4 ], [ -5, %9 ], [ 0, %._crit_edge ], [ 0, %12 ]
  ret i32 %.023
}

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

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

attributes #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass