; 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.0 = type { i64, [8 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_nistcts128_encrypt(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.0, 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 16, ptr %15) #4
  %17 = load i64, ptr %10, align 8, !tbaa !9
  %18 = icmp ult 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 %58

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 = load i64, ptr %14, align 8, !tbaa !9
  %24 = load i64, ptr %10, align 8, !tbaa !9
  %25 = sub i64 %24, %23
  store i64 %25, ptr %10, align 8, !tbaa !9
  %26 = load ptr, ptr %13, align 8, !tbaa !5
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = load i64, ptr %10, align 8, !tbaa !9
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = load ptr, ptr %12, align 8, !tbaa !5
  call void %26(ptr noundef %27, ptr noundef %28, i64 noundef %29, ptr noundef %30, ptr noundef %31, i32 noundef 1)
  %32 = load i64, ptr %14, align 8, !tbaa !9
  %33 = icmp eq i64 %32, 0
  br i1 %33, label %34, label %36

34:                                               ; preds = %20
  %35 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %35, ptr %7, align 8
  store i32 1, ptr %16, align 4
  br label %58

36:                                               ; preds = %20
  %37 = load i64, ptr %10, align 8, !tbaa !9
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i64 %37
  store ptr %39, ptr %8, align 8, !tbaa !5
  %40 = load i64, ptr %10, align 8, !tbaa !9
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 %40
  store ptr %42, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds [16 x i8], ptr %15, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 8 %43, i8 0, i64 16, i1 false)
  %44 = getelementptr inbounds [16 x i8], ptr %15, i64 0, i64 0
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load i64, ptr %14, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %44, ptr align 1 %45, i64 %46, i1 false)
  %47 = load ptr, ptr %13, align 8, !tbaa !5
  %48 = getelementptr inbounds [16 x i8], ptr %15, i64 0, i64 0
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i64 -16
  %51 = load i64, ptr %14, align 8, !tbaa !9
  %52 = getelementptr inbounds i8, ptr %50, i64 %51
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  call void %47(ptr noundef %48, ptr noundef %52, i64 noundef 16, ptr noundef %53, ptr noundef %54, i32 noundef 1)
  %55 = load i64, ptr %10, align 8, !tbaa !9
  %56 = load i64, ptr %14, align 8, !tbaa !9
  %57 = add i64 %55, %56
  store i64 %57, ptr %7, align 8
  store i32 1, ptr %16, align 4
  br label %58

58:                                               ; preds = %36, %34, %19
  call void @llvm.lifetime.end.p0(i64 16, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  %59 = load i64, ptr %7, align 8
  ret i64 %59
}

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.0 = type { i64, [8 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_nistcts128_encrypt(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.0, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #4
  %8 = icmp ult i64 %2, 16
  br i1 %8, label %20, label %9

9:                                                ; preds = %6
  %10 = and i64 %2, 15
  %11 = and i64 %2, -16
  tail call void %5(ptr noundef %0, ptr noundef %1, i64 noundef %11, ptr noundef %3, ptr noundef %4, i32 noundef 1) #4
  %12 = icmp eq i64 %10, 0
  br i1 %12, label %20, label %13

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %0, i64 %11
  %15 = getelementptr inbounds i8, ptr %1, i64 %11
  %16 = sub nuw nsw i64 16, %10
  %17 = getelementptr i8, ptr %7, i64 %10
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %17, i8 0, i64 %16, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %7, ptr align 1 %14, i64 %10, i1 false)
  %18 = getelementptr inbounds i8, ptr %15, i64 -16
  %19 = getelementptr inbounds i8, ptr %18, i64 %10
  call void %5(ptr noundef nonnull %7, ptr noundef nonnull %19, i64 noundef 16, ptr noundef %3, ptr noundef %4, i32 noundef 1) #4
  br label %20

20:                                               ; preds = %9, %6, %13
  %.0 = phi i64 [ %2, %13 ], [ 0, %6 ], [ %11, %9 ]
  call void @llvm.lifetime.end.p0(i64 16, 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,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass