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

; 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_CS1(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 [16 x i8], align 16
  %14 = 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
  %15 = load ptr, ptr %10, align 8, !tbaa !5
  %16 = icmp eq ptr null, %15
  br i1 %16, label %17, label %18

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

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

27:                                               ; preds = %18
  store i32 -13, ptr %6, align 4
  br label %102

28:                                               ; preds = %18
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = icmp eq ptr null, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %28
  store i32 -8, ptr %6, align 4
  br label %102

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

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

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

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

40:                                               ; preds = %36
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = icmp slt i32 %41, 16
  br i1 %42, label %43, label %44

43:                                               ; preds = %40
  store i32 -15, ptr %6, align 4
  br label %102

44:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = and i32 %45, 15
  store i32 %46, ptr %12, align 4, !tbaa !9
  %47 = load i32, ptr %12, align 4, !tbaa !9
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = sub nsw i32 %48, %47
  store i32 %49, ptr %9, align 4, !tbaa !9
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  call void @cpEncryptSMS4_cbc(ptr noundef %50, ptr noundef %51, ptr noundef %52, i32 noundef %53, ptr noundef %54)
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = sext i32 %55 to i64
  %58 = getelementptr inbounds i8, ptr %56, i64 %57
  store ptr %58, ptr %7, align 8, !tbaa !5
  %59 = load i32, ptr %9, align 4, !tbaa !9
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = sext i32 %59 to i64
  %62 = getelementptr inbounds i8, ptr %60, i64 %61
  store ptr %62, ptr %8, align 8, !tbaa !5
  %63 = load i32, ptr %12, align 4, !tbaa !9
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %101

65:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 -16
  %68 = getelementptr inbounds [16 x i8], ptr %13, i64 0, i64 0
  call void @CopyBlock16(ptr noundef %67, ptr noundef %68)
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %69

69:                                               ; preds = %87, %65
  %70 = load i32, ptr %14, align 4, !tbaa !9
  %71 = load i32, ptr %12, align 4, !tbaa !9
  %72 = icmp slt i32 %70, %71
  br i1 %72, label %73, label %90

73:                                               ; preds = %69
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = load i32, ptr %14, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds i8, ptr %74, i64 %76
  %78 = load i8, ptr %77, align 1, !tbaa !13
  %79 = zext i8 %78 to i32
  %80 = load i32, ptr %14, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [16 x i8], ptr %13, i64 0, i64 %81
  %83 = load i8, ptr %82, align 1, !tbaa !13
  %84 = zext i8 %83 to i32
  %85 = xor i32 %84, %79
  %86 = trunc i32 %85 to i8
  store i8 %86, ptr %82, align 1, !tbaa !13
  br label %87

87:                                               ; preds = %73
  %88 = load i32, ptr %14, align 4, !tbaa !9
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %14, align 4, !tbaa !9
  br label %69, !llvm.loop !14

90:                                               ; preds = %69
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = getelementptr inbounds i8, ptr %91, i64 -16
  %93 = load i32, ptr %12, align 4, !tbaa !9
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds i8, ptr %92, i64 %94
  %96 = getelementptr inbounds [16 x i8], ptr %13, i64 0, i64 0
  %97 = load ptr, ptr %10, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct._cpSMS4, ptr %97, i32 0, i32 1
  %99 = getelementptr inbounds [32 x i32], ptr %98, i64 0, i64 0
  call void @cpSMS4_Cipher(ptr noundef %95, ptr noundef %96, ptr noundef %99)
  %100 = getelementptr inbounds [16 x i8], ptr %13, i64 0, i64 0
  call void @PurgeBlock(ptr noundef %100, i32 noundef 16)
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #4
  br label %101

101:                                              ; preds = %90, %44
  store i32 0, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %102

102:                                              ; preds = %101, %43, %39, %35, %31, %27, %17
  %103 = load i32, ptr %6, align 4
  ret i32 %103
}

