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

; 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 void @cpEncryptSMS4_cbc(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %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 [4 x i32], align 16
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %13 = load ptr, ptr %10, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._cpSMS4, ptr %13, i32 0, i32 1
  %15 = getelementptr inbounds [32 x i32], ptr %14, i64 0, i64 0
  store ptr %15, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #4
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 0
  call void @CopyBlock16(ptr noundef %16, ptr noundef %17)
  br label %18

18:                                               ; preds = %65, %5
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %21, label %72

21:                                               ; preds = %18
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds i32, ptr %22, i64 0
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 0
  %26 = load i32, ptr %25, align 16, !tbaa !9
  %27 = xor i32 %26, %24
  store i32 %27, ptr %25, align 16, !tbaa !9
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds i32, ptr %28, i64 1
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 1
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = xor i32 %32, %30
  store i32 %33, ptr %31, align 4, !tbaa !9
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds i32, ptr %34, i64 2
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 2
  %38 = load i32, ptr %37, align 8, !tbaa !9
  %39 = xor i32 %38, %36
  store i32 %39, ptr %37, align 8, !tbaa !9
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds i32, ptr %40, i64 3
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 3
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = xor i32 %44, %42
  store i32 %45, ptr %43, align 4, !tbaa !9
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 0
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  call void @cpSMS4_Cipher(ptr noundef %46, ptr noundef %47, ptr noundef %48)
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds i32, ptr %49, i64 0
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 0
  store i32 %51, ptr %52, align 16, !tbaa !9
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds i32, ptr %53, i64 1
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 1
  store i32 %55, ptr %56, align 4, !tbaa !9
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds i32, ptr %57, i64 2
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 2
  store i32 %59, ptr %60, align 8, !tbaa !9
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds i32, ptr %61, i64 3
  %63 = load i32, ptr %62, align 4, !tbaa !9
  %64 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 3
  store i32 %63, ptr %64, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %21
  %66 = load i32, ptr %9, align 4, !tbaa !9
  %67 = sub nsw i32 %66, 16
  store i32 %67, ptr %9, align 4, !tbaa !9
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i64 16
  store ptr %69, ptr %7, align 8, !tbaa !5
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i64 16
  store ptr %71, ptr %8, align 8, !tbaa !5
  br label %18, !llvm.loop !11

72:                                               ; preds = %18
  %73 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 0
  call void @PurgeBlock(ptr noundef %73, i32 noundef 16)
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  ret void
}

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

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

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

; 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

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 = { 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 = { "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"

; Function Attrs: nounwind uwtable
define dso_local void @cpEncryptSMS4_cbc(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = alloca [4 x i32], align 16
  %7 = getelementptr inbounds i8, ptr %4, i64 4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #4
  call void @CopyBlock16(ptr noundef %0, ptr noundef nonnull %6)
  %8 = icmp sgt i32 %3, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5
  %9 = load <4 x i32>, ptr %6, align 16, !tbaa !5
  br label %10

10:                                               ; preds = %.lr.ph, %10
  %.019 = phi ptr [ %1, %.lr.ph ], [ %16, %10 ]
  %.01518 = phi ptr [ %2, %.lr.ph ], [ %17, %10 ]
  %.01617 = phi i32 [ %3, %.lr.ph ], [ %15, %10 ]
  %11 = phi <4 x i32> [ %9, %.lr.ph ], [ %14, %10 ]
  %12 = load <4 x i32>, ptr %.019, align 4, !tbaa !5
  %13 = xor <4 x i32> %11, %12
  store <4 x i32> %13, ptr %6, align 16, !tbaa !5
  call void @cpSMS4_Cipher(ptr noundef %.01518, ptr noundef nonnull %6, ptr noundef nonnull %7) #4
  %14 = load <4 x i32>, ptr %.01518, align 4, !tbaa !5
  store <4 x i32> %14, ptr %6, align 16, !tbaa !5
  %15 = add nsw i32 %.01617, -16
  %16 = getelementptr inbounds i8, ptr %.019, i64 16
  %17 = getelementptr inbounds i8, ptr %.01518, i64 16
  %18 = icmp ugt i32 %.01617, 16
  br i1 %18, label %10, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %10, %5
  call void @PurgeBlock(ptr noundef nonnull %6, i32 noundef 16)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #4
  ret void
}

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

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

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

; 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

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass