; LLVM IR from ARMmbed/mbed-crypto :: library (aes)

; 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

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

15:                                               ; preds = %6
  br label %16

16:                                               ; preds = %15
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %65, %29
  %31 = load i64, ptr %9, align 8, !tbaa !11
  %32 = add i64 %31, -1
  store i64 %32, ptr %9, align 8, !tbaa !11
  %33 = icmp ne i64 %31, 0
  br i1 %33, label %34, label %69

34:                                               ; preds = %30
  %35 = getelementptr inbounds [17 x i8], ptr %14, i64 0, i64 0
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %35, ptr align 1 %36, i64 16, i1 false)
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = call i32 @mbedtls_aes_crypt_ecb(ptr noundef %37, i32 noundef 1, ptr noundef %38, ptr noundef %39)
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %47

43:                                               ; preds = %34
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  %45 = load i8, ptr %44, align 1, !tbaa !13
  %46 = getelementptr inbounds [17 x i8], ptr %14, i64 0, i64 16
  store i8 %45, ptr %46, align 16, !tbaa !13
  br label %47

47:                                               ; preds = %43, %34
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i64 0
  %50 = load i8, ptr %49, align 1, !tbaa !13
  %51 = zext i8 %50 to i32
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i32 1
  store ptr %53, ptr %11, align 8, !tbaa !5
  %54 = load i8, ptr %52, align 1, !tbaa !13
  %55 = zext i8 %54 to i32
  %56 = xor i32 %51, %55
  %57 = trunc i32 %56 to i8
  %58 = load ptr, ptr %12, align 8, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %58, i32 1
  store ptr %59, ptr %12, align 8, !tbaa !5
  store i8 %57, ptr %58, align 1, !tbaa !13
  store i8 %57, ptr %13, align 1, !tbaa !13
  %60 = load i32, ptr %8, align 4, !tbaa !9
  %61 = icmp eq i32 %60, 1
  br i1 %61, label %62, label %65

62:                                               ; preds = %47
  %63 = load i8, ptr %13, align 1, !tbaa !13
  %64 = getelementptr inbounds [17 x i8], ptr %14, i64 0, i64 16
  store i8 %63, ptr %64, align 16, !tbaa !13
  br label %65

65:                                               ; preds = %62, %47
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = getelementptr inbounds [17 x i8], ptr %14, i64 0, i64 0
  %68 = getelementptr inbounds i8, ptr %67, i64 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %66, ptr align 1 %68, i64 16, i1 false)
  br label %30, !llvm.loop !14

69:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 17, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #3
  ret i32 0
}

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_aes_crypt_ecb(ptr noundef, i32 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 noundef i32 @mbedtls_aes_crypt_cfb8(ptr noundef %0, i32 noundef %1, i64 noundef %2, ptr noundef %3, ptr nocapture noundef readonly %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #1 {
  %.sroa.0 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %.sroa.0)
  %.not14 = icmp eq i64 %2, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6
  %7 = add i64 %2, -1
  %.sroa.0.1.sroa_idx = getelementptr inbounds i8, ptr %.sroa.0, i64 1
  %.sroa.4.1..sroa_idx = getelementptr inbounds i8, ptr %3, i64 15
  switch i32 %1, label %.lr.ph.split.split [
    i32 0, label %.lr.ph.split.us.split
    i32 1, label %.lr.ph.split.split.us
  ]

.lr.ph.split.us.split:                            ; preds = %.lr.ph, %.lr.ph.split.us.split
  %8 = phi i64 [ %15, %.lr.ph.split.us.split ], [ %7, %.lr.ph ]
  %.01216.us = phi ptr [ %14, %.lr.ph.split.us.split ], [ %5, %.lr.ph ]
  %.01315.us = phi ptr [ %12, %.lr.ph.split.us.split ], [ %4, %.lr.ph ]
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %.sroa.0, ptr noundef nonnull align 1 dereferenceable(16) %3, i64 16, i1 false)
  %9 = tail call i32 @mbedtls_aes_crypt_ecb(ptr noundef %0, i32 noundef 1, ptr noundef %3, ptr noundef %3)
  %10 = load i8, ptr %.01315.us, align 1, !tbaa !5
  %11 = load i8, ptr %3, align 1, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %.01315.us, i64 1
  %13 = xor i8 %10, %11
  %14 = getelementptr inbounds i8, ptr %.01216.us, i64 1
  store i8 %13, ptr %.01216.us, align 1, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(15) %3, ptr noundef nonnull align 1 dereferenceable(15) %.sroa.0.1.sroa_idx, i64 15, i1 false)
  store i8 %10, ptr %.sroa.4.1..sroa_idx, align 1
  %15 = add i64 %8, -1
  %.not.us = icmp eq i64 %8, 0
  br i1 %.not.us, label %._crit_edge, label %.lr.ph.split.us.split, !llvm.loop !8

