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

; 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._cpSMS4 = type { i32, [32 x i32], [32 x i32] }

; Function Attrs: nounwind uwtable
define dso_local i32 @cpProcessSMS4_ctr(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5) #0 {
  %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 ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca [33 x i8], align 16
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i32 %2, ptr %10, align 4, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store i32 %5, ptr %13, align 4, !tbaa !9
  %19 = load ptr, ptr %11, align 8, !tbaa !5
  %20 = icmp eq ptr null, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %6
  store i32 -8, ptr %7, align 4
  br label %122

22:                                               ; preds = %6
  %23 = load ptr, ptr %11, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._cpSMS4, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = load ptr, ptr %11, 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, 1397576500
  br i1 %30, label %32, label %31

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

32:                                               ; preds = %22
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = icmp eq ptr null, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %32
  store i32 -8, ptr %7, align 4
  br label %122

36:                                               ; preds = %32
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = icmp eq ptr null, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  store i32 -8, ptr %7, align 4
  br label %122

40:                                               ; preds = %36
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = icmp eq ptr null, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %40
  store i32 -8, ptr %7, align 4
  br label %122

44:                                               ; preds = %40
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = icmp slt i32 %45, 1
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  store i32 -15, ptr %7, align 4
  br label %122

48:                                               ; preds = %44
  %49 = load i32, ptr %13, align 4, !tbaa !9
  %50 = icmp slt i32 128, %49
  br i1 %50, label %54, label %51

51:                                               ; preds = %48
  %52 = load i32, ptr %13, align 4, !tbaa !9
  %53 = icmp slt i32 %52, 1
  br i1 %53, label %54, label %55

54:                                               ; preds = %51, %48
  store i32 -1012, ptr %7, align 4
  br label %122

55:                                               ; preds = %51
  %56 = load i32, ptr %13, align 4, !tbaa !9
  %57 = icmp slt i32 %56, 27
  br i1 %57, label %58, label %77

58:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %59 = load i32, ptr %10, align 4, !tbaa !9
  %60 = ashr i32 %59, 4
  store i32 %60, ptr %14, align 4, !tbaa !9
  %61 = load i32, ptr %10, align 4, !tbaa !9
  %62 = and i32 %61, 15
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %67

64:                                               ; preds = %58
  %65 = load i32, ptr %14, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %14, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %64, %58
  %68 = load i32, ptr %14, align 4, !tbaa !9
  %69 = load i32, ptr %13, align 4, !tbaa !9
  %70 = shl i32 1, %69
  %71 = icmp sgt i32 %68, %70
  br i1 %71, label %72, label %73

72:                                               ; preds = %67
  store i32 -1012, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %74

73:                                               ; preds = %67
  store i32 0, ptr %15, align 4
  br label %74

74:                                               ; preds = %73, %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  %75 = load i32, ptr %15, align 4
  switch i32 %75, label %124 [
    i32 0, label %76
    i32 1, label %122
  ]

76:                                               ; preds = %74
  br label %77

