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

; 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.oid_ecp_grp_t = type { %struct.mbedtls_oid_descriptor_t, i32 }
%struct.mbedtls_oid_descriptor_t = type { ptr, i64, ptr, ptr }

@oid_ecp_grp = external hidden constant [12 x %struct.oid_ecp_grp_t], align 16

; 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
define dso_local i32 @mbedtls_oid_get_oid_by_ec_grp(i32 noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store ptr @oid_ecp_grp, ptr %8, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %33, %3
  %11 = load ptr, ptr %8, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.oid_ecp_grp_t, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds %struct.mbedtls_oid_descriptor_t, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %36

16:                                               ; preds = %10
  %17 = load ptr, ptr %8, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.oid_ecp_grp_t, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !15
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = icmp eq i32 %19, %20
  br i1 %21, label %22, label %33

22:                                               ; preds = %16
  %23 = load ptr, ptr %8, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.oid_ecp_grp_t, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds %struct.mbedtls_oid_descriptor_t, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %26, ptr %27, align 8, !tbaa !9
  %28 = load ptr, ptr %8, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.oid_ecp_grp_t, ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds %struct.mbedtls_oid_descriptor_t, ptr %29, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !16
  %32 = load ptr, ptr %7, align 8, !tbaa !9
  store i64 %31, ptr %32, align 8, !tbaa !17
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %37

33:                                               ; preds = %16
  %34 = load ptr, ptr %8, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.oid_ecp_grp_t, ptr %34, i32 1
  store ptr %35, ptr %8, align 8, !tbaa !9
  br label %10, !llvm.loop !18

36:                                               ; preds = %10
  store i32 -46, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %37

37:                                               ; preds = %36, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %38 = load i32, ptr %4, align 4
  ret i32 %38
}

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 = !{!"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, !10, i64 0}
!12 = !{!"", !13, i64 0, !6, i64 32}
!13 = !{!"mbedtls_oid_descriptor_t", !10, i64 0, !14, i64 8, !10, i64 16, !10, i64 24}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !6, i64 32}
!16 = !{!12, !14, i64 8}
!17 = !{!14, !14, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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.oid_ecp_grp_t = type { %struct.mbedtls_oid_descriptor_t, i32 }
%struct.mbedtls_oid_descriptor_t = type { ptr, i64, ptr, ptr }

@oid_ecp_grp = external hidden local_unnamed_addr constant [12 x %struct.oid_ecp_grp_t], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: write) uwtable
define dso_local range(i32 -46, 1) i32 @mbedtls_oid_get_oid_by_ec_grp(i32 noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr @oid_ecp_grp, align 16, !tbaa !5
  %.not12 = icmp eq ptr %4, null
  br i1 %.not12, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %5 = load i32, ptr getelementptr inbounds (i8, ptr @oid_ecp_grp, i64 32), align 16, !tbaa !13
  %6 = icmp eq i32 %5, %0
  br i1 %6, label %.lr.ph._crit_edge, label %.lr.ph21

.lr.ph:                                           ; preds = %.lr.ph21
  %7 = getelementptr inbounds i8, ptr %.01320, i64 72
  %8 = load i32, ptr %7, align 8, !tbaa !13
  %9 = icmp eq i32 %8, %0
  br i1 %9, label %.lr.ph._crit_edge, label %.lr.ph21, !llvm.loop !14

.lr.ph._crit_edge:                                ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa = phi ptr [ %4, %.lr.ph.preheader ], [ %13, %.lr.ph ]
  %.013.lcssa = phi ptr [ @oid_ecp_grp, %.lr.ph.preheader ], [ %12, %.lr.ph ]
  store ptr %.lcssa, ptr %1, align 8, !tbaa !16
  %10 = getelementptr inbounds i8, ptr %.013.lcssa, i64 8
  %11 = load i64, ptr %10, align 8, !tbaa !17
  store i64 %11, ptr %2, align 8, !tbaa !18
  br label %.loopexit

.lr.ph21:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %.01320 = phi ptr [ %12, %.lr.ph ], [ @oid_ecp_grp, %.lr.ph.preheader ]
  %12 = getelementptr inbounds i8, ptr %.01320, i64 40
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !14

.loopexit:                                        ; preds = %.lr.ph21, %3, %.lr.ph._crit_edge
  %.08 = phi i32 [ 0, %.lr.ph._crit_edge ], [ -46, %3 ], [ -46, %.lr.ph21 ]
  ret i32 %.08
}

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


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