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

@oid_sig_alg = external hidden constant [14 x %struct.oid_sig_alg_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_sig_alg(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store ptr @oid_sig_alg, ptr %10, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %41, %4
  %13 = load ptr, ptr %10, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.oid_sig_alg_t, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.mbedtls_oid_descriptor_t, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %44

18:                                               ; preds = %12
  %19 = load ptr, ptr %10, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.oid_sig_alg_t, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !15
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = icmp eq i32 %21, %22
  br i1 %23, label %24, label %41

24:                                               ; preds = %18
  %25 = load ptr, ptr %10, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.oid_sig_alg_t, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 8, !tbaa !16
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = icmp eq i32 %27, %28
  br i1 %29, label %30, label %41

30:                                               ; preds = %24
  %31 = load ptr, ptr %10, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.oid_sig_alg_t, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds %struct.mbedtls_oid_descriptor_t, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %34, ptr %35, align 8, !tbaa !9
  %36 = load ptr, ptr %10, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.oid_sig_alg_t, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds %struct.mbedtls_oid_descriptor_t, ptr %37, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !17
  %40 = load ptr, ptr %9, align 8, !tbaa !9
  store i64 %39, ptr %40, align 8, !tbaa !18
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %45

41:                                               ; preds = %24, %18
  %42 = load ptr, ptr %10, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.oid_sig_alg_t, ptr %42, i32 1
  store ptr %43, ptr %10, align 8, !tbaa !9
  br label %12, !llvm.loop !19

44:                                               ; preds = %12
  store i32 -46, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %45

45:                                               ; preds = %44, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %46 = load i32, ptr %5, align 4
  ret i32 %46
}

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, !6, i64 36}
!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 36}
!16 = !{!12, !6, i64 32}
!17 = !{!12, !14, i64 8}
!18 = !{!14, !14, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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_sig_alg_t = type { %struct.mbedtls_oid_descriptor_t, i32, i32 }
%struct.mbedtls_oid_descriptor_t = type { ptr, i64, ptr, ptr }

@oid_sig_alg = external hidden local_unnamed_addr constant [14 x %struct.oid_sig_alg_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_sig_alg(i32 noundef %0, i32 noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = load ptr, ptr @oid_sig_alg, align 16, !tbaa !5
  %.not14 = icmp eq ptr %5, null
  br i1 %.not14, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %4, %17
  %6 = phi ptr [ %19, %17 ], [ %5, %4 ]
  %.015 = phi ptr [ %18, %17 ], [ @oid_sig_alg, %4 ]
  %7 = getelementptr inbounds i8, ptr %.015, i64 36
  %8 = load i32, ptr %7, align 4, !tbaa !13
  %9 = icmp eq i32 %8, %0
  br i1 %9, label %10, label %17

10:                                               ; preds = %.lr.ph
  %11 = getelementptr inbounds i8, ptr %.015, i64 32
  %12 = load i32, ptr %11, align 8, !tbaa !14
  %13 = icmp eq i32 %12, %1
  br i1 %13, label %14, label %17

14:                                               ; preds = %10
  store ptr %6, ptr %2, align 8, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %.015, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !16
  store i64 %16, ptr %3, align 8, !tbaa !17
  br label %.loopexit

17:                                               ; preds = %10, %.lr.ph
  %18 = getelementptr inbounds i8, ptr %.015, i64 40
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %.not = icmp eq ptr %19, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !18

.loopexit:                                        ; preds = %17, %4, %14
  %.010 = phi i32 [ 0, %14 ], [ -46, %4 ], [ -46, %17 ]
  ret i32 %.010
}

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, !12, i64 36}
!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 36}
!14 = !{!6, !12, i64 32}
!15 = !{!8, !8, i64 0}
!16 = !{!6, !11, i64 8}
!17 = !{!11, !11, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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