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

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

; Function Attrs: nounwind uwtable
define dso_local void @DecryptCBC_TDES(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  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 i64 %4, ptr %11, align 8, !tbaa !11
  store ptr %5, ptr %12, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %17, %6
  %15 = load i32, ptr %9, align 4, !tbaa !9
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %50

17:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load i64, ptr %18, align 8, !tbaa !11
  store i64 %19, ptr %13, align 8, !tbaa !11
  %20 = load i64, ptr %13, align 8, !tbaa !11
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = getelementptr inbounds ptr, ptr %21, i64 0
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = load ptr, ptr %12, align 8, !tbaa !5
  %25 = call i64 @Cipher_DES(i64 noundef %20, ptr noundef %23, ptr noundef %24)
  store i64 %25, ptr %13, align 8, !tbaa !11
  %26 = load i64, ptr %13, align 8, !tbaa !11
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = getelementptr inbounds ptr, ptr %27, i64 1
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = call i64 @Cipher_DES(i64 noundef %26, ptr noundef %29, ptr noundef %30)
  store i64 %31, ptr %13, align 8, !tbaa !11
  %32 = load i64, ptr %13, align 8, !tbaa !11
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = getelementptr inbounds ptr, ptr %33, i64 2
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = load ptr, ptr %12, align 8, !tbaa !5
  %37 = call i64 @Cipher_DES(i64 noundef %32, ptr noundef %35, ptr noundef %36)
  store i64 %37, ptr %13, align 8, !tbaa !11
  %38 = load i64, ptr %13, align 8, !tbaa !11
  %39 = load i64, ptr %11, align 8, !tbaa !11
  %40 = xor i64 %38, %39
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %40, ptr %41, align 8, !tbaa !11
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load i64, ptr %42, align 8, !tbaa !11
  store i64 %43, ptr %11, align 8, !tbaa !11
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds i64, ptr %44, i32 1
  store ptr %45, ptr %7, align 8, !tbaa !5
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds i64, ptr %46, i32 1
  store ptr %47, ptr %8, align 8, !tbaa !5
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = add nsw i32 %48, -1
  store i32 %49, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %14, !llvm.loop !13

50:                                               ; preds = %14
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare i64 @Cipher_DES(i64 noundef, 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 = { "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, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 void @DecryptCBC_TDES(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, i32 noundef %2, ptr nocapture noundef readonly %3, i64 noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %.not20 = icmp eq i32 %2, 0
  br i1 %.not20, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6
  %7 = getelementptr inbounds i8, ptr %3, i64 8
  %8 = getelementptr inbounds i8, ptr %3, i64 16
  br label %9

9:                                                ; preds = %.lr.ph, %9
  %.024 = phi ptr [ %0, %.lr.ph ], [ %19, %9 ]
  %.01723 = phi ptr [ %1, %.lr.ph ], [ %20, %9 ]
  %.01822 = phi i64 [ %4, %.lr.ph ], [ %18, %9 ]
  %.01921 = phi i32 [ %2, %.lr.ph ], [ %21, %9 ]
  %10 = load i64, ptr %.024, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8, !tbaa !9
  %12 = tail call i64 @Cipher_DES(i64 noundef %10, ptr noundef %11, ptr noundef %5) #2
  %13 = load ptr, ptr %7, align 8, !tbaa !9
  %14 = tail call i64 @Cipher_DES(i64 noundef %12, ptr noundef %13, ptr noundef %5) #2
  %15 = load ptr, ptr %8, align 8, !tbaa !9
  %16 = tail call i64 @Cipher_DES(i64 noundef %14, ptr noundef %15, ptr noundef %5) #2
  %17 = xor i64 %16, %.01822
  store i64 %17, ptr %.01723, align 8, !tbaa !5
  %18 = load i64, ptr %.024, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.024, i64 8
  %20 = getelementptr inbounds i8, ptr %.01723, i64 8
  %21 = add nsw i32 %.01921, -1
  %.not = icmp eq i32 %21, 0
  br i1 %.not, label %._crit_edge, label %9, !llvm.loop !11

._crit_edge:                                      ; preds = %9, %6
  ret void
}

declare i64 @Cipher_DES(i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #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 = { "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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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