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

%union.anon.3 = type { i64, [24 x i8] }

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

; 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) #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @CRYPTO_cts128_decrypt(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #3 {
  %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 %union.anon.3, 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 32, 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 %70

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 = add i64 16, %26
  %28 = load i64, ptr %10, align 8, !tbaa !9
  %29 = sub i64 %28, %27
  store i64 %29, ptr %10, align 8, !tbaa !9
  %30 = load i64, ptr %10, align 8, !tbaa !9
  %31 = icmp ne i64 %30, 0
  br i1 %31, label %32, label %45

32:                                               ; preds = %25
  %33 = load ptr, ptr %13, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = load i64, ptr %10, align 8, !tbaa !9
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  call void %33(ptr noundef %34, ptr noundef %35, i64 noundef %36, ptr noundef %37, ptr noundef %38, i32 noundef 0)
  %39 = load i64, ptr %10, align 8, !tbaa !9
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 %39
  store ptr %41, ptr %8, align 8, !tbaa !5
  %42 = load i64, ptr %10, align 8, !tbaa !9
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i64 %42
  store ptr %44, ptr %9, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %32, %25
  %46 = getelementptr inbounds [32 x i8], ptr %15, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 8 %46, i8 0, i64 32, i1 false)
  %47 = load ptr, ptr %13, align 8, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds [32 x i8], ptr %15, i64 0, i64 0
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = getelementptr inbounds [32 x i8], ptr %15, i64 0, i64 0
  %52 = getelementptr inbounds i8, ptr %51, i64 16
  call void %47(ptr noundef %48, ptr noundef %49, i64 noundef 16, ptr noundef %50, ptr noundef %52, i32 noundef 0)
  %53 = getelementptr inbounds [32 x i8], ptr %15, i64 0, i64 0
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 16
  %56 = load i64, ptr %14, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %53, ptr align 1 %55, i64 %56, i1 false)
  %57 = load ptr, ptr %13, align 8, !tbaa !5
  %58 = getelementptr inbounds [32 x i8], ptr %15, i64 0, i64 0
  %59 = getelementptr inbounds [32 x i8], ptr %15, i64 0, i64 0
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  call void %57(ptr noundef %58, ptr noundef %59, i64 noundef 32, ptr noundef %60, ptr noundef %61, i32 noundef 0)
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = getelementptr inbounds [32 x i8], ptr %15, i64 0, i64 0
  %64 = load i64, ptr %14, align 8, !tbaa !9
  %65 = add i64 16, %64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %62, ptr align 8 %63, i64 %65, i1 false)
  %66 = load i64, ptr %10, align 8, !tbaa !9
  %67 = add i64 16, %66
  %68 = load i64, ptr %14, align 8, !tbaa !9
  %69 = add i64 %67, %68
  store i64 %69, ptr %7, align 8
  store i32 1, ptr %16, align 4
  br label %70

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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}


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

%union.anon.3 = type { i64, [24 x i8] }

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

; 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) #1

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @CRYPTO_cts128_decrypt(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr nocapture noundef readonly %5) local_unnamed_addr #3 {
  %7 = alloca %union.anon.3, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %7) #4
  %8 = icmp ult i64 %2, 17
  br i1 %8, label %20, label %9

9:                                                ; preds = %6
  %10 = and i64 %2, 15
  %11 = icmp eq i64 %10, 0
  %spec.store.select = select i1 %11, i64 16, i64 %10
  %12 = add nuw nsw i64 %spec.store.select, 16
  %.not = icmp eq i64 %12, %2
  br i1 %.not, label %17, label %13

13:                                               ; preds = %9
  %14 = sub i64 %2, %12
  tail call void %5(ptr noundef %0, ptr noundef %1, i64 noundef %14, ptr noundef %3, ptr noundef %4, i32 noundef 0) #4
  %15 = getelementptr inbounds i8, ptr %0, i64 %14
  %16 = getelementptr inbounds i8, ptr %1, i64 %14
  br label %17

17:                                               ; preds = %13, %9
  %.028 = phi ptr [ %16, %13 ], [ %1, %9 ]
  %.027 = phi ptr [ %15, %13 ], [ %0, %9 ]
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %7, i8 0, i64 32, i1 false)
  %18 = getelementptr inbounds i8, ptr %7, i64 16
  call void %5(ptr noundef %.027, ptr noundef nonnull %7, i64 noundef 16, ptr noundef %3, ptr noundef nonnull %18, i32 noundef 0) #4
  %19 = getelementptr inbounds i8, ptr %.027, i64 16
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %7, ptr noundef nonnull align 1 dereferenceable(1) %19, i64 %spec.store.select, i1 false)
  call void %5(ptr noundef nonnull %7, ptr noundef nonnull %7, i64 noundef 32, ptr noundef %3, ptr noundef %4, i32 noundef 0) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %.028, ptr noundef nonnull align 8 dereferenceable(1) %7, i64 %12, i1 false)
  br label %20

20:                                               ; preds = %6, %17
  %.0 = phi i64 [ %2, %17 ], [ 0, %6 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %7) #4
  ret i64 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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)"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass