; LLVM IR from openssl/openssl :: crypto/modes (cts128)

; 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 i64 @CRYPTO_cts128_encrypt_block(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #0 {
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i64 %2, ptr %10, align 8, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %17 = load i64, ptr %10, align 8, !tbaa !9
  %18 = icmp ule i64 %17, 16
  br i1 %18, label %19, label %20

19:                                               ; preds = %6
  store i64 0, ptr %7, align 8
  store i32 1, ptr %16, align 4
  br label %76

20:                                               ; preds = %6
  %21 = load i64, ptr %10, align 8, !tbaa !9
  %22 = urem i64 %21, 16
  store i64 %22, ptr %14, align 8, !tbaa !9
  %23 = icmp eq i64 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %20
  store i64 16, ptr %14, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %24, %20
  %26 = load i64, ptr %14, align 8, !tbaa !9
  %27 = load i64, ptr %10, align 8, !tbaa !9
  %28 = sub i64 %27, %26
  store i64 %28, ptr %10, align 8, !tbaa !9
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = load i64, ptr %10, align 8, !tbaa !9
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = load ptr, ptr %12, align 8, !tbaa !5
  %34 = load ptr, ptr %13, align 8, !tbaa !5
  call void @CRYPTO_cbc128_encrypt(ptr noundef %29, ptr noundef %30, i64 noundef %31, ptr noundef %32, ptr noundef %33, ptr noundef %34)
  %35 = load i64, ptr %10, align 8, !tbaa !9
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 %35
  store ptr %37, ptr %8, align 8, !tbaa !5
  %38 = load i64, ptr %10, align 8, !tbaa !9
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 %38
  store ptr %40, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %58, %25
  %42 = load i64, ptr %15, align 8, !tbaa !9
  %43 = load i64, ptr %14, align 8, !tbaa !9
  %44 = icmp ult i64 %42, %43
  br i1 %44, label %45, label %61

45:                                               ; preds = %41
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load i64, ptr %15, align 8, !tbaa !9
  %48 = getelementptr inbounds i8, ptr %46, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !11
  %50 = zext i8 %49 to i32
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  %52 = load i64, ptr %15, align 8, !tbaa !9
  %53 = getelementptr inbounds i8, ptr %51, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = zext i8 %54 to i32
  %56 = xor i32 %55, %50
  %57 = trunc i32 %56 to i8
  store i8 %57, ptr %53, align 1, !tbaa !11
  br label %58

58:                                               ; preds = %45
  %59 = load i64, ptr %15, align 8, !tbaa !9
  %60 = add i64 %59, 1
  store i64 %60, ptr %15, align 8, !tbaa !9
  br label %41, !llvm.loop !12

61:                                               ; preds = %41
  %62 = load ptr, ptr %13, align 8, !tbaa !5
  %63 = load ptr, ptr %12, align 8, !tbaa !5
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  call void %62(ptr noundef %63, ptr noundef %64, ptr noundef %65)
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = getelementptr inbounds i8, ptr %67, i64 -16
  %69 = load i64, ptr %14, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %66, ptr align 1 %68, i64 %69, i1 false)
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i64 -16
  %72 = load ptr, ptr %12, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %71, ptr align 1 %72, i64 16, i1 false)
  %73 = load i64, ptr %10, align 8, !tbaa !9
  %74 = load i64, ptr %14, align 8, !tbaa !9
  %75 = add i64 %73, %74
  store i64 %75, ptr %7, align 8
  store i32 1, ptr %16, align 4
  br label %76

76:                                               ; preds = %61, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  %77 = load i64, ptr %7, align 8
  ret i64 %77
}

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

