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

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @mpi_get_digit(ptr noundef, i32 noundef, i8 noundef signext) #2

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

13:                                               ; preds = %3
  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
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = icmp slt i32 %19, 2
  br i1 %20, label %24, label %21

21:                                               ; preds = %18
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = icmp sgt i32 %22, 16
  br i1 %23, label %24, label %25

24:                                               ; preds = %21, %18
  store i32 -4, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %91

25:                                               ; preds = %21
  %26 = getelementptr inbounds [2484 x i8], ptr %11, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %26, i8 0, i64 2484, i1 false)
  %27 = getelementptr inbounds [2484 x i8], ptr %11, i64 0, i64 0
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = call ptr @fgets(ptr noundef %27, i32 noundef 2483, ptr noundef %28)
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %25
  store i32 -2, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %91

32:                                               ; preds = %25
  %33 = getelementptr inbounds [2484 x i8], ptr %11, i64 0, i64 0
  %34 = call i64 @strlen(ptr noundef %33) #6
  store i64 %34, ptr %9, align 8, !tbaa !11
  %35 = load i64, ptr %9, align 8, !tbaa !11
  %36 = icmp eq i64 %35, 2482
  br i1 %36, label %37, label %38

37:                                               ; preds = %32
  store i32 -8, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %91

38:                                               ; preds = %32
  %39 = load i64, ptr %9, align 8, !tbaa !11
  %40 = icmp ugt i64 %39, 0
  br i1 %40, label %41, label %53

41:                                               ; preds = %38
  %42 = load i64, ptr %9, align 8, !tbaa !11
  %43 = sub i64 %42, 1
  %44 = getelementptr inbounds [2484 x i8], ptr %11, i64 0, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !13
  %46 = sext i8 %45 to i32
  %47 = icmp eq i32 %46, 10
  br i1 %47, label %48, label %53

48:                                               ; preds = %41
  %49 = load i64, ptr %9, align 8, !tbaa !11
  %50 = add i64 %49, -1
  store i64 %50, ptr %9, align 8, !tbaa !11
  %51 = load i64, ptr %9, align 8, !tbaa !11
  %52 = getelementptr inbounds [2484 x i8], ptr %11, i64 0, i64 %51
  store i8 0, ptr %52, align 1, !tbaa !13
  br label %53

53:                                               ; preds = %48, %41, %38
  %54 = load i64, ptr %9, align 8, !tbaa !11
  %55 = icmp ugt i64 %54, 0
  br i1 %55, label %56, label %68

56:                                               ; preds = %53
  %57 = load i64, ptr %9, align 8, !tbaa !11
  %58 = sub i64 %57, 1
  %59 = getelementptr inbounds [2484 x i8], ptr %11, i64 0, i64 %58
  %60 = load i8, ptr %59, align 1, !tbaa !13
  %61 = sext i8 %60 to i32
  %62 = icmp eq i32 %61, 13
  br i1 %62, label %63, label %68

63:                                               ; preds = %56
  %64 = load i64, ptr %9, align 8, !tbaa !11
  %65 = add i64 %64, -1
  store i64 %65, ptr %9, align 8, !tbaa !11
  %66 = load i64, ptr %9, align 8, !tbaa !11
  %67 = getelementptr inbounds [2484 x i8], ptr %11, i64 0, i64 %66
  store i8 0, ptr %67, align 1, !tbaa !13
  br label %68

68:                                               ; preds = %63, %56, %53
  %69 = getelementptr inbounds [2484 x i8], ptr %11, i64 0, i64 0
  %70 = load i64, ptr %9, align 8, !tbaa !11
  %71 = getelementptr inbounds i8, ptr %69, i64 %70
  store ptr %71, ptr %10, align 8, !tbaa !5
  br label %72

72:                                               ; preds = %84, %68
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %73, i32 -1
  store ptr %74, ptr %10, align 8, !tbaa !5
  %75 = getelementptr inbounds [2484 x i8], ptr %11, i64 0, i64 0
  %76 = icmp ugt ptr %73, %75
  br i1 %76, label %77, label %85

77:                                               ; preds = %72
  %78 = load i32, ptr %6, align 4, !tbaa !9
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = load i8, ptr %79, align 1, !tbaa !13
  %81 = call i32 @mpi_get_digit(ptr noundef %8, i32 noundef %78, i8 noundef signext %80)
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %84

83:                                               ; preds = %77
  br label %85

84:                                               ; preds = %77
  br label %72, !llvm.loop !14

