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

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

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_mpi_init(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_mpi_free(ptr noundef) #0

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @mbedtls_mpi_lsb(ptr noundef) #0

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

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

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

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

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

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

12:                                               ; preds = %3
  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
  call void @mbedtls_mpi_init(ptr noundef %10)
  call void @mbedtls_mpi_init(ptr noundef %11)
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call i32 @mbedtls_mpi_copy(ptr noundef %10, ptr noundef %22)
  store i32 %23, ptr %7, align 4, !tbaa !9
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  br label %133

26:                                               ; preds = %21
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call i32 @mbedtls_mpi_copy(ptr noundef %11, ptr noundef %30)
  store i32 %31, ptr %7, align 4, !tbaa !9
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %29
  br label %133

34:                                               ; preds = %29
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  %37 = call i64 @mbedtls_mpi_lsb(ptr noundef %10)
  store i64 %37, ptr %8, align 8, !tbaa !11
  %38 = call i64 @mbedtls_mpi_lsb(ptr noundef %11)
  store i64 %38, ptr %9, align 8, !tbaa !11
  %39 = load i64, ptr %9, align 8, !tbaa !11
  %40 = load i64, ptr %8, align 8, !tbaa !11
  %41 = icmp ult i64 %39, %40
  br i1 %41, label %42, label %44

42:                                               ; preds = %36
  %43 = load i64, ptr %9, align 8, !tbaa !11
  store i64 %43, ptr %8, align 8, !tbaa !11
  br label %44

44:                                               ; preds = %42, %36
  br label %45

45:                                               ; preds = %44
  %46 = load i64, ptr %8, align 8, !tbaa !11
  %47 = call i32 @mbedtls_mpi_shift_r(ptr noundef %10, i64 noundef %46)
  store i32 %47, ptr %7, align 4, !tbaa !9
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %45
  br label %133

50:                                               ; preds = %45
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52
  %54 = load i64, ptr %8, align 8, !tbaa !11
  %55 = call i32 @mbedtls_mpi_shift_r(ptr noundef %11, i64 noundef %54)
  store i32 %55, ptr %7, align 4, !tbaa !9
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %53
  br label %133

58:                                               ; preds = %53
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59
  %61 = getelementptr inbounds %struct.mbedtls_mpi, ptr %11, i32 0, i32 0
  store i32 1, ptr %61, align 8, !tbaa !13
  %62 = getelementptr inbounds %struct.mbedtls_mpi, ptr %10, i32 0, i32 0
  store i32 1, ptr %62, align 8, !tbaa !13
  br label %63

63:                                               ; preds = %115, %60
  %64 = call i32 @mbedtls_mpi_cmp_int(ptr noundef %10, i64 noundef 0)
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %116

66:                                               ; preds = %63
  br label %67

67:                                               ; preds = %66
  %68 = call i64 @mbedtls_mpi_lsb(ptr noundef %10)
  %69 = call i32 @mbedtls_mpi_shift_r(ptr noundef %10, i64 noundef %68)
  store i32 %69, ptr %7, align 4, !tbaa !9
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %67
  br label %133

72:                                               ; preds = %67
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73
  br label %75

75:                                               ; preds = %74
  %76 = call i64 @mbedtls_mpi_lsb(ptr noundef %11)
  %77 = call i32 @mbedtls_mpi_shift_r(ptr noundef %11, i64 noundef %76)
  store i32 %77, ptr %7, align 4, !tbaa !9
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %80

79:                                               ; preds = %75
  br label %133

80:                                               ; preds = %75
  br label %81

81:                                               ; preds = %80
  br label %82

82:                                               ; preds = %81
  %83 = call i32 @mbedtls_mpi_cmp_mpi(ptr noundef %10, ptr noundef %11)
  %84 = icmp sge i32 %83, 0
  br i1 %84, label %85, label %100

85:                                               ; preds = %82
  br label %86

86:                                               ; preds = %85
  %87 = call i32 @mbedtls_mpi_sub_abs(ptr noundef %10, ptr noundef %10, ptr noundef %11)
  store i32 %87, ptr %7, align 4, !tbaa !9
  %88 = icmp ne i32 %87, 0
  br i1 %88, label %89, label %90

89:                                               ; preds = %86
  br label %133

90:                                               ; preds = %86
  br label %91

91:                                               ; preds = %90
  br label %92

92:                                               ; preds = %91
  br label %93

93:                                               ; preds = %92
  %94 = call i32 @mbedtls_mpi_shift_r(ptr noundef %10, i64 noundef 1)
  store i32 %94, ptr %7, align 4, !tbaa !9
  %95 = icmp ne i32 %94, 0
  br i1 %95, label %96, label %97

96:                                               ; preds = %93
  br label %133

97:                                               ; preds = %93
  br label %98

98:                                               ; preds = %97
  br label %99

99:                                               ; preds = %98
  br label %115

100:                                              ; preds = %82
  br label %101

101:                                              ; preds = %100
  %102 = call i32 @mbedtls_mpi_sub_abs(ptr noundef %11, ptr noundef %11, ptr noundef %10)
  store i32 %102, ptr %7, align 4, !tbaa !9
  %103 = icmp ne i32 %102, 0
  br i1 %103, label %104, label %105

104:                                              ; preds = %101
  br label %133

105:                                              ; preds = %101
  br label %106

106:                                              ; preds = %105
  br label %107

107:                                              ; preds = %106
  br label %108

108:                                              ; preds = %107
  %109 = call i32 @mbedtls_mpi_shift_r(ptr noundef %11, i64 noundef 1)
  store i32 %109, ptr %7, align 4, !tbaa !9
  %110 = icmp ne i32 %109, 0
  br i1 %110, label %111, label %112

111:                                              ; preds = %108
  br label %133

112:                                              ; preds = %108
  br label %113

113:                                              ; preds = %112
  br label %114

114:                                              ; preds = %113
  br label %115

115:                                              ; preds = %114, %99
  br label %63, !llvm.loop !15

116:                                              ; preds = %63
  br label %117

117:                                              ; preds = %116
  %118 = load i64, ptr %8, align 8, !tbaa !11
  %119 = call i32 @mbedtls_mpi_shift_l(ptr noundef %11, i64 noundef %118)
  store i32 %119, ptr %7, align 4, !tbaa !9
  %120 = icmp ne i32 %119, 0
  br i1 %120, label %121, label %122

121:                                              ; preds = %117
  br label %133

122:                                              ; preds = %117
  br label %123

123:                                              ; preds = %122
  br label %124

124:                                              ; preds = %123
  br label %125

125:                                              ; preds = %124
  %126 = load ptr, ptr %4, align 8, !tbaa !5
  %127 = call i32 @mbedtls_mpi_copy(ptr noundef %126, ptr noundef %11)
  store i32 %127, ptr %7, align 4, !tbaa !9
  %128 = icmp ne i32 %127, 0
  br i1 %128, label %129, label %130

129:                                              ; preds = %125
  br label %133

130:                                              ; preds = %125
  br label %131

131:                                              ; preds = %130
  br label %132

132:                                              ; preds = %131
  br label %133

133:                                              ; preds = %132, %129, %121, %111, %104, %96, %89, %79, %71, %57, %49, %33, %25
  call void @mbedtls_mpi_free(ptr noundef %10)
  call void @mbedtls_mpi_free(ptr noundef %11)
  %134 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 24, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret i32 %134
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"mbedtls_mpi", !10, i64 0, !12, i64 8, !6, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

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

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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @mbedtls_mpi_lsb(ptr noundef) local_unnamed_addr #0

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_mpi_gcd(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.mbedtls_mpi, align 8
  %5 = alloca %struct.mbedtls_mpi, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #3
  call void @mbedtls_mpi_init(ptr noundef nonnull %4)
  call void @mbedtls_mpi_init(ptr noundef nonnull %5)
  %6 = call i32 @mbedtls_mpi_copy(ptr noundef nonnull %4, ptr noundef %1)
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %.loopexit

7:                                                ; preds = %3
  %8 = call i32 @mbedtls_mpi_copy(ptr noundef nonnull %5, ptr noundef %2)
  %.not23 = icmp eq i32 %8, 0
  br i1 %.not23, label %9, label %.loopexit

9:                                                ; preds = %7
  %10 = call i64 @mbedtls_mpi_lsb(ptr noundef nonnull %4)
  %11 = call i64 @mbedtls_mpi_lsb(ptr noundef nonnull %5)
  %spec.select = call i64 @llvm.umin.i64(i64 %11, i64 %10)
  %12 = call i32 @mbedtls_mpi_shift_r(ptr noundef nonnull %4, i64 noundef %spec.select)
  %.not24 = icmp eq i32 %12, 0
  br i1 %.not24, label %13, label %.loopexit

13:                                               ; preds = %9
  %14 = call i32 @mbedtls_mpi_shift_r(ptr noundef nonnull %5, i64 noundef %spec.select)
  %.not25 = icmp eq i32 %14, 0
  br i1 %.not25, label %15, label %.loopexit

15:                                               ; preds = %13
  store i32 1, ptr %5, align 8, !tbaa !5
  store i32 1, ptr %4, align 8, !tbaa !5
  %16 = call i32 @mbedtls_mpi_cmp_int(ptr noundef nonnull %4, i64 noundef 0)
  %.not2634 = icmp eq i32 %16, 0
  br i1 %.not2634, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %15, %33
  %17 = call i64 @mbedtls_mpi_lsb(ptr noundef nonnull %4)
  %18 = call i32 @mbedtls_mpi_shift_r(ptr noundef nonnull %4, i64 noundef %17)
  %.not28 = icmp eq i32 %18, 0
  br i1 %.not28, label %19, label %.loopexit

19:                                               ; preds = %.lr.ph
  %20 = call i64 @mbedtls_mpi_lsb(ptr noundef nonnull %5)
  %21 = call i32 @mbedtls_mpi_shift_r(ptr noundef nonnull %5, i64 noundef %20)
  %.not29 = icmp eq i32 %21, 0
  br i1 %.not29, label %22, label %.loopexit

22:                                               ; preds = %19
  %23 = call i32 @mbedtls_mpi_cmp_mpi(ptr noundef nonnull %4, ptr noundef nonnull %5)
  %24 = icmp sgt i32 %23, -1
  br i1 %24, label %25, label %29

25:                                               ; preds = %22
  %26 = call i32 @mbedtls_mpi_sub_abs(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %.not32 = icmp eq i32 %26, 0
  br i1 %.not32, label %27, label %.loopexit

27:                                               ; preds = %25
  %28 = call i32 @mbedtls_mpi_shift_r(ptr noundef nonnull %4, i64 noundef 1)
  %.not33 = icmp eq i32 %28, 0
  br i1 %.not33, label %33, label %.loopexit

29:                                               ; preds = %22
  %30 = call i32 @mbedtls_mpi_sub_abs(ptr noundef nonnull %5, ptr noundef nonnull %5, ptr noundef nonnull %4)
  %.not30 = icmp eq i32 %30, 0
  br i1 %.not30, label %31, label %.loopexit

31:                                               ; preds = %29
  %32 = call i32 @mbedtls_mpi_shift_r(ptr noundef nonnull %5, i64 noundef 1)
  %.not31 = icmp eq i32 %32, 0
  br i1 %.not31, label %33, label %.loopexit

33:                                               ; preds = %31, %27
  %34 = call i32 @mbedtls_mpi_cmp_int(ptr noundef nonnull %4, i64 noundef 0)
  %.not26 = icmp eq i32 %34, 0
  br i1 %.not26, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %33, %15
  %35 = call i32 @mbedtls_mpi_shift_l(ptr noundef nonnull %5, i64 noundef %spec.select)
  %.not27 = icmp eq i32 %35, 0
  br i1 %.not27, label %36, label %.loopexit

36:                                               ; preds = %._crit_edge
  %37 = call i32 @mbedtls_mpi_copy(ptr noundef %0, ptr noundef nonnull %5)
  br label %.loopexit

.loopexit:                                        ; preds = %31, %29, %27, %25, %19, %.lr.ph, %36, %._crit_edge, %13, %9, %7, %3
  %.0 = phi i32 [ %6, %3 ], [ %8, %7 ], [ %12, %9 ], [ %14, %13 ], [ %35, %._crit_edge ], [ %37, %36 ], [ %32, %31 ], [ %30, %29 ], [ %28, %27 ], [ %26, %25 ], [ %21, %19 ], [ %18, %.lr.ph ]
  call void @mbedtls_mpi_free(ptr noundef nonnull %4)
  call void @mbedtls_mpi_free(ptr noundef nonnull %5)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #3
  ret i32 %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #2

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"mbedtls_mpi", !7, i64 0, !10, i64 8, !11, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass