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

; 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] }

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

; Function Attrs: nounwind uwtable
define dso_local void @cpDecryptAES_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
  %13 = 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) #3
  %14 = load ptr, ptr %10, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._cpRijndael128, ptr %14, i32 0, i32 5
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  store ptr %16, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 0
  call void @CopyBlock16(ptr noundef %17, ptr noundef %18)
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = icmp ne ptr %19, %20
  br i1 %21, label %22, label %83

22:                                               ; preds = %5
  br label %23

23:                                               ; preds = %26, %22
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %82

26:                                               ; preds = %23
  %27 = load ptr, ptr %11, align 8, !tbaa !5
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._cpRijndael128, ptr %30, i32 0, i32 3
  %32 = load i32, ptr %31, align 4, !tbaa !13
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._cpRijndael128, ptr %33, i32 0, i32 8
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  call void %27(ptr noundef %28, ptr noundef %29, i32 noundef %32, ptr noundef %35, ptr noundef @RijDecSbox)
  %36 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 0
  %37 = load i32, ptr %36, align 16, !tbaa !9
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds i32, ptr %38, i64 0
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = xor i32 %40, %37
  store i32 %41, ptr %39, align 4, !tbaa !9
  %42 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 1
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds i32, ptr %44, i64 1
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = xor i32 %46, %43
  store i32 %47, ptr %45, align 4, !tbaa !9
  %48 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 2
  %49 = load i32, ptr %48, align 8, !tbaa !9
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds i32, ptr %50, i64 2
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = xor i32 %52, %49
  store i32 %53, ptr %51, align 4, !tbaa !9
  %54 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 3
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = getelementptr inbounds i32, ptr %56, i64 3
  %58 = load i32, ptr %57, align 4, !tbaa !9
  %59 = xor i32 %58, %55
  store i32 %59, ptr %57, align 4, !tbaa !9
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds i32, ptr %60, i64 0
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 0
  store i32 %62, ptr %63, align 16, !tbaa !9
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds i32, ptr %64, i64 1
  %66 = load i32, ptr %65, align 4, !tbaa !9
  %67 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 1
  store i32 %66, ptr %67, align 4, !tbaa !9
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds i32, ptr %68, i64 2
  %70 = load i32, ptr %69, align 4, !tbaa !9
  %71 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 2
  store i32 %70, ptr %71, align 8, !tbaa !9
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = getelementptr inbounds i32, ptr %72, i64 3
  %74 = load i32, ptr %73, align 4, !tbaa !9
  %75 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 3
  store i32 %74, ptr %75, align 4, !tbaa !9
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %76, i64 16
  store ptr %77, ptr %7, align 8, !tbaa !5
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = getelementptr inbounds i8, ptr %78, i64 16
  store ptr %79, ptr %8, align 8, !tbaa !5
  %80 = load i32, ptr %9, align 4, !tbaa !9
  %81 = add nsw i32 %80, -1
  store i32 %81, ptr %9, align 4, !tbaa !9
  br label %23, !llvm.loop !15

82:                                               ; preds = %23
  br label %143

83:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #3
  br label %84

84:                                               ; preds = %87, %83
  %85 = load i32, ptr %9, align 4, !tbaa !9
  %86 = icmp ne i32 %85, 0
  br i1 %86, label %87, label %141