85:                                               ; preds = %83, %72
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = load i32, ptr %6, align 4, !tbaa !9
  %88 = load ptr, ptr %10, align 8, !tbaa !5
  %89 = getelementptr inbounds i8, ptr %88, i64 1
  %90 = call i32 @mbedtls_mpi_read_string(ptr noundef %86, i32 noundef %87, ptr noundef %89)
  store i32 %90, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %91

91:                                               ; preds = %85, %37, %31, %24
  call void @llvm.lifetime.end.p0(i64 2484, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %92 = load i32, ptr %4, align 4
  ret i32 %92
}

declare ptr @fgets(ptr noundef, i32 noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { nounwind willreturn memory(read) "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 #4 = { "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

; 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i32 @mpi_get_digit(ptr noundef, i32 noundef, i8 noundef signext) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_mpi_read_file(ptr noundef %0, i32 noundef %1, ptr nocapture noundef %2) local_unnamed_addr #2 {
  %4 = alloca i64, align 8
  %5 = alloca [2484 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 2484, ptr nonnull %5) #5
  %6 = add i32 %1, -17
  %or.cond = icmp ult i32 %6, -15
  br i1 %or.cond, label %31, label %7

7:                                                ; preds = %3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2484) %5, i8 0, i64 2484, i1 false)
  %8 = call ptr @fgets(ptr noundef nonnull %5, i32 noundef 2483, ptr noundef %2)
  %9 = icmp eq ptr %8, null
  br i1 %9, label %31, label %10

10:                                               ; preds = %7
  %11 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %5) #6
  switch i64 %11, label %12 [
    i64 2482, label %31
    i64 0, label %.thread
  ]

12:                                               ; preds = %10
  %13 = add i64 %11, -1
  %14 = getelementptr inbounds [2484 x i8], ptr %5, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = icmp eq i8 %15, 10
  br i1 %16, label %17, label %.thread28

17:                                               ; preds = %12
  store i8 0, ptr %14, align 1, !tbaa !5
  %.not24 = icmp eq i64 %13, 0
  br i1 %.not24, label %.thread, label %..thread28_crit_edge

..thread28_crit_edge:                             ; preds = %17
  %.pre = add i64 %11, -2
  %.phi.trans.insert = getelementptr inbounds [2484 x i8], ptr %5, i64 0, i64 %.pre
  %.pre32 = load i8, ptr %.phi.trans.insert, align 1, !tbaa !5
  br label %.thread28

.thread28:                                        ; preds = %..thread28_crit_edge, %12
  %18 = phi i8 [ %.pre32, %..thread28_crit_edge ], [ %15, %12 ]
  %.pre-phi = phi i64 [ %.pre, %..thread28_crit_edge ], [ %13, %12 ]
  %.02031 = phi i64 [ %13, %..thread28_crit_edge ], [ %11, %12 ]
  %19 = icmp eq i8 %18, 13
  br i1 %19, label %20, label %.thread

20:                                               ; preds = %.thread28
  %21 = getelementptr inbounds [2484 x i8], ptr %5, i64 0, i64 %.pre-phi
  store i8 0, ptr %21, align 1, !tbaa !5
  br label %.thread

.thread:                                          ; preds = %10, %20, %.thread28, %17
  %.1 = phi i64 [ %.pre-phi, %20 ], [ %.02031, %.thread28 ], [ 0, %17 ], [ %11, %10 ]
  %22 = getelementptr inbounds i8, ptr %5, i64 %.1
  br label %23

23:                                               ; preds = %25, %.thread
  %.0 = phi ptr [ %22, %.thread ], [ %26, %25 ]
  %24 = icmp ugt ptr %.0, %5
  br i1 %24, label %25, label %29

25:                                               ; preds = %23
  %26 = getelementptr inbounds i8, ptr %.0, i64 -1
  %27 = load i8, ptr %26, align 1, !tbaa !5
  %28 = call i32 @mpi_get_digit(ptr noundef nonnull %4, i32 noundef %1, i8 noundef signext %27)
  %.not25 = icmp eq i32 %28, 0
  br i1 %.not25, label %23, label %29, !llvm.loop !8

29:                                               ; preds = %25, %23
  %30 = call i32 @mbedtls_mpi_read_string(ptr noundef %0, i32 noundef %1, ptr noundef nonnull %.0)
  br label %31

31:                                               ; preds = %10, %7, %3, %29
  %.021 = phi i32 [ %30, %29 ], [ -4, %3 ], [ -2, %7 ], [ -8, %10 ]
  call void @llvm.lifetime.end.p0(i64 2484, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  ret i32 %.021
}

; Function Attrs: nofree nounwind
declare noundef ptr @fgets(ptr noundef, i32 noundef, ptr nocapture noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 #4 = { nofree nounwind "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass