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

; 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 @ippsSMS4EncryptCBC_CS3(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca [32 x i8], align 16
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %17 = load ptr, ptr %10, align 8, !tbaa !5
  %18 = icmp eq ptr null, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %5
  store i32 -8, ptr %6, align 4
  br label %111

20:                                               ; preds = %5
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._cpSMS4, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = call i64 @IPP_UINT_PTR(ptr noundef %24)
  %26 = trunc i64 %25 to i32
  %27 = xor i32 %23, %26
  %28 = icmp eq i32 %27, 1397576500
  br i1 %28, label %30, label %29

29:                                               ; preds = %20
  store i32 -13, ptr %6, align 4
  br label %111

30:                                               ; preds = %20
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = icmp eq ptr null, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %30
  store i32 -8, ptr %6, align 4
  br label %111

34:                                               ; preds = %30
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = icmp eq ptr null, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  store i32 -8, ptr %6, align 4
  br label %111

38:                                               ; preds = %34
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = icmp eq ptr null, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %38
  store i32 -8, ptr %6, align 4
  br label %111

42:                                               ; preds = %38
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = icmp sle i32 %43, 16
  br i1 %44, label %45, label %46

45:                                               ; preds = %42
  store i32 -15, ptr %6, align 4
  br label %111

46:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = and i32 %47, 15
  store i32 %48, ptr %12, align 4, !tbaa !9
  %49 = load i32, ptr %12, align 4, !tbaa !9
  %50 = icmp eq i32 0, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %46
  store i32 16, ptr %12, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %51, %46
  %53 = load i32, ptr %12, align 4, !tbaa !9
  %54 = load i32, ptr %9, align 4, !tbaa !9
  %55 = sub nsw i32 %54, %53
  store i32 %55, ptr %9, align 4, !tbaa !9
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = load i32, ptr %9, align 4, !tbaa !9
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  call void @cpEncryptSMS4_cbc(ptr noundef %56, ptr noundef %57, ptr noundef %58, i32 noundef %59, ptr noundef %60)
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = sext i32 %61 to i64
  %64 = getelementptr inbounds i8, ptr %62, i64 %63
  store ptr %64, ptr %7, align 8, !tbaa !5
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = sext i32 %65 to i64
  %68 = getelementptr inbounds i8, ptr %66, i64 %67
  store ptr %68, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %69 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  store ptr %69, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %70 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  %71 = getelementptr inbounds i8, ptr %70, i64 16
  store ptr %71, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %72, i64 -16
  %74 = load ptr, ptr %14, align 8, !tbaa !5
  call void @CopyBlock16(ptr noundef %73, ptr noundef %74)
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = getelementptr inbounds i8, ptr %75, i64 -16
  %77 = load ptr, ptr %15, align 8, !tbaa !5
  call void @CopyBlock16(ptr noundef %76, ptr noundef %77)
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %78

78:                                               ; preds = %97, %52
  %79 = load i32, ptr %16, align 4, !tbaa !9
  %80 = load i32, ptr %12, align 4, !tbaa !9
  %81 = icmp slt i32 %79, %80
  br i1 %81, label %82, label %100

82:                                               ; preds = %78
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = load i32, ptr %16, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds i8, ptr %83, i64 %85
  %87 = load i8, ptr %86, align 1, !tbaa !13
  %88 = zext i8 %87 to i32
  %89 = load ptr, ptr %14, align 8, !tbaa !5
  %90 = load i32, ptr %16, align 4, !tbaa !9
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds i8, ptr %89, i64 %91
  %93 = load i8, ptr %92, align 1, !tbaa !13
  %94 = zext i8 %93 to i32
  %95 = xor i32 %94, %88
  %96 = trunc i32 %95 to i8
  store i8 %96, ptr %92, align 1, !tbaa !13
  br label %97

97:                                               ; preds = %82
  %98 = load i32, ptr %16, align 4, !tbaa !9
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %16, align 4, !tbaa !9
  br label %78, !llvm.loop !14

100:                                              ; preds = %78
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  %102 = getelementptr inbounds i8, ptr %101, i64 -16
  %103 = load ptr, ptr %14, align 8, !tbaa !5
  %104 = load ptr, ptr %10, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct._cpSMS4, ptr %104, i32 0, i32 1
  %106 = getelementptr inbounds [32 x i32], ptr %105, i64 0, i64 0
  call void @cpSMS4_Cipher(ptr noundef %102, ptr noundef %103, ptr noundef %106)
  %107 = load ptr, ptr %15, align 8, !tbaa !5
  %108 = load ptr, ptr %8, align 8, !tbaa !5
  %109 = load i32, ptr %12, align 4, !tbaa !9
  call void @CopyBlock(ptr noundef %107, ptr noundef %108, i32 noundef %109)
  %110 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  call void @PurgeBlock(ptr noundef %110, i32 noundef 32)
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %13) #4
  store i32 0, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %111

111:                                              ; preds = %100, %45, %41, %37, %33, %29, %19
  %112 = load i32, ptr %6, align 4
  ret i32 %112
}

; 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