77:                                               ; preds = %76, %55
  call void @llvm.lifetime.start.p0(i64 33, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %78 = getelementptr inbounds [33 x i8], ptr %16, i64 0, i64 0
  store ptr %78, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %79 = getelementptr inbounds [33 x i8], ptr %16, i64 0, i64 0
  %80 = getelementptr inbounds i8, ptr %79, i64 16
  store ptr %80, ptr %18, align 8, !tbaa !5
  %81 = load ptr, ptr %12, align 8, !tbaa !5
  %82 = load ptr, ptr %18, align 8, !tbaa !5
  call void @CopyBlock16(ptr noundef %81, ptr noundef %82)
  br label %83

83:                                               ; preds = %86, %77
  %84 = load i32, ptr %10, align 4, !tbaa !9
  %85 = icmp sge i32 %84, 16
  br i1 %85, label %86, label %103

86:                                               ; preds = %83
  %87 = load ptr, ptr %17, align 8, !tbaa !5
  %88 = load ptr, ptr %18, align 8, !tbaa !5
  %89 = load ptr, ptr %11, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct._cpSMS4, ptr %89, i32 0, i32 1
  %91 = getelementptr inbounds [32 x i32], ptr %90, i64 0, i64 0
  call void @cpSMS4_Cipher(ptr noundef %87, ptr noundef %88, ptr noundef %91)
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = load ptr, ptr %17, align 8, !tbaa !5
  %94 = load ptr, ptr %9, align 8, !tbaa !5
  call void @XorBlock16(ptr noundef %92, ptr noundef %93, ptr noundef %94)
  %95 = load ptr, ptr %18, align 8, !tbaa !5
  %96 = load i32, ptr %13, align 4, !tbaa !9
  call void @StdIncrement(ptr noundef %95, i32 noundef 128, i32 noundef %96)
  %97 = load ptr, ptr %8, align 8, !tbaa !5
  %98 = getelementptr inbounds i8, ptr %97, i64 16
  store ptr %98, ptr %8, align 8, !tbaa !5
  %99 = load ptr, ptr %9, align 8, !tbaa !5
  %100 = getelementptr inbounds i8, ptr %99, i64 16
  store ptr %100, ptr %9, align 8, !tbaa !5
  %101 = load i32, ptr %10, align 4, !tbaa !9
  %102 = sub nsw i32 %101, 16
  store i32 %102, ptr %10, align 4, !tbaa !9
  br label %83, !llvm.loop !13

103:                                              ; preds = %83
  %104 = load i32, ptr %10, align 4, !tbaa !9
  %105 = icmp ne i32 %104, 0
  br i1 %105, label %106, label %118

106:                                              ; preds = %103
  %107 = load ptr, ptr %17, align 8, !tbaa !5
  %108 = load ptr, ptr %18, align 8, !tbaa !5
  %109 = load ptr, ptr %11, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct._cpSMS4, ptr %109, i32 0, i32 1
  %111 = getelementptr inbounds [32 x i32], ptr %110, i64 0, i64 0
  call void @cpSMS4_Cipher(ptr noundef %107, ptr noundef %108, ptr noundef %111)
  %112 = load ptr, ptr %8, align 8, !tbaa !5
  %113 = load ptr, ptr %17, align 8, !tbaa !5
  %114 = load ptr, ptr %9, align 8, !tbaa !5
  %115 = load i32, ptr %10, align 4, !tbaa !9
  call void @XorBlock(ptr noundef %112, ptr noundef %113, ptr noundef %114, i32 noundef %115)
  %116 = load ptr, ptr %18, align 8, !tbaa !5
  %117 = load i32, ptr %13, align 4, !tbaa !9
  call void @StdIncrement(ptr noundef %116, i32 noundef 128, i32 noundef %117)
  br label %118

118:                                              ; preds = %106, %103
  %119 = load ptr, ptr %18, align 8, !tbaa !5
  %120 = load ptr, ptr %12, align 8, !tbaa !5
  call void @CopyBlock16(ptr noundef %119, ptr noundef %120)
  %121 = getelementptr inbounds [33 x i8], ptr %16, i64 0, i64 0
  call void @PurgeBlock(ptr noundef %121, i32 noundef 33)
  store i32 0, ptr %7, align 4
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 33, ptr %16) #4
  br label %122

122:                                              ; preds = %118, %74, %54, %47, %43, %39, %35, %31, %21
  %123 = load i32, ptr %7, align 4
  ret i32 %123

124:                                              ; preds = %74
  unreachable
}

; 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: 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 void @CopyBlock16(ptr noundef, ptr noundef) #1