declare void @CRYPTO_cbc128_encrypt(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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(i64 17, 1) i64 @CRYPTO_cts128_encrypt_block(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %7 = icmp ult i64 %2, 17
  br i1 %7, label %55, label %iter.check

iter.check:                                       ; preds = %6
  %8 = and i64 %2, 15
  %9 = icmp eq i64 %8, 0
  %spec.store.select = select i1 %9, i64 16, i64 %8
  %10 = sub nuw i64 %2, %spec.store.select
  tail call void @CRYPTO_cbc128_encrypt(ptr noundef %0, ptr noundef %1, i64 noundef %10, ptr noundef %3, ptr noundef %4, ptr noundef %5) #3
  %11 = getelementptr inbounds i8, ptr %0, i64 %10
  %min.iters.check = icmp ult i64 %spec.store.select, 8
  br i1 %min.iters.check, label %vec.epilog.scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %iter.check
  %scevgep = getelementptr i8, ptr %4, i64 %spec.store.select
  %scevgep35 = getelementptr i8, ptr %0, i64 %2
  %bound0 = icmp ugt ptr %scevgep35, %4
  %bound1 = icmp ult ptr %11, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %vec.epilog.scalar.ph.preheader, label %vec.epilog.ph

vec.epilog.ph:                                    ; preds = %vector.memcheck
  %n.vec41 = and i64 %spec.store.select, 24
  %wide.load43 = load <8 x i8>, ptr %11, align 1, !tbaa !5, !alias.scope !8
  %wide.load44 = load <8 x i8>, ptr %4, align 1, !tbaa !5, !alias.scope !11, !noalias !8
  %12 = xor <8 x i8> %wide.load44, %wide.load43
  store <8 x i8> %12, ptr %4, align 1, !tbaa !5, !alias.scope !11, !noalias !8
  %13 = icmp eq i64 %n.vec41, 8
  br i1 %13, label %vec.epilog.middle.block, label %vec.epilog.vector.body.1, !llvm.loop !13

vec.epilog.vector.body.1:                         ; preds = %vec.epilog.ph
  %14 = getelementptr inbounds i8, ptr %11, i64 8
  %wide.load43.1 = load <8 x i8>, ptr %14, align 1, !tbaa !5, !alias.scope !8
  %15 = getelementptr inbounds i8, ptr %4, i64 8
  %wide.load44.1 = load <8 x i8>, ptr %15, align 1, !tbaa !5, !alias.scope !11, !noalias !8
  %16 = xor <8 x i8> %wide.load44.1, %wide.load43.1
  store <8 x i8> %16, ptr %15, align 1, !tbaa !5, !alias.scope !11, !noalias !8
  %17 = icmp eq i64 %n.vec41, 16
  br i1 %17, label %vec.epilog.middle.block, label %vec.epilog.vector.body.2, !llvm.loop !13

vec.epilog.vector.body.2:                         ; preds = %vec.epilog.vector.body.1
  %18 = getelementptr inbounds i8, ptr %11, i64 16
  %wide.load43.2 = load <8 x i8>, ptr %18, align 1, !tbaa !5, !alias.scope !8
  %19 = getelementptr inbounds i8, ptr %4, i64 16
  %wide.load44.2 = load <8 x i8>, ptr %19, align 1, !tbaa !5, !alias.scope !11, !noalias !8
  %20 = xor <8 x i8> %wide.load44.2, %wide.load43.2
  store <8 x i8> %20, ptr %19, align 1, !tbaa !5, !alias.scope !11, !noalias !8
  br label %vec.epilog.middle.block

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body.2, %vec.epilog.vector.body.1, %vec.epilog.ph
  %cmp.n46 = icmp eq i64 %spec.store.select, %n.vec41
  br i1 %cmp.n46, label %.loopexit, label %vec.epilog.scalar.ph.preheader

vec.epilog.scalar.ph.preheader:                   ; preds = %vec.epilog.middle.block, %vector.memcheck, %iter.check
  %.034.ph = phi i64 [ 0, %iter.check ], [ 0, %vector.memcheck ], [ %n.vec41, %vec.epilog.middle.block ]
  %xtraiter = and i64 %spec.store.select, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %vec.epilog.scalar.ph.prol.loopexit, label %vec.epilog.scalar.ph.prol

vec.epilog.scalar.ph.prol:                        ; preds = %vec.epilog.scalar.ph.preheader, %vec.epilog.scalar.ph.prol
  %.034.prol = phi i64 [ %26, %vec.epilog.scalar.ph.prol ], [ %.034.ph, %vec.epilog.scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %vec.epilog.scalar.ph.prol ], [ 0, %vec.epilog.scalar.ph.preheader ]
  %21 = getelementptr inbounds i8, ptr %11, i64 %.034.prol
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %4, i64 %.034.prol
  %24 = load i8, ptr %23, align 1, !tbaa !5
  %25 = xor i8 %24, %22
  store i8 %25, ptr %23, align 1, !tbaa !5
  %26 = add nuw nsw i64 %.034.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %vec.epilog.scalar.ph.prol.loopexit, label %vec.epilog.scalar.ph.prol, !llvm.loop !17

vec.epilog.scalar.ph.prol.loopexit:               ; preds = %vec.epilog.scalar.ph.prol, %vec.epilog.scalar.ph.preheader
  %.034.unr = phi i64 [ %.034.ph, %vec.epilog.scalar.ph.preheader ], [ %26, %vec.epilog.scalar.ph.prol ]
  %27 = sub nsw i64 %.034.ph, %spec.store.select
  %28 = icmp ugt i64 %27, -4
  br i1 %28, label %.loopexit, label %vec.epilog.scalar.ph

vec.epilog.scalar.ph:                             ; preds = %vec.epilog.scalar.ph.prol.loopexit, %vec.epilog.scalar.ph
  %.034 = phi i64 [ %52, %vec.epilog.scalar.ph ], [ %.034.unr, %vec.epilog.scalar.ph.prol.loopexit ]
  %29 = getelementptr inbounds i8, ptr %11, i64 %.034
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %4, i64 %.034
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %33 = xor i8 %32, %30
  store i8 %33, ptr %31, align 1, !tbaa !5
  %34 = add nuw nsw i64 %.034, 1
  %35 = getelementptr inbounds i8, ptr %11, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %4, i64 %34
  %38 = load i8, ptr %37, align 1, !tbaa !5
  %39 = xor i8 %38, %36
  store i8 %39, ptr %37, align 1, !tbaa !5
  %40 = add nuw nsw i64 %.034, 2
  %41 = getelementptr inbounds i8, ptr %11, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %4, i64 %40
  %44 = load i8, ptr %43, align 1, !tbaa !5
  %45 = xor i8 %44, %42
  store i8 %45, ptr %43, align 1, !tbaa !5
  %46 = add nuw nsw i64 %.034, 3
  %47 = getelementptr inbounds i8, ptr %11, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %4, i64 %46
  %50 = load i8, ptr %49, align 1, !tbaa !5
  %51 = xor i8 %50, %48
  store i8 %51, ptr %49, align 1, !tbaa !5
  %52 = add nuw nsw i64 %.034, 4
  %exitcond.not.3 = icmp eq i64 %52, %spec.store.select
  br i1 %exitcond.not.3, label %.loopexit, label %vec.epilog.scalar.ph, !llvm.loop !19

.loopexit:                                        ; preds = %vec.epilog.scalar.ph.prol.loopexit, %vec.epilog.scalar.ph, %vec.epilog.middle.block
  %53 = getelementptr inbounds i8, ptr %1, i64 %10
  tail call void %5(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %3) #3
  %54 = getelementptr inbounds i8, ptr %53, i64 -16
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %53, ptr noundef nonnull align 1 dereferenceable(1) %54, i64 %spec.store.select, i1 false)
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(16) %54, ptr noundef nonnull align 1 dereferenceable(16) %4, i64 16, i1 false)
  br label %55

55:                                               ; preds = %6, %.loopexit
  %.032 = phi i64 [ %2, %.loopexit ], [ 0, %6 ]
  ret i64 %.032
}

declare void @CRYPTO_cbc128_encrypt(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 = { "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 nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9}
!9 = distinct !{!9, !10}
!10 = distinct !{!10, !"LVerDomain"}
!11 = !{!12}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !14, !15, !16}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = distinct !{!19, !14, !15}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass