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

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

%struct.mbedtls_cipher_definition_t = type { i32, ptr }

@supported_init = external hidden global i32, align 4
@mbedtls_cipher_definitions = external constant [0 x %struct.mbedtls_cipher_definition_t], align 8
@mbedtls_cipher_supported = external global [0 x i32], align 4

; Function Attrs: nounwind uwtable
define dso_local ptr @mbedtls_cipher_list() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  %3 = load i32, ptr @supported_init, align 4, !tbaa !5
  %4 = icmp ne i32 %3, 0
  br i1 %4, label %20, label %5

5:                                                ; preds = %0
  store ptr @mbedtls_cipher_definitions, ptr %1, align 8, !tbaa !9
  store ptr @mbedtls_cipher_supported, ptr %2, align 8, !tbaa !9
  br label %6

6:                                                ; preds = %11, %5
  %7 = load ptr, ptr %1, align 8, !tbaa !9
  %8 = getelementptr inbounds %struct.mbedtls_cipher_definition_t, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !11
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %18

11:                                               ; preds = %6
  %12 = load ptr, ptr %1, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.mbedtls_cipher_definition_t, ptr %12, i32 1
  store ptr %13, ptr %1, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.mbedtls_cipher_definition_t, ptr %12, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = load ptr, ptr %2, align 8, !tbaa !9
  %17 = getelementptr inbounds i32, ptr %16, i32 1
  store ptr %17, ptr %2, align 8, !tbaa !9
  store i32 %15, ptr %16, align 4, !tbaa !5
  br label %6, !llvm.loop !13

18:                                               ; preds = %6
  %19 = load ptr, ptr %2, align 8, !tbaa !9
  store i32 0, ptr %19, align 4, !tbaa !5
  store i32 1, ptr @supported_init, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %18, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret ptr @mbedtls_cipher_supported
}

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

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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !10, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%struct.mbedtls_cipher_definition_t = type { i32, ptr }

@supported_init = external hidden local_unnamed_addr global i32, align 4
@mbedtls_cipher_definitions = external local_unnamed_addr constant [0 x %struct.mbedtls_cipher_definition_t], align 8
@mbedtls_cipher_supported = external global [0 x i32], align 4

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: write, inaccessiblemem: none) uwtable
define dso_local noundef nonnull ptr @mbedtls_cipher_list() local_unnamed_addr #0 {
  %1 = load i32, ptr @supported_init, align 4, !tbaa !5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %.preheader, label %7

.preheader:                                       ; preds = %0
  %2 = load i32, ptr @mbedtls_cipher_definitions, align 8, !tbaa !9
  %.not67 = icmp eq i32 %2, 0
  br i1 %.not67, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %3 = phi i32 [ %6, %.lr.ph ], [ %2, %.preheader ]
  %.09 = phi ptr [ %5, %.lr.ph ], [ @mbedtls_cipher_supported, %.preheader ]
  %.048 = phi ptr [ %4, %.lr.ph ], [ @mbedtls_cipher_definitions, %.preheader ]
  %4 = getelementptr inbounds i8, ptr %.048, i64 16
  %5 = getelementptr inbounds i8, ptr %.09, i64 4
  store i32 %3, ptr %.09, align 4, !tbaa !5
  %6 = load i32, ptr %4, align 8, !tbaa !9
  %.not6 = icmp eq i32 %6, 0
  br i1 %.not6, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.0.lcssa = phi ptr [ @mbedtls_cipher_supported, %.preheader ], [ %5, %.lr.ph ]
  store i32 0, ptr %.0.lcssa, align 4, !tbaa !5
  store i32 1, ptr @supported_init, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %._crit_edge, %0
  ret ptr @mbedtls_cipher_supported
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, argmem: write, inaccessiblemem: none) 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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