declare void @cpSMS4_Cipher(ptr noundef, ptr noundef, ptr noundef) #3

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @PurgeBlock(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 = !{!"_cpSMS4", !10, i64 0, !7, i64 4, !7, i64 132}
!13 = distinct !{!13, !14}
!14 = !{!"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 range(i32 -1012, 1) i32 @cpProcessSMS4_ctr(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = alloca [33 x i8], align 16
  %8 = icmp eq ptr %3, null
  br i1 %8, label %41, label %9

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

15:                                               ; preds = %9
  %16 = icmp eq ptr %0, null
  %17 = icmp eq ptr %1, null
  %or.cond54 = or i1 %16, %17
  %18 = icmp eq ptr %4, null
  %or.cond55 = or i1 %or.cond54, %18
  br i1 %or.cond55, label %41, label %19

19:                                               ; preds = %15
  %20 = icmp slt i32 %2, 1
  br i1 %20, label %41, label %21

21:                                               ; preds = %19
  %22 = add i32 %5, -129
  %or.cond = icmp ult i32 %22, -128
  br i1 %or.cond, label %41, label %23

23:                                               ; preds = %21
  %24 = icmp ult i32 %5, 27
  br i1 %24, label %25, label %30

25:                                               ; preds = %23
  %26 = lshr i32 %2, 4
  %27 = and i32 %2, 15
  %.not = icmp ne i32 %27, 0
  %28 = zext i1 %.not to i32
  %spec.select = add nuw nsw i32 %26, %28
  %29 = shl nuw nsw i32 1, %5
  %.not56 = icmp ugt i32 %spec.select, %29
  br i1 %.not56, label %41, label %30

30:                                               ; preds = %25, %23
  call void @llvm.lifetime.start.p0(i64 33, ptr nonnull %7) #4
  %31 = getelementptr inbounds i8, ptr %7, i64 16
  call void @CopyBlock16(ptr noundef nonnull %4, ptr noundef nonnull %31)
  %32 = icmp ugt i32 %2, 15
  br i1 %32, label %.lr.ph, label %._crit_edge.thread

.lr.ph:                                           ; preds = %30
  %33 = getelementptr inbounds i8, ptr %3, i64 4
  br label %34

34:                                               ; preds = %.lr.ph, %34
  %.04359 = phi ptr [ %0, %.lr.ph ], [ %35, %34 ]
  %.04658 = phi ptr [ %1, %.lr.ph ], [ %36, %34 ]
  %.04757 = phi i32 [ %2, %.lr.ph ], [ %37, %34 ]
  call void @cpSMS4_Cipher(ptr noundef nonnull %7, ptr noundef nonnull %31, ptr noundef nonnull %33) #4
  call void @XorBlock16(ptr noundef nonnull %.04359, ptr noundef nonnull %7, ptr noundef nonnull %.04658)
  call void @StdIncrement(ptr noundef nonnull %31, i32 noundef 128, i32 noundef %5)
  %35 = getelementptr inbounds i8, ptr %.04359, i64 16
  %36 = getelementptr inbounds i8, ptr %.04658, i64 16
  %37 = add nsw i32 %.04757, -16
  %38 = icmp ugt i32 %37, 15
  br i1 %38, label %34, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %34
  %.not53 = icmp eq i32 %37, 0
  br i1 %.not53, label %40, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %30, %._crit_edge
  %.043.lcssa70 = phi ptr [ %35, %._crit_edge ], [ %0, %30 ]
  %.046.lcssa69 = phi ptr [ %36, %._crit_edge ], [ %1, %30 ]
  %.047.lcssa68 = phi i32 [ %37, %._crit_edge ], [ %2, %30 ]
  %39 = getelementptr inbounds i8, ptr %3, i64 4
  call void @cpSMS4_Cipher(ptr noundef nonnull %7, ptr noundef nonnull %31, ptr noundef nonnull %39) #4
  call void @XorBlock(ptr noundef nonnull %.043.lcssa70, ptr noundef nonnull %7, ptr noundef nonnull %.046.lcssa69, i32 noundef %.047.lcssa68)
  call void @StdIncrement(ptr noundef nonnull %31, i32 noundef 128, i32 noundef %5)
  br label %40

40:                                               ; preds = %._crit_edge.thread, %._crit_edge
  call void @CopyBlock16(ptr noundef nonnull %31, ptr noundef nonnull %4)
  call void @PurgeBlock(ptr noundef nonnull %7, i32 noundef 33)
  call void @llvm.lifetime.end.p0(i64 33, ptr nonnull %7) #4
  br label %41

41:                                               ; preds = %25, %21, %19, %15, %9, %6, %40
  %.1 = phi i32 [ -1012, %25 ], [ 0, %40 ], [ -8, %6 ], [ -13, %9 ], [ -8, %15 ], [ -15, %19 ], [ -1012, %21 ]
  ret i32 %.1
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @IPP_UINT_PTR(ptr 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: mustprogress 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 void @CopyBlock16(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @cpSMS4_Cipher(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @PurgeBlock(ptr noundef, i32 noundef) local_unnamed_addr #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 = { 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, !7, i64 0}
!6 = !{!"_cpSMS4", !7, i64 0, !8, i64 4, !8, i64 132}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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