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

; 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 void @cpEncryptAES_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) #3
  %13 = load ptr, ptr %10, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._cpRijndael128, ptr %13, i32 0, i32 4
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  store ptr %15, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #3
  %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 = %21, %5
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %77

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 %11, align 8, !tbaa !5
  %47 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 0
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._cpRijndael128, ptr %49, i32 0, i32 3
  %51 = load i32, ptr %50, align 4, !tbaa !13
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._cpRijndael128, ptr %52, i32 0, i32 8
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  call void %46(ptr noundef %47, ptr noundef %48, i32 noundef %51, ptr noundef %54, ptr noundef @RijEncSbox)
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds i32, ptr %55, i64 0
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 0
  store i32 %57, ptr %58, align 16, !tbaa !9
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = getelementptr inbounds i32, ptr %59, i64 1
  %61 = load i32, ptr %60, align 4, !tbaa !9
  %62 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 1
  store i32 %61, ptr %62, align 4, !tbaa !9
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = getelementptr inbounds i32, ptr %63, i64 2
  %65 = load i32, ptr %64, align 4, !tbaa !9
  %66 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 2
  store i32 %65, ptr %66, align 8, !tbaa !9
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds i32, ptr %67, i64 3
  %69 = load i32, ptr %68, align 4, !tbaa !9
  %70 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 3
  store i32 %69, ptr %70, align 4, !tbaa !9
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i64 16
  store ptr %72, ptr %7, align 8, !tbaa !5
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %73, i64 16
  store ptr %74, ptr %8, align 8, !tbaa !5
  %75 = load i32, ptr %9, align 4, !tbaa !9
  %76 = add nsw i32 %75, -1
  store i32 %76, ptr %9, align 4, !tbaa !9
  br label %18, !llvm.loop !15

77:                                               ; preds = %18
  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: 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 16}
!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"}


; 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 void @cpEncryptAES_cbc(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, i32 noundef %3, ptr nocapture noundef readonly %4) local_unnamed_addr #0 {
  %6 = alloca [4 x i32], align 16
  %7 = getelementptr inbounds i8, ptr %4, i64 16
  %8 = load ptr, ptr %7, 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)
  %.not19 = icmp eq i32 %3, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %9 = getelementptr inbounds i8, ptr %4, i64 12
  %10 = getelementptr inbounds i8, ptr %4, i64 48
  %11 = load <4 x i32>, ptr %6, align 16, !tbaa !11
  br label %12

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

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


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