; LLVM IR from square/subzero :: core/external-crypto/aes (modetest)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare i32 @aes_encrypt(ptr noundef, ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @CBCenc(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = sdiv i32 %11, 16
  store i32 %12, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  br label %13

13:                                               ; preds = %39, %4
  %14 = load i32, ptr %9, align 4, !tbaa !9
  %15 = add nsw i32 %14, -1
  store i32 %15, ptr %9, align 4, !tbaa !9
  %16 = icmp ne i32 %14, 0
  br i1 %16, label %17, label %48

17:                                               ; preds = %13
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %36, %17
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = icmp slt i32 %19, 16
  br i1 %20, label %21, label %39

21:                                               ; preds = %18
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load i32, ptr %10, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i8, ptr %22, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = zext i8 %26 to i32
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i8, ptr %28, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !11
  %33 = zext i8 %32 to i32
  %34 = xor i32 %33, %27
  %35 = trunc i32 %34 to i8
  store i8 %35, ptr %31, align 1, !tbaa !11
  br label %36

36:                                               ; preds = %21
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %10, align 4, !tbaa !9
  br label %18, !llvm.loop !12

39:                                               ; preds = %18
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = call i32 @aes_encrypt(ptr noundef %40, ptr noundef %41, ptr noundef %42)
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %44, ptr align 1 %45, i64 16, i1 false)
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i64 16
  store ptr %47, ptr %5, align 8, !tbaa !5
  br label %13, !llvm.loop !14

48:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret void
}

; 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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

declare i32 @aes_encrypt(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @CBCenc(ptr noundef %0, i32 noundef %1, ptr nocapture noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %.off = add i32 %1, 15
  %.not16 = icmp ult i32 %.off, 31
  br i1 %.not16, label %._crit_edge, label %.preheader.preheader

.preheader.preheader:                             ; preds = %4
  %5 = sdiv i32 %1, 16
  %6 = getelementptr inbounds i8, ptr %2, i64 1
  %7 = getelementptr inbounds i8, ptr %2, i64 2
  %8 = getelementptr inbounds i8, ptr %2, i64 3
  %9 = getelementptr inbounds i8, ptr %2, i64 4
  %10 = getelementptr inbounds i8, ptr %2, i64 5
  %11 = getelementptr inbounds i8, ptr %2, i64 6
  %12 = getelementptr inbounds i8, ptr %2, i64 7
  %13 = getelementptr inbounds i8, ptr %2, i64 8
  %14 = getelementptr inbounds i8, ptr %2, i64 9
  %15 = getelementptr inbounds i8, ptr %2, i64 10
  %16 = getelementptr inbounds i8, ptr %2, i64 11
  %17 = getelementptr inbounds i8, ptr %2, i64 12
  %18 = getelementptr inbounds i8, ptr %2, i64 13
  %19 = getelementptr inbounds i8, ptr %2, i64 14
  %20 = getelementptr inbounds i8, ptr %2, i64 15
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %.in = phi i32 [ %84, %.preheader ], [ %5, %.preheader.preheader ]
  %.01417 = phi ptr [ %86, %.preheader ], [ %0, %.preheader.preheader ]
  %21 = load i8, ptr %2, align 1, !tbaa !5
  %22 = load i8, ptr %.01417, align 1, !tbaa !5
  %23 = xor i8 %22, %21
  store i8 %23, ptr %.01417, align 1, !tbaa !5
  %24 = load i8, ptr %6, align 1, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %.01417, i64 1
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %27 = xor i8 %26, %24
  store i8 %27, ptr %25, align 1, !tbaa !5
  %28 = load i8, ptr %7, align 1, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %.01417, i64 2
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = xor i8 %30, %28
  store i8 %31, ptr %29, align 1, !tbaa !5
  %32 = load i8, ptr %8, align 1, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %.01417, i64 3
  %34 = load i8, ptr %33, align 1, !tbaa !5
  %35 = xor i8 %34, %32
  store i8 %35, ptr %33, align 1, !tbaa !5
  %36 = load i8, ptr %9, align 1, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %.01417, i64 4
  %38 = load i8, ptr %37, align 1, !tbaa !5
  %39 = xor i8 %38, %36
  store i8 %39, ptr %37, align 1, !tbaa !5
  %40 = load i8, ptr %10, align 1, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %.01417, i64 5
  %42 = load i8, ptr %41, align 1, !tbaa !5
  %43 = xor i8 %42, %40
  store i8 %43, ptr %41, align 1, !tbaa !5
  %44 = load i8, ptr %11, align 1, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %.01417, i64 6
  %46 = load i8, ptr %45, align 1, !tbaa !5
  %47 = xor i8 %46, %44
  store i8 %47, ptr %45, align 1, !tbaa !5
  %48 = load i8, ptr %12, align 1, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %.01417, i64 7
  %50 = load i8, ptr %49, align 1, !tbaa !5
  %51 = xor i8 %50, %48
  store i8 %51, ptr %49, align 1, !tbaa !5
  %52 = load i8, ptr %13, align 1, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %.01417, i64 8
  %54 = load i8, ptr %53, align 1, !tbaa !5
  %55 = xor i8 %54, %52
  store i8 %55, ptr %53, align 1, !tbaa !5
  %56 = load i8, ptr %14, align 1, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %.01417, i64 9
  %58 = load i8, ptr %57, align 1, !tbaa !5
  %59 = xor i8 %58, %56
  store i8 %59, ptr %57, align 1, !tbaa !5
  %60 = load i8, ptr %15, align 1, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %.01417, i64 10
  %62 = load i8, ptr %61, align 1, !tbaa !5
  %63 = xor i8 %62, %60
  store i8 %63, ptr %61, align 1, !tbaa !5
  %64 = load i8, ptr %16, align 1, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %.01417, i64 11
  %66 = load i8, ptr %65, align 1, !tbaa !5
  %67 = xor i8 %66, %64
  store i8 %67, ptr %65, align 1, !tbaa !5
  %68 = load i8, ptr %17, align 1, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %.01417, i64 12
  %70 = load i8, ptr %69, align 1, !tbaa !5
  %71 = xor i8 %70, %68
  store i8 %71, ptr %69, align 1, !tbaa !5
  %72 = load i8, ptr %18, align 1, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %.01417, i64 13
  %74 = load i8, ptr %73, align 1, !tbaa !5
  %75 = xor i8 %74, %72
  store i8 %75, ptr %73, align 1, !tbaa !5
  %76 = load i8, ptr %19, align 1, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %.01417, i64 14
  %78 = load i8, ptr %77, align 1, !tbaa !5
  %79 = xor i8 %78, %76
  store i8 %79, ptr %77, align 1, !tbaa !5
  %80 = load i8, ptr %20, align 1, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %.01417, i64 15
  %82 = load i8, ptr %81, align 1, !tbaa !5
  %83 = xor i8 %82, %80
  store i8 %83, ptr %81, align 1, !tbaa !5
  %84 = add nsw i32 %.in, -1
  %85 = tail call i32 @aes_encrypt(ptr noundef nonnull %.01417, ptr noundef nonnull %.01417, ptr noundef %3) #3
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(16) %2, ptr noundef nonnull align 1 dereferenceable(16) %.01417, i64 16, i1 false)
  %86 = getelementptr inbounds i8, ptr %.01417, i64 16
  %.not = icmp eq i32 %84, 0
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !8

._crit_edge:                                      ; preds = %.preheader, %4
  ret void
}

; 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 = { "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 = { 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 #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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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