; 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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @CBCdec(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca [16 x i8], align 16
  %10 = alloca i32, align 4
  %11 = 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 16, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = sdiv i32 %12, 16
  store i32 %13, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  br label %14

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

18:                                               ; preds = %14
  %19 = getelementptr inbounds [16 x i8], ptr %9, i64 0, i64 0
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %19, ptr align 1 %20, i64 16, i1 false)
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = call i32 @aes_decrypt(ptr noundef %21, ptr noundef %22, ptr noundef %23)
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %43, %18
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = icmp slt i32 %26, 16
  br i1 %27, label %28, label %46

28:                                               ; preds = %25
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i8, ptr %29, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = zext i8 %33 to i32
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i8, ptr %35, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %40 = zext i8 %39 to i32
  %41 = xor i32 %40, %34
  %42 = trunc i32 %41 to i8
  store i8 %42, ptr %38, align 1, !tbaa !11
  br label %43

43:                                               ; preds = %28
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %11, align 4, !tbaa !9
  br label %25, !llvm.loop !12

46:                                               ; preds = %25
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds [16 x i8], ptr %9, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %47, ptr align 16 %48, i64 16, i1 false)
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i64 16
  store ptr %50, ptr %5, align 8, !tbaa !5
  br label %14, !llvm.loop !14

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

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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"

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

declare i32 @aes_decrypt(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

; Function Attrs: nounwind uwtable
define dso_local void @CBCdec(ptr noundef %0, i32 noundef %1, ptr nocapture noundef %2, ptr noundef %3) local_unnamed_addr #3 {
  %5 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5)
  %.off = add i32 %1, 15
  %.not16 = icmp ult i32 %.off, 31
  br i1 %.not16, label %._crit_edge, label %.lr.ph.preheader

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

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

._crit_edge:                                      ; preds = %.lr.ph, %4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5)
  ret void
}

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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