87:                                               ; preds = %84
  %88 = load ptr, ptr %11, align 8, !tbaa !5
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = getelementptr inbounds [4 x i32], ptr %13, i64 0, i64 0
  %91 = load ptr, ptr %10, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct._cpRijndael128, ptr %91, i32 0, i32 3
  %93 = load i32, ptr %92, align 4, !tbaa !13
  %94 = load ptr, ptr %10, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct._cpRijndael128, ptr %94, i32 0, i32 8
  %96 = load ptr, ptr %95, align 8, !tbaa !14
  call void %88(ptr noundef %89, ptr noundef %90, i32 noundef %93, ptr noundef %96, ptr noundef @RijDecSbox)
  %97 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 0
  %98 = load i32, ptr %97, align 16, !tbaa !9
  %99 = getelementptr inbounds [4 x i32], ptr %13, i64 0, i64 0
  %100 = load i32, ptr %99, align 16, !tbaa !9
  %101 = xor i32 %100, %98
  store i32 %101, ptr %99, align 16, !tbaa !9
  %102 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 1
  %103 = load i32, ptr %102, align 4, !tbaa !9
  %104 = getelementptr inbounds [4 x i32], ptr %13, i64 0, i64 1
  %105 = load i32, ptr %104, align 4, !tbaa !9
  %106 = xor i32 %105, %103
  store i32 %106, ptr %104, align 4, !tbaa !9
  %107 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 2
  %108 = load i32, ptr %107, align 8, !tbaa !9
  %109 = getelementptr inbounds [4 x i32], ptr %13, i64 0, i64 2
  %110 = load i32, ptr %109, align 8, !tbaa !9
  %111 = xor i32 %110, %108
  store i32 %111, ptr %109, align 8, !tbaa !9
  %112 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 3
  %113 = load i32, ptr %112, align 4, !tbaa !9
  %114 = getelementptr inbounds [4 x i32], ptr %13, i64 0, i64 3
  %115 = load i32, ptr %114, align 4, !tbaa !9
  %116 = xor i32 %115, %113
  store i32 %116, ptr %114, align 4, !tbaa !9
  %117 = load ptr, ptr %7, align 8, !tbaa !5
  %118 = getelementptr inbounds i32, ptr %117, i64 0
  %119 = load i32, ptr %118, align 4, !tbaa !9
  %120 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 0
  store i32 %119, ptr %120, align 16, !tbaa !9
  %121 = load ptr, ptr %7, align 8, !tbaa !5
  %122 = getelementptr inbounds i32, ptr %121, i64 1
  %123 = load i32, ptr %122, align 4, !tbaa !9
  %124 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 1
  store i32 %123, ptr %124, align 4, !tbaa !9
  %125 = load ptr, ptr %7, align 8, !tbaa !5
  %126 = getelementptr inbounds i32, ptr %125, i64 2
  %127 = load i32, ptr %126, align 4, !tbaa !9
  %128 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 2
  store i32 %127, ptr %128, align 8, !tbaa !9
  %129 = load ptr, ptr %7, align 8, !tbaa !5
  %130 = getelementptr inbounds i32, ptr %129, i64 3
  %131 = load i32, ptr %130, align 4, !tbaa !9
  %132 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 3
  store i32 %131, ptr %132, align 4, !tbaa !9
  %133 = getelementptr inbounds [4 x i32], ptr %13, i64 0, i64 0
  %134 = load ptr, ptr %8, align 8, !tbaa !5
  call void @CopyBlock16(ptr noundef %133, ptr noundef %134)
  %135 = load ptr, ptr %7, align 8, !tbaa !5
  %136 = getelementptr inbounds i8, ptr %135, i64 16
  store ptr %136, ptr %7, align 8, !tbaa !5
  %137 = load ptr, ptr %8, align 8, !tbaa !5
  %138 = getelementptr inbounds i8, ptr %137, i64 16
  store ptr %138, ptr %8, align 8, !tbaa !5
  %139 = load i32, ptr %9, align 4, !tbaa !9
  %140 = add nsw i32 %139, -1
  store i32 %140, ptr %9, align 4, !tbaa !9
  br label %84, !llvm.loop !17

141:                                              ; preds = %84
  %142 = getelementptr inbounds [4 x i32], ptr %13, i64 0, i64 0
  call void @PurgeBlock(ptr noundef %142, i32 noundef 16)
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #3
  br label %143

143:                                              ; preds = %141, %82
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  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

; 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 = { 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, !6, i64 24}
!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, !10, i64 12}
!14 = !{!12, !6, i64 48}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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

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

; Function Attrs: nounwind uwtable
define dso_local void @cpDecryptAES_cbc(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr nocapture noundef readonly %4) local_unnamed_addr #0 {
  %6 = alloca [4 x i32], align 16
  %7 = alloca [4 x i32], align 16
  %8 = getelementptr inbounds i8, ptr %4, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #3
  call void @CopyBlock16(ptr noundef %0, ptr noundef nonnull %6)
  %.not = icmp eq ptr %1, %2
  br i1 %.not, label %22, label %.preheader

