; 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_group = type { i32, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_ecp_point, %struct.mbedtls_mpi, i64, i64, i32, ptr, ptr, ptr, ptr, ptr, i64 }
%struct.mbedtls_ecp_point = type { %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi }
%struct.mbedtls_mpi = type { i32, i64, ptr }
%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_grp_id(i32 noundef) #1

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

12:                                               ; preds = %4
  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
  br label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.mbedtls_ecp_group, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = call ptr @mbedtls_ecp_curve_info_from_grp_id(i32 noundef %23)
  store ptr %24, ptr %10, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %27

26:                                               ; preds = %20
  store i32 -20352, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %53

27:                                               ; preds = %20
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 3, ptr %28, align 8, !tbaa !9
  %29 = load i64, ptr %9, align 8, !tbaa !9
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load i64, ptr %30, align 8, !tbaa !9
  %32 = icmp ult i64 %29, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %27
  store i32 -20224, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %53

34:                                               ; preds = %27
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i32 1
  store ptr %36, ptr %8, align 8, !tbaa !5
  store i8 3, ptr %35, align 1, !tbaa !16
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.mbedtls_ecp_curve_info, ptr %37, i32 0, i32 1
  %39 = load i16, ptr %38, align 4, !tbaa !17
  %40 = zext i16 %39 to i32
  %41 = ashr i32 %40, 8
  %42 = trunc i32 %41 to i8
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i64 0
  store i8 %42, ptr %44, align 1, !tbaa !16
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.mbedtls_ecp_curve_info, ptr %45, i32 0, i32 1
  %47 = load i16, ptr %46, align 4, !tbaa !17
  %48 = zext i16 %47 to i32
  %49 = and i32 %48, 255
  %50 = trunc i32 %49 to i8
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i64 1
  store i8 %50, ptr %52, align 1, !tbaa !16
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %53

53:                                               ; preds = %34, %33, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %54 = load i32, ptr %5, align 4
  ret i32 %54
}

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, !13, i64 0}
!12 = !{!"mbedtls_ecp_group", !13, i64 0, !14, i64 8, !14, i64 32, !14, i64 56, !15, i64 80, !14, i64 152, !10, i64 176, !10, i64 184, !13, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !10, i64 240}
!13 = !{!"int", !7, i64 0}
!14 = !{!"mbedtls_mpi", !13, i64 0, !10, i64 8, !6, i64 16}
!15 = !{!"mbedtls_ecp_point", !14, i64 0, !14, i64 24, !14, i64 48}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !19, i64 4}
!18 = !{!"mbedtls_ecp_curve_info", !13, i64 0, !19, i64 4, !19, i64 6, !6, i64 8}
!19 = !{!"short", !7, 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_grp_id(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -20352, 1) i32 @mbedtls_ecp_tls_write_group(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef writeonly %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = load i32, ptr %0, align 8, !tbaa !5
  %6 = tail call ptr @mbedtls_ecp_curve_info_from_grp_id(i32 noundef %5)
  %7 = icmp eq ptr %6, null
  br i1 %7, label %19, label %8

8:                                                ; preds = %4
  store i64 3, ptr %1, align 8, !tbaa !14
  %9 = icmp ult i64 %3, 3
  br i1 %9, label %19, label %10

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %2, i64 1
  store i8 3, ptr %2, align 1, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %6, i64 4
  %13 = load i16, ptr %12, align 4, !tbaa !16
  %14 = lshr i16 %13, 8
  %15 = trunc nuw i16 %14 to i8
  store i8 %15, ptr %11, align 1, !tbaa !15
  %16 = load i16, ptr %12, align 4, !tbaa !16
  %17 = trunc i16 %16 to i8
  %18 = getelementptr inbounds i8, ptr %2, i64 2
  store i8 %17, ptr %18, align 1, !tbaa !15
  br label %19

19:                                               ; preds = %8, %4, %10
  %.0 = phi i32 [ 0, %10 ], [ -20352, %4 ], [ -20224, %8 ]
  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, !7, i64 0}
!6 = !{!"mbedtls_ecp_group", !7, i64 0, !10, i64 8, !10, i64 32, !10, i64 56, !13, i64 80, !10, i64 152, !11, i64 176, !11, i64 184, !7, i64 192, !12, i64 200, !12, i64 208, !12, i64 216, !12, i64 224, !12, i64 232, !11, i64 240}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"mbedtls_mpi", !7, i64 0, !11, i64 8, !12, i64 16}
!11 = !{!"long", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"mbedtls_ecp_point", !10, i64 0, !10, i64 24, !10, i64 48}
!14 = !{!11, !11, i64 0}
!15 = !{!8, !8, i64 0}
!16 = !{!17, !18, i64 4}
!17 = !{!"mbedtls_ecp_curve_info", !7, i64 0, !18, i64 4, !18, i64 6, !12, i64 8}
!18 = !{!"short", !8, i64 0}


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