declare void @cpEncryptSMS4_cbc(ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

; 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 @CopyBlock(ptr noundef, ptr noundef, i32 noundef) #1

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

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

14:                                               ; preds = %8
  %15 = icmp eq ptr %0, null
  %16 = icmp eq ptr %4, null
  %or.cond = or i1 %15, %16
  %17 = icmp eq ptr %1, null
  %or.cond43 = or i1 %17, %or.cond
  br i1 %or.cond43, label %43, label %18

18:                                               ; preds = %14
  %19 = icmp slt i32 %2, 17
  br i1 %19, label %43, label %iter.check

iter.check:                                       ; preds = %18
  %20 = and i32 %2, 15
  %21 = icmp eq i32 %20, 0
  %spec.store.select = select i1 %21, i32 16, i32 %20
  %22 = sub nuw nsw i32 %2, %spec.store.select
  tail call void @cpEncryptSMS4_cbc(ptr noundef nonnull %4, ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %22, ptr noundef nonnull %3) #4
  %23 = zext nneg i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %0, i64 %23
  %25 = getelementptr inbounds i8, ptr %1, i64 %23
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #4
  %26 = getelementptr inbounds i8, ptr %6, i64 16
  %27 = getelementptr inbounds i8, ptr %25, i64 -16
  call void @CopyBlock16(ptr noundef nonnull %27, ptr noundef nonnull %6)
  call void @CopyBlock16(ptr noundef nonnull %27, ptr noundef nonnull %26)
  %wide.trip.count = zext nneg i32 %spec.store.select to i64
  %min.iters.check = icmp ult i32 %spec.store.select, 8
  br i1 %min.iters.check, label %vec.epilog.scalar.ph.preheader, label %vec.epilog.ph

vec.epilog.ph:                                    ; preds = %iter.check
  %n.vec51 = and i64 %wide.trip.count, 24
  %wide.load53 = load <8 x i8>, ptr %24, align 1, !tbaa !10
  %wide.load54 = load <8 x i8>, ptr %6, align 16, !tbaa !10
  %28 = xor <8 x i8> %wide.load54, %wide.load53
  store <8 x i8> %28, ptr %6, align 16, !tbaa !10
  %29 = icmp eq i64 %n.vec51, 8
  br i1 %29, label %vec.epilog.middle.block, label %vec.epilog.vector.body.1, !llvm.loop !11

vec.epilog.vector.body.1:                         ; preds = %vec.epilog.ph
  %30 = getelementptr inbounds i8, ptr %24, i64 8
  %wide.load53.1 = load <8 x i8>, ptr %30, align 1, !tbaa !10
  %31 = getelementptr inbounds i8, ptr %6, i64 8
  %wide.load54.1 = load <8 x i8>, ptr %31, align 8, !tbaa !10
  %32 = xor <8 x i8> %wide.load54.1, %wide.load53.1
  store <8 x i8> %32, ptr %31, align 8, !tbaa !10
  %33 = icmp eq i64 %n.vec51, 16
  br i1 %33, label %vec.epilog.middle.block, label %vec.epilog.vector.body.2, !llvm.loop !11

vec.epilog.vector.body.2:                         ; preds = %vec.epilog.vector.body.1
  %34 = getelementptr inbounds i8, ptr %24, i64 16
  %wide.load53.2 = load <8 x i8>, ptr %34, align 1, !tbaa !10
  %35 = getelementptr inbounds i8, ptr %6, i64 16
  %wide.load54.2 = load <8 x i8>, ptr %35, align 16, !tbaa !10
  %36 = xor <8 x i8> %wide.load54.2, %wide.load53.2
  store <8 x i8> %36, ptr %35, align 16, !tbaa !10
  br label %vec.epilog.middle.block

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body.2, %vec.epilog.vector.body.1, %vec.epilog.ph
  %cmp.n56 = icmp eq i64 %n.vec51, %wide.trip.count
  br i1 %cmp.n56, label %.loopexit, label %vec.epilog.scalar.ph.preheader

vec.epilog.scalar.ph.preheader:                   ; preds = %vec.epilog.middle.block, %iter.check
  %indvars.iv.ph = phi i64 [ 0, %iter.check ], [ %n.vec51, %vec.epilog.middle.block ]
  br label %vec.epilog.scalar.ph

vec.epilog.scalar.ph:                             ; preds = %vec.epilog.scalar.ph.preheader, %vec.epilog.scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %vec.epilog.scalar.ph ], [ %indvars.iv.ph, %vec.epilog.scalar.ph.preheader ]
  %37 = getelementptr inbounds i8, ptr %24, i64 %indvars.iv
  %38 = load i8, ptr %37, align 1, !tbaa !10
  %39 = getelementptr inbounds i8, ptr %6, i64 %indvars.iv
  %40 = load i8, ptr %39, align 1, !tbaa !10
  %41 = xor i8 %40, %38
  store i8 %41, ptr %39, align 1, !tbaa !10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %vec.epilog.scalar.ph, !llvm.loop !15

.loopexit:                                        ; preds = %vec.epilog.scalar.ph, %vec.epilog.middle.block
  %42 = getelementptr inbounds i8, ptr %3, i64 4
  call void @cpSMS4_Cipher(ptr noundef nonnull %27, ptr noundef nonnull %6, ptr noundef nonnull %42) #4
  call void @CopyBlock(ptr noundef nonnull %26, ptr noundef nonnull %25, i32 noundef %spec.store.select)
  call void @PurgeBlock(ptr noundef nonnull %6, i32 noundef 32)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #4
  br label %43

43:                                               ; preds = %18, %14, %8, %5, %.loopexit
  %.037 = phi i32 [ 0, %.loopexit ], [ -8, %5 ], [ -13, %8 ], [ -8, %14 ], [ -15, %18 ]
  ret i32 %.037
}

; 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

declare void @cpEncryptSMS4_cbc(ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

; 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 @CopyBlock(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

; 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, !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 = !{!8, !8, i64 0}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12, !14, !13}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass