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

; 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_ecp_curve_info = type { i32, i16, i16, ptr }

; 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 ptr @mbedtls_ecp_curve_info_from_tls_id(i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_ecp_tls_read_group_id(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i16, align 2
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  br label %11

11:                                               ; preds = %3
  br label %12

12:                                               ; preds = %11
  br label %13

13:                                               ; preds = %12
  br label %14

14:                                               ; preds = %13
  br label %15

15:                                               ; preds = %14
  br label %16

16:                                               ; preds = %15
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = icmp ult i64 %20, 3
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  store i32 -20352, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %59

23:                                               ; preds = %19
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i32 1
  store ptr %26, ptr %24, align 8, !tbaa !5
  %27 = load i8, ptr %25, align 1, !tbaa !11
  %28 = zext i8 %27 to i32
  %29 = icmp ne i32 %28, 3
  br i1 %29, label %30, label %31

30:                                               ; preds = %23
  store i32 -20352, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %59

31:                                               ; preds = %23
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i32 1
  store ptr %34, ptr %32, align 8, !tbaa !5
  %35 = load i8, ptr %33, align 1, !tbaa !11
  %36 = zext i8 %35 to i16
  store i16 %36, ptr %8, align 2, !tbaa !12
  %37 = load i16, ptr %8, align 2, !tbaa !12
  %38 = zext i16 %37 to i32
  %39 = shl i32 %38, 8
  %40 = trunc i32 %39 to i16
  store i16 %40, ptr %8, align 2, !tbaa !12
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i32 1
  store ptr %43, ptr %41, align 8, !tbaa !5
  %44 = load i8, ptr %42, align 1, !tbaa !11
  %45 = zext i8 %44 to i32
  %46 = load i16, ptr %8, align 2, !tbaa !12
  %47 = zext i16 %46 to i32
  %48 = or i32 %47, %45
  %49 = trunc i32 %48 to i16
  store i16 %49, ptr %8, align 2, !tbaa !12
  %50 = load i16, ptr %8, align 2, !tbaa !12
  %51 = call ptr @mbedtls_ecp_curve_info_from_tls_id(i16 noundef zeroext %50)
  store ptr %51, ptr %9, align 8, !tbaa !5
  %52 = icmp eq ptr %51, null
  br i1 %52, label %53, label %54

53:                                               ; preds = %31
  store i32 -20096, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %59

54:                                               ; preds = %31
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.mbedtls_ecp_curve_info, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %56, align 8, !tbaa !14
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %57, ptr %58, align 4, !tbaa !17
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %59

59:                                               ; preds = %54, %53, %30, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #2
  %60 = load i32, ptr %4, align 4
  ret i32 %60
}

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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !16, i64 0}
!15 = !{!"mbedtls_ecp_curve_info", !16, i64 0, !13, i64 4, !13, i64 6, !6, i64 8}
!16 = !{!"int", !7, i64 0}
!17 = !{!16, !16, i64 0}


; 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 ptr @mbedtls_ecp_curve_info_from_tls_id(i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -20352, 1) i32 @mbedtls_ecp_tls_read_group_id(ptr nocapture noundef writeonly %0, ptr nocapture noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = icmp ult i64 %2, 3
  br i1 %4, label %22, label %5

5:                                                ; preds = %3
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 1
  store ptr %7, ptr %1, align 8, !tbaa !5
  %8 = load i8, ptr %6, align 1, !tbaa !9
  %.not = icmp eq i8 %8, 3
  br i1 %.not, label %9, label %22

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %6, i64 2
  store ptr %10, ptr %1, align 8, !tbaa !5
  %11 = load i8, ptr %7, align 1, !tbaa !9
  %12 = zext i8 %11 to i16
  %13 = shl nuw i16 %12, 8
  %14 = getelementptr inbounds i8, ptr %6, i64 3
  store ptr %14, ptr %1, align 8, !tbaa !5
  %15 = load i8, ptr %10, align 1, !tbaa !9
  %16 = zext i8 %15 to i16
  %17 = or disjoint i16 %13, %16
  %18 = tail call ptr @mbedtls_ecp_curve_info_from_tls_id(i16 noundef zeroext %17)
  %19 = icmp eq ptr %18, null
  br i1 %19, label %22, label %20

20:                                               ; preds = %9
  %21 = load i32, ptr %18, align 8, !tbaa !10
  store i32 %21, ptr %0, align 4, !tbaa !14
  br label %22

22:                                               ; preds = %9, %5, %3, %20
  %.0 = phi i32 [ 0, %20 ], [ -20352, %3 ], [ -20352, %5 ], [ -20096, %9 ]
  ret i32 %.0
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"mbedtls_ecp_curve_info", !12, i64 0, !13, i64 4, !13, i64 6, !6, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !12, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass