; 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: nounwind uwtable
declare dso_local i32 @mbedtls_mpi_grow(ptr noundef, i64 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_lset(ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_mpi_read_binary_le(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 -110, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %10 = load i64, ptr %6, align 8, !tbaa !9
  %11 = udiv i64 %10, 8
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = urem i64 %12, 8
  %14 = icmp ne i64 %13, 0
  %15 = zext i1 %14 to i32
  %16 = sext i32 %15 to i64
  %17 = add i64 %11, %16
  store i64 %17, ptr %9, align 8, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.mbedtls_mpi, ptr %18, i32 0, i32 1
  %20 = load i64, ptr %19, align 8, !tbaa !13
  %21 = load i64, ptr %9, align 8, !tbaa !9
  %22 = icmp ne i64 %20, %21
  br i1 %22, label %23, label %35

23:                                               ; preds = %3
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mbedtls_mpi_free(ptr noundef %24)
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mbedtls_mpi_init(ptr noundef %25)
  br label %26

26:                                               ; preds = %23
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = call i32 @mbedtls_mpi_grow(ptr noundef %27, i64 noundef %28)
  store i32 %29, ptr %7, align 4, !tbaa !11
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %26
  br label %70

32:                                               ; preds = %26
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34, %3
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = call i32 @mbedtls_mpi_lset(ptr noundef %37, i64 noundef 0)
  store i32 %38, ptr %7, align 4, !tbaa !11
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %36
  br label %70

41:                                               ; preds = %36
  br label %42

42:                                               ; preds = %41
  br label %43

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

44:                                               ; preds = %66, %43
  %45 = load i64, ptr %8, align 8, !tbaa !9
  %46 = load i64, ptr %6, align 8, !tbaa !9
  %47 = icmp ult i64 %45, %46
  br i1 %47, label %48, label %69

48:                                               ; preds = %44
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i64, ptr %8, align 8, !tbaa !9
  %51 = getelementptr inbounds i8, ptr %49, i64 %50
  %52 = load i8, ptr %51, align 1, !tbaa !15
  %53 = zext i8 %52 to i64
  %54 = load i64, ptr %8, align 8, !tbaa !9
  %55 = urem i64 %54, 8
  %56 = shl i64 %55, 3
  %57 = shl i64 %53, %56
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.mbedtls_mpi, ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %59, align 8, !tbaa !16
  %61 = load i64, ptr %8, align 8, !tbaa !9
  %62 = udiv i64 %61, 8
  %63 = getelementptr inbounds i64, ptr %60, i64 %62
  %64 = load i64, ptr %63, align 8, !tbaa !9
  %65 = or i64 %64, %57
  store i64 %65, ptr %63, align 8, !tbaa !9
  br label %66

66:                                               ; preds = %48
  %67 = load i64, ptr %8, align 8, !tbaa !9
  %68 = add i64 %67, 1
  store i64 %68, ptr %8, align 8, !tbaa !9
  br label %44, !llvm.loop !17

69:                                               ; preds = %44
  br label %70

70:                                               ; preds = %69, %40, %31
  %71 = load i32, ptr %7, align 4, !tbaa !11
  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 %71
}

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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"mbedtls_mpi", !12, i64 0, !10, i64 8, !6, i64 16}
!15 = !{!7, !7, i64 0}
!16 = !{!14, !6, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"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: 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: nounwind uwtable
declare dso_local i32 @mbedtls_mpi_grow(ptr noundef, i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_mpi_read_binary_le(ptr noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = lshr i64 %2, 3
  %5 = and i64 %2, 7
  %6 = icmp ne i64 %5, 0
  %7 = zext i1 %6 to i64
  %8 = add nuw nsw i64 %4, %7
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %.not = icmp eq i64 %10, %8
  br i1 %.not, label %13, label %11

11:                                               ; preds = %3
  tail call void @mbedtls_mpi_free(ptr noundef nonnull %0)
  tail call void @mbedtls_mpi_init(ptr noundef nonnull %0)
  %12 = tail call i32 @mbedtls_mpi_grow(ptr noundef nonnull %0, i64 noundef %8)
  %.not21 = icmp eq i32 %12, 0
  br i1 %.not21, label %13, label %.loopexit

13:                                               ; preds = %3, %11
  %14 = tail call i32 @mbedtls_mpi_lset(ptr noundef nonnull %0, i64 noundef 0)
  %.not22 = icmp eq i32 %14, 0
  br i1 %.not22, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %13
  %.not24 = icmp eq i64 %2, 0
  br i1 %.not24, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %xtraiter = and i64 %2, 1
  %17 = icmp eq i64 %2, 1
  br i1 %17, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %2, -2
  br label %18

18:                                               ; preds = %18, %.lr.ph.new
  %.01723 = phi i64 [ 0, %.lr.ph.new ], [ %40, %18 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %18 ]
  %19 = getelementptr inbounds i8, ptr %1, i64 %.01723
  %20 = load i8, ptr %19, align 1, !tbaa !13
  %21 = zext i8 %20 to i64
  %22 = shl i64 %.01723, 3
  %23 = and i64 %22, 48
  %24 = shl nuw nsw i64 %21, %23
  %25 = lshr i64 %.01723, 3
  %26 = getelementptr inbounds i64, ptr %16, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !14
  %28 = or i64 %27, %24
  store i64 %28, ptr %26, align 8, !tbaa !14
  %29 = or disjoint i64 %.01723, 1
  %30 = getelementptr inbounds i8, ptr %1, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !13
  %32 = zext i8 %31 to i64
  %33 = shl i64 %29, 3
  %34 = and i64 %33, 56
  %35 = shl nuw i64 %32, %34
  %36 = lshr i64 %.01723, 3
  %37 = getelementptr inbounds i64, ptr %16, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !14
  %39 = or i64 %38, %35
  store i64 %39, ptr %37, align 8, !tbaa !14
  %40 = add nuw i64 %.01723, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %18, !llvm.loop !15

.loopexit.loopexit.unr-lcssa:                     ; preds = %18, %.lr.ph
  %.01723.unr = phi i64 [ 0, %.lr.ph ], [ %40, %18 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.loopexit.loopexit.epilog-lcssa

.loopexit.loopexit.epilog-lcssa:                  ; preds = %.loopexit.loopexit.unr-lcssa
  %41 = getelementptr inbounds i8, ptr %1, i64 %.01723.unr
  %42 = load i8, ptr %41, align 1, !tbaa !13
  %43 = zext i8 %42 to i64
  %44 = shl i64 %.01723.unr, 3
  %45 = and i64 %44, 56
  %46 = shl nuw i64 %43, %45
  %47 = lshr i64 %.01723.unr, 3
  %48 = getelementptr inbounds i64, ptr %16, i64 %47
  %49 = load i64, ptr %48, align 8, !tbaa !14
  %50 = or i64 %49, %46
  store i64 %50, ptr %48, align 8, !tbaa !14
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.epilog-lcssa, %.loopexit.loopexit.unr-lcssa, %.preheader, %13, %11
  %.0 = phi i32 [ %12, %11 ], [ %14, %13 ], [ 0, %.preheader ], [ 0, %.loopexit.loopexit.unr-lcssa ], [ 0, %.loopexit.loopexit.epilog-lcssa ]
  ret i32 %.0
}

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

!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, !10, i64 8}
!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 = !{!6, !11, i64 16}
!13 = !{!8, !8, i64 0}
!14 = !{!10, !10, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass