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

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

declare void @mbedtls_mpi_free(ptr noundef) #2

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

declare i32 @mbedtls_mpi_read_binary_le(ptr noundef, ptr noundef, i64 noundef) #2

declare i32 @mbedtls_mpi_set_bit(ptr noundef, i64 noundef, i8 noundef zeroext) #2

declare i32 @mbedtls_mpi_read_binary(ptr noundef, ptr noundef, i64 noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_ecp_read_key(i32 noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !5
  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
  %18 = load ptr, ptr %7, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = call i32 @mbedtls_ecp_group_load(ptr noundef %19, i32 noundef %20)
  store i32 %21, ptr %10, align 4, !tbaa !5
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %17
  %24 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %24, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %133

25:                                               ; preds = %17
  store i32 -20096, ptr %10, align 4, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %26, i32 0, i32 0
  %28 = call i32 @mbedtls_ecp_get_type(ptr noundef %27)
  %29 = icmp eq i32 %28, 2
  br i1 %29, label %30, label %96

30:                                               ; preds = %25
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = icmp eq i32 %31, 9
  br i1 %32, label %33, label %94

33:                                               ; preds = %30
  %34 = load i64, ptr %9, align 8, !tbaa !11
  %35 = icmp ne i64 %34, 32
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  store i32 -19584, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %133

37:                                               ; preds = %33
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %7, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %8, align 8, !tbaa !9
  %42 = load i64, ptr %9, align 8, !tbaa !11
  %43 = call i32 @mbedtls_mpi_read_binary_le(ptr noundef %40, ptr noundef %41, i64 noundef %42)
  store i32 %43, ptr %10, align 4, !tbaa !5
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %38
  br label %125

46:                                               ; preds = %38
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr %7, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %50, i32 0, i32 1
  %52 = call i32 @mbedtls_mpi_set_bit(ptr noundef %51, i64 noundef 0, i8 noundef zeroext 0)
  store i32 %52, ptr %10, align 4, !tbaa !5
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %49
  br label %125

55:                                               ; preds = %49
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57
  %59 = load ptr, ptr %7, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %59, i32 0, i32 1
  %61 = call i32 @mbedtls_mpi_set_bit(ptr noundef %60, i64 noundef 1, i8 noundef zeroext 0)
  store i32 %61, ptr %10, align 4, !tbaa !5
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %64

63:                                               ; preds = %58
  br label %125

64:                                               ; preds = %58
  br label %65

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr %7, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %68, i32 0, i32 1
  %70 = call i32 @mbedtls_mpi_set_bit(ptr noundef %69, i64 noundef 2, i8 noundef zeroext 0)
  store i32 %70, ptr %10, align 4, !tbaa !5
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %73

72:                                               ; preds = %67
  br label %125

73:                                               ; preds = %67
  br label %74

74:                                               ; preds = %73
  br label %75

75:                                               ; preds = %74
  br label %76

76:                                               ; preds = %75
  %77 = load ptr, ptr %7, align 8, !tbaa !9
  %78 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %77, i32 0, i32 1
  %79 = call i32 @mbedtls_mpi_set_bit(ptr noundef %78, i64 noundef 255, i8 noundef zeroext 0)
  store i32 %79, ptr %10, align 4, !tbaa !5
  %80 = icmp ne i32 %79, 0
  br i1 %80, label %81, label %82

81:                                               ; preds = %76
  br label %125

82:                                               ; preds = %76
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %83
  br label %85

85:                                               ; preds = %84
  %86 = load ptr, ptr %7, align 8, !tbaa !9
  %87 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %86, i32 0, i32 1
  %88 = call i32 @mbedtls_mpi_set_bit(ptr noundef %87, i64 noundef 254, i8 noundef zeroext 1)
  store i32 %88, ptr %10, align 4, !tbaa !5
  %89 = icmp ne i32 %88, 0
  br i1 %89, label %90, label %91

90:                                               ; preds = %85
  br label %125

91:                                               ; preds = %85
  br label %92

92:                                               ; preds = %91
  br label %93

93:                                               ; preds = %92
  br label %95

94:                                               ; preds = %30
  store i32 -20096, ptr %10, align 4, !tbaa !5
  br label %95

95:                                               ; preds = %94, %93
  br label %96

96:                                               ; preds = %95, %25
  %97 = load ptr, ptr %7, align 8, !tbaa !9
  %98 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %97, i32 0, i32 0
  %99 = call i32 @mbedtls_ecp_get_type(ptr noundef %98)
  %100 = icmp eq i32 %99, 1
  br i1 %100, label %101, label %124

101:                                              ; preds = %96
  br label %102

102:                                              ; preds = %101
  %103 = load ptr, ptr %7, align 8, !tbaa !9
  %104 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %103, i32 0, i32 1
  %105 = load ptr, ptr %8, align 8, !tbaa !9
  %106 = load i64, ptr %9, align 8, !tbaa !11
  %107 = call i32 @mbedtls_mpi_read_binary(ptr noundef %104, ptr noundef %105, i64 noundef %106)
  store i32 %107, ptr %10, align 4, !tbaa !5
  %108 = icmp ne i32 %107, 0
  br i1 %108, label %109, label %110

109:                                              ; preds = %102
  br label %125

110:                                              ; preds = %102
  br label %111

111:                                              ; preds = %110
  br label %112

112:                                              ; preds = %111
  br label %113

113:                                              ; preds = %112
  %114 = load ptr, ptr %7, align 8, !tbaa !9
  %115 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %114, i32 0, i32 0
  %116 = load ptr, ptr %7, align 8, !tbaa !9
  %117 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %116, i32 0, i32 1
  %118 = call i32 @mbedtls_ecp_check_privkey(ptr noundef %115, ptr noundef %117)
  store i32 %118, ptr %10, align 4, !tbaa !5
  %119 = icmp ne i32 %118, 0
  br i1 %119, label %120, label %121

120:                                              ; preds = %113
  br label %125

121:                                              ; preds = %113
  br label %122

122:                                              ; preds = %121
  br label %123

123:                                              ; preds = %122
  br label %124

124:                                              ; preds = %123, %96
  br label %125

125:                                              ; preds = %124, %120, %109, %90, %81, %72, %63, %54, %45
  %126 = load i32, ptr %10, align 4, !tbaa !5
  %127 = icmp ne i32 %126, 0
  br i1 %127, label %128, label %131

128:                                              ; preds = %125
  %129 = load ptr, ptr %7, align 8, !tbaa !9
  %130 = getelementptr inbounds %struct.mbedtls_ecp_keypair, ptr %129, i32 0, i32 1
  call void @mbedtls_mpi_free(ptr noundef %130)
  br label %131

131:                                              ; preds = %128, %125
  %132 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %132, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %133

133:                                              ; preds = %131, %36, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %134 = load i32, ptr %5, align 4
  ret i32 %134
}

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 = !{!"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, !12, i64 0}
!12 = !{!"long", !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 i32 @mbedtls_ecp_get_type(ptr noundef) local_unnamed_addr #0

declare void @mbedtls_mpi_free(ptr noundef) local_unnamed_addr #1

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

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

declare i32 @mbedtls_mpi_set_bit(ptr noundef, i64 noundef, i8 noundef zeroext) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_ecp_read_key(i32 noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = tail call i32 @mbedtls_ecp_group_load(ptr noundef %1, i32 noundef %0) #2
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %6, label %34

6:                                                ; preds = %4
  %7 = tail call i32 @mbedtls_ecp_get_type(ptr noundef %1)
  %8 = icmp eq i32 %7, 2
  %9 = icmp eq i32 %0, 9
  %or.cond = and i1 %9, %8
  br i1 %or.cond, label %10, label %24

10:                                               ; preds = %6
  %.not34 = icmp eq i64 %3, 32
  br i1 %.not34, label %11, label %34

11:                                               ; preds = %10
  %12 = getelementptr inbounds i8, ptr %1, i64 248
  %13 = tail call i32 @mbedtls_mpi_read_binary_le(ptr noundef nonnull %12, ptr noundef %2, i64 noundef 32) #2
  %.not35 = icmp eq i32 %13, 0
  br i1 %.not35, label %14, label %.thread

14:                                               ; preds = %11
  %15 = tail call i32 @mbedtls_mpi_set_bit(ptr noundef nonnull %12, i64 noundef 0, i8 noundef zeroext 0) #2
  %.not36 = icmp eq i32 %15, 0
  br i1 %.not36, label %16, label %.thread

16:                                               ; preds = %14
  %17 = tail call i32 @mbedtls_mpi_set_bit(ptr noundef nonnull %12, i64 noundef 1, i8 noundef zeroext 0) #2
  %.not37 = icmp eq i32 %17, 0
  br i1 %.not37, label %18, label %.thread

18:                                               ; preds = %16
  %19 = tail call i32 @mbedtls_mpi_set_bit(ptr noundef nonnull %12, i64 noundef 2, i8 noundef zeroext 0) #2
  %.not38 = icmp eq i32 %19, 0
  br i1 %.not38, label %20, label %.thread

20:                                               ; preds = %18
  %21 = tail call i32 @mbedtls_mpi_set_bit(ptr noundef nonnull %12, i64 noundef 255, i8 noundef zeroext 0) #2
  %.not39 = icmp eq i32 %21, 0
  br i1 %.not39, label %22, label %.thread

22:                                               ; preds = %20
  %23 = tail call i32 @mbedtls_mpi_set_bit(ptr noundef nonnull %12, i64 noundef 254, i8 noundef zeroext 1) #2
  %.not40 = icmp eq i32 %23, 0
  br i1 %.not40, label %24, label %.thread

24:                                               ; preds = %22, %6
  %.0 = phi i32 [ 0, %22 ], [ -20096, %6 ]
  %25 = tail call i32 @mbedtls_ecp_get_type(ptr noundef %1)
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %27, label %32

27:                                               ; preds = %24
  %28 = getelementptr inbounds i8, ptr %1, i64 248
  %29 = tail call i32 @mbedtls_mpi_read_binary(ptr noundef nonnull %28, ptr noundef %2, i64 noundef %3) #2
  %.not41 = icmp eq i32 %29, 0
  br i1 %.not41, label %30, label %.thread

30:                                               ; preds = %27
  %31 = tail call i32 @mbedtls_ecp_check_privkey(ptr noundef %1, ptr noundef nonnull %28)
  br label %32

32:                                               ; preds = %30, %24
  %.1 = phi i32 [ %31, %30 ], [ %.0, %24 ]
  %.not42 = icmp eq i32 %.1, 0
  br i1 %.not42, label %34, label %.thread

.thread:                                          ; preds = %27, %22, %20, %18, %16, %14, %11, %32
  %.145 = phi i32 [ %.1, %32 ], [ %29, %27 ], [ %23, %22 ], [ %21, %20 ], [ %19, %18 ], [ %17, %16 ], [ %15, %14 ], [ %13, %11 ]
  %33 = getelementptr inbounds i8, ptr %1, i64 248
  tail call void @mbedtls_mpi_free(ptr noundef nonnull %33) #2
  br label %34

34:                                               ; preds = %32, %.thread, %10, %4
  %.023 = phi i32 [ %5, %4 ], [ -19584, %10 ], [ %.145, %.thread ], [ 0, %32 ]
  ret i32 %.023
}

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)"}


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