; LLVM IR from intel/cryptography-primitives :: sources/ippcp (pcpaes_cbcencrypt_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._cpRijndael128 = type { i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, [124 x i32] }

@RijEncSbox = external constant [256 x i8], align 64

; Function Attrs: nounwind uwtable
define dso_local i32 @ippsAESEncryptCBC_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 ptr, align 8
  %14 = alloca [16 x i8], align 16
  %15 = 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
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  %17 = icmp eq ptr null, %16
  br i1 %17, label %18, label %19

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

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

28:                                               ; preds = %19
  store i32 -13, ptr %6, align 4
  br label %110

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

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

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

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

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

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

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

44:                                               ; preds = %41
  store i32 -15, ptr %6, align 4
  br label %110

45:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = and i32 %46, 15
  store i32 %47, ptr %12, align 4, !tbaa !9
  %48 = load i32, ptr %12, align 4, !tbaa !9
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = sub nsw i32 %49, %48
  store i32 %50, ptr %9, align 4, !tbaa !9
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = load i32, ptr %9, align 4, !tbaa !9
  %55 = sdiv i32 %54, 16
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  call void @cpEncryptAES_cbc(ptr noundef %51, ptr noundef %52, ptr noundef %53, 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 %109

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

74:                                               ; preds = %92, %67
  %75 = load i32, ptr %15, align 4, !tbaa !9
  %76 = load i32, ptr %12, align 4, !tbaa !9
  %77 = icmp slt i32 %75, %76
  br i1 %77, label %78, label %95

78:                                               ; preds = %74
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = load i32, ptr %15, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds i8, ptr %79, i64 %81
  %83 = load i8, ptr %82, align 1, !tbaa !14
  %84 = zext i8 %83 to i32
  %85 = load i32, ptr %15, align 4, !tbaa !9
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 %86
  %88 = load i8, ptr %87, align 1, !tbaa !14
  %89 = zext i8 %88 to i32
  %90 = xor i32 %89, %84
  %91 = trunc i32 %90 to i8
  store i8 %91, ptr %87, align 1, !tbaa !14
  br label %92

92:                                               ; preds = %78
  %93 = load i32, ptr %15, align 4, !tbaa !9
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %15, align 4, !tbaa !9
  br label %74, !llvm.loop !15

95:                                               ; preds = %74
  %96 = load ptr, ptr %13, align 8, !tbaa !5
  %97 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  %99 = getelementptr inbounds i8, ptr %98, i64 -16
  %100 = load i32, ptr %12, align 4, !tbaa !9
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds i8, ptr %99, i64 %101
  %103 = load ptr, ptr %10, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct._cpRijndael128, ptr %103, i32 0, i32 3
  %105 = load i32, ptr %104, align 4, !tbaa !17
  %106 = load ptr, ptr %10, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct._cpRijndael128, ptr %106, i32 0, i32 8
  %108 = load ptr, ptr %107, align 8, !tbaa !18
  call void %96(ptr noundef %97, ptr noundef %102, i32 noundef %105, ptr noundef %108, ptr noundef @RijEncSbox)
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %109

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

110:                                              ; preds = %109, %44, %40, %36, %32, %28, %18
  %111 = load i32, ptr %6, align 4
  ret i32 %111
}

; 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 @cpEncryptAES_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

; 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 = !{!"_cpRijndael128", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !10, i64 64, !10, i64 68, !7, i64 72}
!13 = !{!12, !6, i64 16}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !10, i64 12}
!18 = !{!12, !6, i64 48}


; 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"

@RijEncSbox = external constant [256 x i8], align 64

; Function Attrs: nounwind uwtable
define dso_local range(i32 -15, 1) i32 @ippsAESEncryptCBC_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 %63, label %8

8:                                                ; preds = %5
  %9 = load i32, ptr %3, align 8, !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, 542263626
  br i1 %13, label %14, label %63

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

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

20:                                               ; preds = %18
  %21 = and i32 %2, 15
  %22 = and i32 %2, 2147483632
  %23 = lshr i32 %2, 4
  tail call void @cpEncryptAES_cbc(ptr noundef nonnull %4, ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %23, ptr noundef nonnull %3) #4
  %24 = zext nneg i32 %22 to i64
  %25 = getelementptr inbounds i8, ptr %0, i64 %24
  %.not = icmp eq i32 %21, 0
  br i1 %.not, label %63, label %26

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

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

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

.unr-lcssa:                                       ; preds = %32, %26
  %indvars.iv.unr = phi i64 [ 0, %26 ], [ %indvars.iv.next.3, %32 ]
  %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 ]
  %53 = getelementptr inbounds i8, ptr %25, i64 %indvars.iv.epil
  %54 = load i8, ptr %53, align 1, !tbaa !12
  %55 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 %indvars.iv.epil
  %56 = load i8, ptr %55, align 1, !tbaa !12
  %57 = xor i8 %56, %54
  store i8 %57, ptr %55, align 1, !tbaa !12
  %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 !15

.epilog-lcssa:                                    ; preds = %.epil.preheader, %.unr-lcssa
  %58 = getelementptr inbounds i8, ptr %30, i64 %wide.trip.count
  %59 = getelementptr inbounds i8, ptr %3, i64 12
  %60 = load i32, ptr %59, align 4, !tbaa !17
  %61 = getelementptr inbounds i8, ptr %3, i64 48
  %62 = load ptr, ptr %61, align 8, !tbaa !18
  call void %29(ptr noundef nonnull %6, ptr noundef nonnull %58, i32 noundef %60, ptr noundef %62, ptr noundef nonnull @RijEncSbox) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #4
  br label %63

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

; 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 @cpEncryptAES_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

; 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 = !{!"_cpRijndael128", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !7, i64 64, !7, i64 68, !8, i64 72}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!8, !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.unroll.disable"}
!17 = !{!6, !7, i64 12}
!18 = !{!6, !10, i64 48}


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