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

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_ecp_get_type(ptr noundef) #0

declare i32 @mbedtls_mpi_cmp_int(ptr noundef, i64 noundef) #1

declare i32 @mbedtls_mpi_cmp_mpi(ptr noundef, ptr noundef) #1

declare i32 @mbedtls_mpi_get_bit(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_ecp_check_privkey(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %2
  br label %7

7:                                                ; preds = %6
  br label %8

8:                                                ; preds = %7
  br label %9

9:                                                ; preds = %8
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call i32 @mbedtls_ecp_get_type(ptr noundef %10)
  %12 = icmp eq i32 %11, 2
  br i1 %12, label %13, label %41

13:                                               ; preds = %9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call i32 @mbedtls_mpi_get_bit(ptr noundef %14, i64 noundef 0)
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %29, label %17

17:                                               ; preds = %13
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call i32 @mbedtls_mpi_get_bit(ptr noundef %18, i64 noundef 1)
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %29, label %21

21:                                               ; preds = %17
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call i64 @mbedtls_mpi_bitlen(ptr noundef %22)
  %24 = sub i64 %23, 1
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.mbedtls_ecp_group, ptr %25, i32 0, i32 7
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = icmp ne i64 %24, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %21, %17, %13
  store i32 -19584, ptr %3, align 4
  br label %58

30:                                               ; preds = %21
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.mbedtls_ecp_group, ptr %31, i32 0, i32 7
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = icmp eq i64 %33, 254
  br i1 %34, label %35, label %40

35:                                               ; preds = %30
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = call i32 @mbedtls_mpi_get_bit(ptr noundef %36, i64 noundef 2)
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %35
  store i32 -19584, ptr %3, align 4
  br label %58

40:                                               ; preds = %35, %30
  store i32 0, ptr %3, align 4
  br label %58

41:                                               ; preds = %9
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = call i32 @mbedtls_ecp_get_type(ptr noundef %42)
  %44 = icmp eq i32 %43, 1
  br i1 %44, label %45, label %57

45:                                               ; preds = %41
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = call i32 @mbedtls_mpi_cmp_int(ptr noundef %46, i64 noundef 1)
  %48 = icmp slt i32 %47, 0
  br i1 %48, label %55, label %49

49:                                               ; preds = %45
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.mbedtls_ecp_group, ptr %51, i32 0, i32 5
  %53 = call i32 @mbedtls_mpi_cmp_mpi(ptr noundef %50, ptr noundef %52)
  %54 = icmp sge i32 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %49, %45
  store i32 -19584, ptr %3, align 4
  br label %58

56:                                               ; preds = %49
  store i32 0, ptr %3, align 4
  br label %58

57:                                               ; preds = %41
  store i32 -20352, ptr %3, align 4
  br label %58

58:                                               ; preds = %57, %56, %55, %40, %39, %29
  %59 = load i32, ptr %3, align 4
  ret i32 %59
}

declare i64 @mbedtls_mpi_bitlen(ptr noundef) #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 = { "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 = !{!10, !13, i64 184}
!10 = !{!"mbedtls_ecp_group", !11, i64 0, !12, i64 8, !12, i64 32, !12, i64 56, !14, i64 80, !12, i64 152, !13, i64 176, !13, i64 184, !11, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !13, i64 240}
!11 = !{!"int", !7, i64 0}
!12 = !{!"mbedtls_mpi", !11, i64 0, !13, i64 8, !6, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!"mbedtls_ecp_point", !12, i64 0, !12, i64 24, !12, i64 48}


; 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 i32 @mbedtls_ecp_get_type(ptr noundef) local_unnamed_addr #0

declare i32 @mbedtls_mpi_cmp_int(ptr noundef, i64 noundef) local_unnamed_addr #1

declare i32 @mbedtls_mpi_cmp_mpi(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @mbedtls_mpi_get_bit(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -20352, 1) i32 @mbedtls_ecp_check_privkey(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @mbedtls_ecp_get_type(ptr noundef %0)
  %4 = icmp eq i32 %3, 2
  br i1 %4, label %5, label %19

5:                                                ; preds = %2
  %6 = tail call i32 @mbedtls_mpi_get_bit(ptr noundef %1, i64 noundef 0) #2
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %28

7:                                                ; preds = %5
  %8 = tail call i32 @mbedtls_mpi_get_bit(ptr noundef %1, i64 noundef 1) #2
  %.not12 = icmp eq i32 %8, 0
  br i1 %.not12, label %9, label %28

9:                                                ; preds = %7
  %10 = tail call i64 @mbedtls_mpi_bitlen(ptr noundef %1) #2
  %11 = add i64 %10, -1
  %12 = getelementptr inbounds i8, ptr %0, i64 184
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %.not13 = icmp eq i64 %11, %13
  br i1 %.not13, label %14, label %28

14:                                               ; preds = %9
  %15 = icmp eq i64 %11, 254
  br i1 %15, label %16, label %18

16:                                               ; preds = %14
  %17 = tail call i32 @mbedtls_mpi_get_bit(ptr noundef %1, i64 noundef 2) #2
  %.not14 = icmp eq i32 %17, 0
  br i1 %.not14, label %18, label %28

18:                                               ; preds = %16, %14
  br label %28

19:                                               ; preds = %2
  %20 = tail call i32 @mbedtls_ecp_get_type(ptr noundef %0)
  %21 = icmp eq i32 %20, 1
  br i1 %21, label %22, label %28

22:                                               ; preds = %19
  %23 = tail call i32 @mbedtls_mpi_cmp_int(ptr noundef %1, i64 noundef 1) #2
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %28, label %25

25:                                               ; preds = %22
  %26 = getelementptr inbounds i8, ptr %0, i64 152
  %27 = tail call i32 @mbedtls_mpi_cmp_mpi(ptr noundef %1, ptr noundef nonnull %26) #2
  %.inv = icmp slt i32 %27, 0
  %spec.select = select i1 %.inv, i32 0, i32 -19584
  br label %28

28:                                               ; preds = %25, %19, %22, %16, %5, %7, %9, %18
  %.0 = phi i32 [ 0, %18 ], [ -19584, %9 ], [ -19584, %7 ], [ -19584, %5 ], [ -19584, %16 ], [ -19584, %22 ], [ -20352, %19 ], [ %spec.select, %25 ]
  ret i32 %.0
}

declare i64 @mbedtls_mpi_bitlen(ptr noundef) local_unnamed_addr #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 = { "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, !11, i64 184}
!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}


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