; 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 @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_CS1(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = alloca [16 x i8], align 16
  %7 = icmp eq ptr %3, null
  br i1 %7, label %57, 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 %57

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.cond37 = or i1 %17, %or.cond
  br i1 %or.cond37, label %57, label %18

18:                                               ; preds = %14
  %19 = icmp slt i32 %2, 16
  br i1 %19, label %57, label %20

20:                                               ; preds = %18
  %21 = and i32 %2, 15
  %22 = and i32 %2, 2147483632
  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
  %.not = icmp eq i32 %21, 0
  br i1 %.not, label %57, label %25

25:                                               ; preds = %20
  %26 = getelementptr inbounds i8, ptr %1, i64 %23
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #4
  %27 = getelementptr inbounds i8, ptr %26, i64 -16
  call void @CopyBlock16(ptr noundef nonnull %27, ptr noundef nonnull %6)
  %wide.trip.count = zext nneg i32 %21 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %28 = icmp ult i32 %21, 4
  br i1 %28, label %.unr-lcssa, label %.new

.new:                                             ; preds = %25
  %unroll_iter = and i64 %wide.trip.count, 12
  br label %29

29:                                               ; preds = %29, %.new
  %indvars.iv = phi i64 [ 0, %.new ], [ %indvars.iv.next.3, %29 ]
  %niter = phi i64 [ 0, %.new ], [ %niter.next.3, %29 ]
  %30 = getelementptr inbounds i8, ptr %24, i64 %indvars.iv
  %31 = load i8, ptr %30, align 1, !tbaa !10
  %32 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 %indvars.iv
  %33 = load i8, ptr %32, align 4, !tbaa !10
  %34 = xor i8 %33, %31
  store i8 %34, ptr %32, align 4, !tbaa !10
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %35 = getelementptr inbounds i8, ptr %24, i64 %indvars.iv.next
  %36 = load i8, ptr %35, align 1, !tbaa !10
  %37 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 %indvars.iv.next
  %38 = load i8, ptr %37, align 1, !tbaa !10
  %39 = xor i8 %38, %36
  store i8 %39, ptr %37, align 1, !tbaa !10
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %40 = getelementptr inbounds i8, ptr %24, i64 %indvars.iv.next.1
  %41 = load i8, ptr %40, align 1, !tbaa !10
  %42 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 %indvars.iv.next.1
  %43 = load i8, ptr %42, align 2, !tbaa !10
  %44 = xor i8 %43, %41
  store i8 %44, ptr %42, align 2, !tbaa !10
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %45 = getelementptr inbounds i8, ptr %24, i64 %indvars.iv.next.2
  %46 = load i8, ptr %45, align 1, !tbaa !10
  %47 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 %indvars.iv.next.2
  %48 = load i8, ptr %47, align 1, !tbaa !10
  %49 = xor i8 %48, %46
  store i8 %49, ptr %47, align 1, !tbaa !10
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.unr-lcssa, label %29, !llvm.loop !11

.unr-lcssa:                                       ; preds = %29, %25
  %indvars.iv.unr = phi i64 [ 0, %25 ], [ %indvars.iv.next.3, %29 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.epilog-lcssa, label %.epil.preheader

.epil.preheader:                                  ; preds = %.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.unr-lcssa ]
  %50 = getelementptr inbounds i8, ptr %24, i64 %indvars.iv.epil
  %51 = load i8, ptr %50, align 1, !tbaa !10
  %52 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 %indvars.iv.epil
  %53 = load i8, ptr %52, align 1, !tbaa !10
  %54 = xor i8 %53, %51
  store i8 %54, ptr %52, align 1, !tbaa !10
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.epilog-lcssa, label %.epil.preheader, !llvm.loop !13

.epilog-lcssa:                                    ; preds = %.epil.preheader, %.unr-lcssa
  %55 = getelementptr inbounds i8, ptr %27, i64 %wide.trip.count
  %56 = getelementptr inbounds i8, ptr %3, i64 4
  call void @cpSMS4_Cipher(ptr noundef nonnull %55, ptr noundef nonnull %6, ptr noundef nonnull %56) #4
  call void @PurgeBlock(ptr noundef nonnull %6, i32 noundef 16)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #4
  br label %57

57:                                               ; preds = %20, %.epilog-lcssa, %18, %14, %8, %5
  %.030 = phi i32 [ -8, %5 ], [ -13, %8 ], [ -8, %14 ], [ -15, %18 ], [ 0, %.epilog-lcssa ], [ 0, %20 ]
  ret i32 %.030
}

; 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 @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}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass