; 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_point = type { %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi }
%struct.mbedtls_mpi = type { i32, i64, ptr }
%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_keypair = type { %struct.mbedtls_ecp_group, %struct.mbedtls_mpi, %struct.mbedtls_ecp_point }

; 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 void @mbedtls_ecp_point_init(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_ecp_group_init(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_ecp_point_free(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_ecp_group_free(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_ecp_group_copy(ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_ecp_mul(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_ecp_check_pub_priv(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.mbedtls_ecp_point, align 8
  %8 = alloca %struct.mbedtls_ecp_group, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 -110, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 72, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 248, ptr %8) #3
  br label %10

10:                                               ; preds = %2
  br label %11

11:                                               ; preds = %10
  br label %12

12:                                               ; preds = %11
  br label %13

13:                                               ; preds = %12
  br label %14

14:                                               ; preds = %13
  br label %15

15:                                               ; preds = %14
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %16, i32 0, i32 0
  %18 = getelementptr inbounds %struct.mbedtls_ecp_group, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %58, label %21

21:                                               ; preds = %15
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %22, i32 0, i32 0
  %24 = getelementptr inbounds %struct.mbedtls_ecp_group, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %struct.mbedtls_ecp_group, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = icmp ne i32 %25, %29
  br i1 %30, label %58, label %31

31:                                               ; preds = %21
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %32, i32 0, i32 2
  %34 = getelementptr inbounds %struct.mbedtls_ecp_point, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %35, i32 0, i32 2
  %37 = getelementptr inbounds %struct.mbedtls_ecp_point, ptr %36, i32 0, i32 0
  %38 = call i32 @mbedtls_mpi_cmp_mpi(ptr noundef %34, ptr noundef %37)
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %58, label %40

40:                                               ; preds = %31
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %41, i32 0, i32 2
  %43 = getelementptr inbounds %struct.mbedtls_ecp_point, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %44, i32 0, i32 2
  %46 = getelementptr inbounds %struct.mbedtls_ecp_point, ptr %45, i32 0, i32 1
  %47 = call i32 @mbedtls_mpi_cmp_mpi(ptr noundef %43, ptr noundef %46)
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %58, label %49

49:                                               ; preds = %40
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %50, i32 0, i32 2
  %52 = getelementptr inbounds %struct.mbedtls_ecp_point, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %53, i32 0, i32 2
  %55 = getelementptr inbounds %struct.mbedtls_ecp_point, ptr %54, i32 0, i32 2
  %56 = call i32 @mbedtls_mpi_cmp_mpi(ptr noundef %52, ptr noundef %55)
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %49, %40, %31, %21, %15
  store i32 -20352, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %99

59:                                               ; preds = %49
  call void @mbedtls_ecp_point_init(ptr noundef %7)
  call void @mbedtls_ecp_group_init(ptr noundef %8)
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %60, i32 0, i32 0
  %62 = call i32 @mbedtls_ecp_group_copy(ptr noundef %8, ptr noundef %61)
  br label %63

63:                                               ; preds = %59
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %66, i32 0, i32 0
  %68 = getelementptr inbounds %struct.mbedtls_ecp_group, ptr %67, i32 0, i32 4
  %69 = call i32 @mbedtls_ecp_mul(ptr noundef %8, ptr noundef %7, ptr noundef %65, ptr noundef %68, ptr noundef null, ptr noundef null)
  store i32 %69, ptr %6, align 4, !tbaa !9
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %63
  br label %97

72:                                               ; preds = %63
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73
  %75 = getelementptr inbounds %struct.mbedtls_ecp_point, ptr %7, i32 0, i32 0
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %76, i32 0, i32 2
  %78 = getelementptr inbounds %struct.mbedtls_ecp_point, ptr %77, i32 0, i32 0
  %79 = call i32 @mbedtls_mpi_cmp_mpi(ptr noundef %75, ptr noundef %78)
  %80 = icmp ne i32 %79, 0
  br i1 %80, label %95, label %81

81:                                               ; preds = %74
  %82 = getelementptr inbounds %struct.mbedtls_ecp_point, ptr %7, i32 0, i32 1
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %83, i32 0, i32 2
  %85 = getelementptr inbounds %struct.mbedtls_ecp_point, ptr %84, i32 0, i32 1
  %86 = call i32 @mbedtls_mpi_cmp_mpi(ptr noundef %82, ptr noundef %85)
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %95, label %88

88:                                               ; preds = %81
  %89 = getelementptr inbounds %struct.mbedtls_ecp_point, ptr %7, i32 0, i32 2
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %90, i32 0, i32 2
  %92 = getelementptr inbounds %struct.mbedtls_ecp_point, ptr %91, i32 0, i32 2
  %93 = call i32 @mbedtls_mpi_cmp_mpi(ptr noundef %89, ptr noundef %92)
  %94 = icmp ne i32 %93, 0
  br i1 %94, label %95, label %96

95:                                               ; preds = %88, %81, %74
  store i32 -20352, ptr %6, align 4, !tbaa !9
  br label %97

96:                                               ; preds = %88
  br label %97

97:                                               ; preds = %96, %95, %71
  call void @mbedtls_ecp_point_free(ptr noundef %7)
  call void @mbedtls_ecp_group_free(ptr noundef %8)
  %98 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %98, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %99

99:                                               ; preds = %97, %58
  call void @llvm.lifetime.end.p0(i64 248, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 72, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %100 = load i32, ptr %3, align 4
  ret i32 %100
}

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 = { "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 #3 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"mbedtls_ecp_keypair", !13, i64 0, !14, i64 248, !16, i64 272}
!13 = !{!"mbedtls_ecp_group", !10, i64 0, !14, i64 8, !14, i64 32, !14, i64 56, !16, i64 80, !14, i64 152, !15, i64 176, !15, i64 184, !10, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !15, i64 240}
!14 = !{!"mbedtls_mpi", !10, i64 0, !15, i64 8, !6, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!"mbedtls_ecp_point", !14, i64 0, !14, i64 24, !14, 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"

%struct.mbedtls_ecp_point = type { %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi }
%struct.mbedtls_mpi = type { i32, i64, ptr }
%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 }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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 void @mbedtls_ecp_point_init(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_ecp_group_init(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_ecp_point_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_ecp_group_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_ecp_group_copy(ptr noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_ecp_mul(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_ecp_check_pub_priv(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca %struct.mbedtls_ecp_point, align 8
  %4 = alloca %struct.mbedtls_ecp_group, align 8
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 248, ptr nonnull %4) #3
  %5 = load i32, ptr %0, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %36, label %7

7:                                                ; preds = %2
  %8 = load i32, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i32 %5, %8
  br i1 %.not, label %9, label %36

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 272
  %11 = getelementptr inbounds i8, ptr %1, i64 272
  %12 = tail call i32 @mbedtls_mpi_cmp_mpi(ptr noundef nonnull %10, ptr noundef nonnull %11) #3
  %.not19 = icmp eq i32 %12, 0
  br i1 %.not19, label %13, label %36

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %0, i64 296
  %15 = getelementptr inbounds i8, ptr %1, i64 296
  %16 = tail call i32 @mbedtls_mpi_cmp_mpi(ptr noundef nonnull %14, ptr noundef nonnull %15) #3
  %.not20 = icmp eq i32 %16, 0
  br i1 %.not20, label %17, label %36

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %0, i64 320
  %19 = getelementptr inbounds i8, ptr %1, i64 320
  %20 = tail call i32 @mbedtls_mpi_cmp_mpi(ptr noundef nonnull %18, ptr noundef nonnull %19) #3
  %.not21 = icmp eq i32 %20, 0
  br i1 %.not21, label %21, label %36

21:                                               ; preds = %17
  call void @mbedtls_ecp_point_init(ptr noundef nonnull %3)
  call void @mbedtls_ecp_group_init(ptr noundef nonnull %4)
  %22 = call i32 @mbedtls_ecp_group_copy(ptr noundef nonnull %4, ptr noundef nonnull %1)
  %23 = getelementptr inbounds i8, ptr %1, i64 248
  %24 = getelementptr inbounds i8, ptr %1, i64 80
  %25 = call i32 @mbedtls_ecp_mul(ptr noundef nonnull %4, ptr noundef nonnull %3, ptr noundef nonnull %23, ptr noundef nonnull %24, ptr noundef null, ptr noundef null)
  %.not22 = icmp eq i32 %25, 0
  br i1 %.not22, label %26, label %35

26:                                               ; preds = %21
  %27 = call i32 @mbedtls_mpi_cmp_mpi(ptr noundef nonnull %3, ptr noundef nonnull %11) #3
  %.not23 = icmp eq i32 %27, 0
  br i1 %.not23, label %28, label %34

28:                                               ; preds = %26
  %29 = getelementptr inbounds i8, ptr %3, i64 24
  %30 = call i32 @mbedtls_mpi_cmp_mpi(ptr noundef nonnull %29, ptr noundef nonnull %15) #3
  %.not24 = icmp eq i32 %30, 0
  br i1 %.not24, label %31, label %34

31:                                               ; preds = %28
  %32 = getelementptr inbounds i8, ptr %3, i64 48
  %33 = call i32 @mbedtls_mpi_cmp_mpi(ptr noundef nonnull %32, ptr noundef nonnull %19) #3
  %.not25 = icmp eq i32 %33, 0
  br i1 %.not25, label %35, label %34

34:                                               ; preds = %31, %28, %26
  br label %35

35:                                               ; preds = %31, %21, %34
  %.0 = phi i32 [ %25, %21 ], [ -20352, %34 ], [ 0, %31 ]
  call void @mbedtls_ecp_point_free(ptr noundef nonnull %3)
  call void @mbedtls_ecp_group_free(ptr noundef nonnull %4)
  br label %36

36:                                               ; preds = %2, %7, %9, %13, %17, %35
  %.016 = phi i32 [ %.0, %35 ], [ -20352, %17 ], [ -20352, %13 ], [ -20352, %9 ], [ -20352, %7 ], [ -20352, %2 ]
  call void @llvm.lifetime.end.p0(i64 248, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %3) #3
  ret i32 %.016
}

attributes #0 = { mustprogress 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 = { "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 #3 = { 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, !8, i64 0}
!6 = !{!"mbedtls_ecp_keypair", !7, i64 0, !11, i64 248, !14, i64 272}
!7 = !{!"mbedtls_ecp_group", !8, i64 0, !11, i64 8, !11, i64 32, !11, i64 56, !14, i64 80, !11, i64 152, !12, i64 176, !12, i64 184, !8, i64 192, !13, i64 200, !13, i64 208, !13, i64 216, !13, i64 224, !13, i64 232, !12, i64 240}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"mbedtls_mpi", !8, i64 0, !12, i64 8, !13, i64 16}
!12 = !{!"long", !9, i64 0}
!13 = !{!"any pointer", !9, i64 0}
!14 = !{!"mbedtls_ecp_point", !11, i64 0, !11, i64 24, !11, i64 48}


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