.lr.ph.split.split.us:                            ; preds = %.lr.ph, %.lr.ph.split.split.us
  %16 = phi i64 [ %23, %.lr.ph.split.split.us ], [ %7, %.lr.ph ]
  %.01216.us19 = phi ptr [ %22, %.lr.ph.split.split.us ], [ %5, %.lr.ph ]
  %.01315.us20 = phi ptr [ %19, %.lr.ph.split.split.us ], [ %4, %.lr.ph ]
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %.sroa.0, ptr noundef nonnull align 1 dereferenceable(16) %3, i64 16, i1 false)
  %17 = tail call i32 @mbedtls_aes_crypt_ecb(ptr noundef %0, i32 noundef 1, ptr noundef %3, ptr noundef %3)
  %18 = load i8, ptr %3, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.01315.us20, i64 1
  %20 = load i8, ptr %.01315.us20, align 1, !tbaa !5
  %21 = xor i8 %20, %18
  %22 = getelementptr inbounds i8, ptr %.01216.us19, i64 1
  store i8 %21, ptr %.01216.us19, align 1, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(15) %3, ptr noundef nonnull align 1 dereferenceable(15) %.sroa.0.1.sroa_idx, i64 15, i1 false)
  store i8 %21, ptr %.sroa.4.1..sroa_idx, align 1
  %23 = add i64 %16, -1
  %.not.us21 = icmp eq i64 %16, 0
  br i1 %.not.us21, label %._crit_edge, label %.lr.ph.split.split.us, !llvm.loop !8

.lr.ph.split.split:                               ; preds = %.lr.ph, %.lr.ph.split.split
  %24 = phi i64 [ %31, %.lr.ph.split.split ], [ %7, %.lr.ph ]
  %.01216 = phi ptr [ %30, %.lr.ph.split.split ], [ %5, %.lr.ph ]
  %.01315 = phi ptr [ %27, %.lr.ph.split.split ], [ %4, %.lr.ph ]
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %.sroa.0, ptr noundef nonnull align 1 dereferenceable(16) %3, i64 16, i1 false)
  %25 = tail call i32 @mbedtls_aes_crypt_ecb(ptr noundef %0, i32 noundef 1, ptr noundef %3, ptr noundef %3)
  %26 = load i8, ptr %3, align 1, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %.01315, i64 1
  %28 = load i8, ptr %.01315, align 1, !tbaa !5
  %29 = xor i8 %28, %26
  %30 = getelementptr inbounds i8, ptr %.01216, i64 1
  store i8 %29, ptr %.01216, align 1, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(15) %3, ptr noundef nonnull align 1 dereferenceable(15) %.sroa.0.1.sroa_idx, i64 15, i1 false)
  %31 = add i64 %24, -1
  %.not = icmp eq i64 %24, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.split.split, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph.split.split.us, %.lr.ph.split.us.split, %.lr.ph.split.split, %6
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %.sroa.0)
  ret i32 0
}

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

!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,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass