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

; 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_CS2(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 slt 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 = load i32, ptr %9, align 4, !tbaa !9
  %51 = sub nsw i32 %50, %49
  store i32 %51, ptr %9, align 4, !tbaa !9
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  call void @cpEncryptSMS4_cbc(ptr noundef %52, ptr noundef %53, ptr noundef %54, i32 noundef %55, ptr noundef %56)
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = sext i32 %57 to i64
  %60 = getelementptr inbounds i8, ptr %58, i64 %59
  store ptr %60, ptr %7, align 8, !tbaa !5
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = sext i32 %61 to i64
  %64 = getelementptr inbounds i8, ptr %62, i64 %63
  store ptr %64, ptr %8, align 8, !tbaa !5
  %65 = load i32, ptr %12, align 4, !tbaa !9
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %110

67:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 32, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %68 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  store ptr %68, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %69 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  %70 = getelementptr inbounds i8, ptr %69, i64 16
  store ptr %70, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i64 -16
  %73 = load ptr, ptr %14, align 8, !tbaa !5
  call void @CopyBlock16(ptr noundef %72, ptr noundef %73)
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = getelementptr inbounds i8, ptr %74, i64 -16
  %76 = load ptr, ptr %15, align 8, !tbaa !5
  call void @CopyBlock16(ptr noundef %75, ptr noundef %76)
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %77

77:                                               ; preds = %96, %67
  %78 = load i32, ptr %16, align 4, !tbaa !9
  %79 = load i32, ptr %12, align 4, !tbaa !9
  %80 = icmp slt i32 %78, %79
  br i1 %80, label %81, label %99

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

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

99:                                               ; preds = %77
  %100 = load ptr, ptr %8, align 8, !tbaa !5
  %101 = getelementptr inbounds i8, ptr %100, i64 -16
  %102 = load ptr, ptr %14, align 8, !tbaa !5
  %103 = load ptr, ptr %10, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct._cpSMS4, ptr %103, i32 0, i32 1
  %105 = getelementptr inbounds [32 x i32], ptr %104, i64 0, i64 0
  call void @cpSMS4_Cipher(ptr noundef %101, ptr noundef %102, ptr noundef %105)
  %106 = load ptr, ptr %15, align 8, !tbaa !5
  %107 = load ptr, ptr %8, align 8, !tbaa !5
  %108 = load i32, ptr %12, align 4, !tbaa !9
  call void @CopyBlock(ptr noundef %106, ptr noundef %107, i32 noundef %108)
  %109 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  call void @PurgeBlock(ptr noundef %109, 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
  br label %110

110:                                              ; preds = %99, %46
  store i32 0, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %111

111:                                              ; preds = %110, %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_CS2(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 %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.cond44 = or i1 %17, %or.cond
  br i1 %or.cond44, 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
  %25 = getelementptr inbounds i8, ptr %1, i64 %23
  %.not = icmp eq i32 %21, 0
  br i1 %.not, label %57, label %26

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

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

30:                                               ; preds = %30, %.new
  %indvars.iv = phi i64 [ 0, %.new ], [ %indvars.iv.next.3, %30 ]
  %niter = phi i64 [ 0, %.new ], [ %niter.next.3, %30 ]
  %31 = getelementptr inbounds i8, ptr %24, i64 %indvars.iv
  %32 = load i8, ptr %31, align 1, !tbaa !10
  %33 = getelementptr inbounds i8, ptr %6, i64 %indvars.iv
  %34 = load i8, ptr %33, align 4, !tbaa !10
  %35 = xor i8 %34, %32
  store i8 %35, ptr %33, align 4, !tbaa !10
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %36 = getelementptr inbounds i8, ptr %24, i64 %indvars.iv.next
  %37 = load i8, ptr %36, align 1, !tbaa !10
  %38 = getelementptr inbounds i8, ptr %6, i64 %indvars.iv.next
  %39 = load i8, ptr %38, align 1, !tbaa !10
  %40 = xor i8 %39, %37
  store i8 %40, ptr %38, align 1, !tbaa !10
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %41 = getelementptr inbounds i8, ptr %24, i64 %indvars.iv.next.1
  %42 = load i8, ptr %41, align 1, !tbaa !10
  %43 = getelementptr inbounds i8, ptr %6, i64 %indvars.iv.next.1
  %44 = load i8, ptr %43, align 2, !tbaa !10
  %45 = xor i8 %44, %42
  store i8 %45, ptr %43, align 2, !tbaa !10
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %46 = getelementptr inbounds i8, ptr %24, i64 %indvars.iv.next.2
  %47 = load i8, ptr %46, align 1, !tbaa !10
  %48 = getelementptr inbounds i8, ptr %6, i64 %indvars.iv.next.2
  %49 = load i8, ptr %48, align 1, !tbaa !10
  %50 = xor i8 %49, %47
  store i8 %50, ptr %48, 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 %30, !llvm.loop !11

.unr-lcssa:                                       ; preds = %30, %26
  %indvars.iv.unr = phi i64 [ 0, %26 ], [ %indvars.iv.next.3, %30 ]
  %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 ]
  %51 = getelementptr inbounds i8, ptr %24, i64 %indvars.iv.epil
  %52 = load i8, ptr %51, align 1, !tbaa !10
  %53 = getelementptr inbounds i8, ptr %6, i64 %indvars.iv.epil
  %54 = load i8, ptr %53, align 1, !tbaa !10
  %55 = xor i8 %54, %52
  store i8 %55, ptr %53, 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
  %56 = getelementptr inbounds i8, ptr %3, i64 4
  call void @cpSMS4_Cipher(ptr noundef nonnull %28, ptr noundef nonnull %6, ptr noundef nonnull %56) #4
  call void @CopyBlock(ptr noundef nonnull %27, ptr noundef nonnull %25, i32 noundef %21)
  call void @PurgeBlock(ptr noundef nonnull %6, i32 noundef 32)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #4
  br label %57

57:                                               ; preds = %20, %.epilog-lcssa, %18, %14, %8, %5
  %.037 = phi i32 [ -8, %5 ], [ -13, %8 ], [ -8, %14 ], [ -15, %18 ], [ 0, %.epilog-lcssa ], [ 0, %20 ]
  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}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}


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