.preheader:                                       ; preds = %5
  %.not4243 = icmp eq i32 %3, 0
  br i1 %.not4243, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %10 = getelementptr inbounds i8, ptr %4, i64 12
  %11 = getelementptr inbounds i8, ptr %4, i64 48
  br label %12

12:                                               ; preds = %.lr.ph, %12
  %.046 = phi ptr [ %1, %.lr.ph ], [ %19, %12 ]
  %.03345 = phi ptr [ %2, %.lr.ph ], [ %20, %12 ]
  %.03544 = phi i32 [ %3, %.lr.ph ], [ %21, %12 ]
  %13 = load i32, ptr %10, align 4, !tbaa !11
  %14 = load ptr, ptr %11, align 8, !tbaa !12
  call void %9(ptr noundef %.046, ptr noundef %.03345, i32 noundef %13, ptr noundef %14, ptr noundef nonnull @RijDecSbox) #3
  %15 = load <4 x i32>, ptr %6, align 16, !tbaa !13
  %16 = load <4 x i32>, ptr %.03345, align 4, !tbaa !13
  %17 = xor <4 x i32> %16, %15
  store <4 x i32> %17, ptr %.03345, align 4, !tbaa !13
  %18 = load <4 x i32>, ptr %.046, align 4, !tbaa !13
  store <4 x i32> %18, ptr %6, align 16, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %.046, i64 16
  %20 = getelementptr inbounds i8, ptr %.03345, i64 16
  %21 = add nsw i32 %.03544, -1
  %.not42 = icmp eq i32 %21, 0
  br i1 %.not42, label %.loopexit, label %12, !llvm.loop !14

22:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #3
  %.not4147 = icmp eq i32 %3, 0
  br i1 %.not4147, label %._crit_edge, label %.lr.ph51

.lr.ph51:                                         ; preds = %22
  %23 = getelementptr inbounds i8, ptr %4, i64 12
  %24 = getelementptr inbounds i8, ptr %4, i64 48
  br label %25

25:                                               ; preds = %.lr.ph51, %25
  %.150 = phi ptr [ %1, %.lr.ph51 ], [ %32, %25 ]
  %.13449 = phi ptr [ %2, %.lr.ph51 ], [ %33, %25 ]
  %.13648 = phi i32 [ %3, %.lr.ph51 ], [ %34, %25 ]
  %26 = load i32, ptr %23, align 4, !tbaa !11
  %27 = load ptr, ptr %24, align 8, !tbaa !12
  call void %9(ptr noundef %.150, ptr noundef nonnull %7, i32 noundef %26, ptr noundef %27, ptr noundef nonnull @RijDecSbox) #3
  %28 = load <4 x i32>, ptr %6, align 16, !tbaa !13
  %29 = load <4 x i32>, ptr %7, align 16, !tbaa !13
  %30 = xor <4 x i32> %29, %28
  store <4 x i32> %30, ptr %7, align 16, !tbaa !13
  %31 = load <4 x i32>, ptr %.150, align 4, !tbaa !13
  store <4 x i32> %31, ptr %6, align 16, !tbaa !13
  call void @CopyBlock16(ptr noundef nonnull %7, ptr noundef %.13449)
  %32 = getelementptr inbounds i8, ptr %.150, i64 16
  %33 = getelementptr inbounds i8, ptr %.13449, i64 16
  %34 = add nsw i32 %.13648, -1
  %.not41 = icmp eq i32 %34, 0
  br i1 %.not41, label %._crit_edge, label %25, !llvm.loop !16

._crit_edge:                                      ; preds = %25, %22
  call void @PurgeBlock(ptr noundef nonnull %7, i32 noundef 16)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #3
  br label %.loopexit

.loopexit:                                        ; preds = %12, %.preheader, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #3
  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

; 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 = { 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, !10, i64 24}
!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, !7, i64 12}
!12 = !{!6, !10, i64 48}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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