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

17:                                               ; preds = %6
  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 = %29
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = load i64, ptr %32, align 8, !tbaa !9
  store i64 %33, ptr %15, align 8, !tbaa !9
  %34 = load i64, ptr %15, align 8, !tbaa !9
  %35 = icmp ugt i64 %34, 15
  br i1 %35, label %36, label %37

36:                                               ; preds = %31
  store i32 -33, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %76

37:                                               ; preds = %31
  br label %38

38:                                               ; preds = %54, %37
  %39 = load i64, ptr %9, align 8, !tbaa !9
  %40 = add i64 %39, -1
  store i64 %40, ptr %9, align 8, !tbaa !9
  %41 = icmp ne i64 %39, 0
  br i1 %41, label %42, label %71

42:                                               ; preds = %38
  %43 = load i64, ptr %15, align 8, !tbaa !9
  %44 = icmp eq i64 %43, 0
  br i1 %44, label %45, label %54

45:                                               ; preds = %42
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = call i32 @mbedtls_aes_crypt_ecb(ptr noundef %46, i32 noundef 1, ptr noundef %47, ptr noundef %48)
  store i32 %49, ptr %14, align 4, !tbaa !11
  %50 = load i32, ptr %14, align 4, !tbaa !11
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %53

52:                                               ; preds = %45
  br label %74

53:                                               ; preds = %45
  br label %54

54:                                               ; preds = %53, %42
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i32 1
  store ptr %56, ptr %12, align 8, !tbaa !5
  %57 = load i8, ptr %55, align 1, !tbaa !13
  %58 = zext i8 %57 to i32
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  %60 = load i64, ptr %15, align 8, !tbaa !9
  %61 = getelementptr inbounds i8, ptr %59, i64 %60
  %62 = load i8, ptr %61, align 1, !tbaa !13
  %63 = zext i8 %62 to i32
  %64 = xor i32 %58, %63
  %65 = trunc i32 %64 to i8
  %66 = load ptr, ptr %13, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i32 1
  store ptr %67, ptr %13, align 8, !tbaa !5
  store i8 %65, ptr %66, align 1, !tbaa !13
  %68 = load i64, ptr %15, align 8, !tbaa !9
  %69 = add i64 %68, 1
  %70 = and i64 %69, 15
  store i64 %70, ptr %15, align 8, !tbaa !9
  br label %38, !llvm.loop !14

71:                                               ; preds = %38
  %72 = load i64, ptr %15, align 8, !tbaa !9
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  store i64 %72, ptr %73, align 8, !tbaa !9
  br label %74

74:                                               ; preds = %71, %52
  %75 = load i32, ptr %14, align 4, !tbaa !11
  store i32 %75, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %76

76:                                               ; preds = %74, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  %77 = load i32, ptr %7, align 4
  ret i32 %77
}

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 = { 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}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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: nounwind uwtable
declare dso_local i32 @mbedtls_aes_crypt_ecb(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_aes_crypt_ofb(ptr noundef %0, i64 noundef %1, ptr nocapture noundef %2, ptr noundef %3, ptr nocapture noundef readonly %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #0 {
  %7 = load i64, ptr %2, align 8, !tbaa !5
  %8 = icmp ugt i64 %7, 15
  br i1 %8, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %6
  %.not26 = icmp eq i64 %1, 0
  br i1 %.not26, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %13
  %.in = phi i64 [ %9, %13 ], [ %1, %.preheader ]
  %.029 = phi i64 [ %21, %13 ], [ %7, %.preheader ]
  %.01728 = phi ptr [ %19, %13 ], [ %5, %.preheader ]
  %.01827 = phi ptr [ %14, %13 ], [ %4, %.preheader ]
  %9 = add i64 %.in, -1
  %10 = icmp eq i64 %.029, 0
  br i1 %10, label %11, label %13

11:                                               ; preds = %.lr.ph
  %12 = tail call i32 @mbedtls_aes_crypt_ecb(ptr noundef %0, i32 noundef 1, ptr noundef %3, ptr noundef %3)
  %.not24 = icmp eq i32 %12, 0
  br i1 %.not24, label %13, label %.loopexit

13:                                               ; preds = %11, %.lr.ph
  %14 = getelementptr inbounds i8, ptr %.01827, i64 1
  %15 = load i8, ptr %.01827, align 1, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %3, i64 %.029
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = xor i8 %17, %15
  %19 = getelementptr inbounds i8, ptr %.01728, i64 1
  store i8 %18, ptr %.01728, align 1, !tbaa !9
  %20 = add nuw nsw i64 %.029, 1
  %21 = and i64 %20, 15
  %.not = icmp eq i64 %9, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %13, %.preheader
  %.0.lcssa = phi i64 [ %7, %.preheader ], [ %21, %13 ]
  store i64 %.0.lcssa, ptr %2, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %11, %._crit_edge, %6
  %.019 = phi i32 [ -33, %6 ], [ 0, %._crit_edge ], [ %12, %11 ]
  ret i32 %.019
}

attributes #0 = { 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" }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass