; 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: 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
define dso_local i64 @mbedtls_mpi_lsb(ptr noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %1
  br label %9

9:                                                ; preds = %8
  br label %10

10:                                               ; preds = %9
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %41, %10
  %12 = load i64, ptr %4, align 8, !tbaa !9
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.mbedtls_mpi, ptr %13, i32 0, i32 1
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = icmp ult i64 %12, %15
  br i1 %16, label %17, label %44

17:                                               ; preds = %11
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %35, %17
  %19 = load i64, ptr %5, align 8, !tbaa !9
  %20 = icmp ult i64 %19, 64
  br i1 %20, label %21, label %40

21:                                               ; preds = %18
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.mbedtls_mpi, ptr %22, i32 0, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = load i64, ptr %4, align 8, !tbaa !9
  %26 = getelementptr inbounds i64, ptr %24, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = load i64, ptr %5, align 8, !tbaa !9
  %29 = lshr i64 %27, %28
  %30 = and i64 %29, 1
  %31 = icmp ne i64 %30, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %21
  %33 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %33, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %45

34:                                               ; preds = %21
  br label %35

35:                                               ; preds = %34
  %36 = load i64, ptr %5, align 8, !tbaa !9
  %37 = add i64 %36, 1
  store i64 %37, ptr %5, align 8, !tbaa !9
  %38 = load i64, ptr %6, align 8, !tbaa !9
  %39 = add i64 %38, 1
  store i64 %39, ptr %6, align 8, !tbaa !9
  br label %18, !llvm.loop !15

40:                                               ; preds = %18
  br label %41

41:                                               ; preds = %40
  %42 = load i64, ptr %4, align 8, !tbaa !9
  %43 = add i64 %42, 1
  store i64 %43, ptr %4, align 8, !tbaa !9
  br label %11, !llvm.loop !17

44:                                               ; preds = %11
  store i64 0, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %45

45:                                               ; preds = %44, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %46 = load i64, ptr %2, align 8
  ret i64 %46
}

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


; 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: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local i64 @mbedtls_mpi_lsb(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %.not19 = icmp eq i64 %3, 0
  br i1 %.not19, label %.loopexit, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !12
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %24
  %.018 = phi i64 [ 0, %.preheader.lr.ph ], [ %8, %24 ]
  %.01117 = phi i64 [ 0, %.preheader.lr.ph ], [ %25, %24 ]
  %6 = getelementptr inbounds i64, ptr %5, i64 %.01117
  %7 = load i64, ptr %6, align 8, !tbaa !13
  %8 = add i64 %.018, 64
  br label %9

9:                                                ; preds = %21, %.preheader
  %.116 = phi i64 [ %.018, %.preheader ], [ %23, %21 ]
  %.01015 = phi i64 [ 0, %.preheader ], [ %22, %21 ]
  %10 = shl nuw i64 1, %.01015
  %11 = and i64 %7, %10
  %.not = icmp eq i64 %11, 0
  br i1 %.not, label %12, label %.loopexit

12:                                               ; preds = %9
  %13 = shl nuw i64 2, %.01015
  %14 = and i64 %7, %13
  %.not.1 = icmp eq i64 %14, 0
  br i1 %.not.1, label %15, label %.loopexit.loopexit.split.loop.exit31

15:                                               ; preds = %12
  %16 = shl nuw i64 4, %.01015
  %17 = and i64 %7, %16
  %.not.2 = icmp eq i64 %17, 0
  br i1 %.not.2, label %18, label %.loopexit.loopexit.split.loop.exit29

18:                                               ; preds = %15
  %19 = shl nuw i64 8, %.01015
  %20 = and i64 %7, %19
  %.not.3 = icmp eq i64 %20, 0
  br i1 %.not.3, label %21, label %.loopexit.loopexit.split.loop.exit

21:                                               ; preds = %18
  %22 = add nuw nsw i64 %.01015, 4
  %23 = add i64 %.116, 4
  %exitcond.not.3 = icmp eq i64 %22, 64
  br i1 %exitcond.not.3, label %24, label %9, !llvm.loop !14

24:                                               ; preds = %21
  %25 = add nuw i64 %.01117, 1
  %exitcond22.not = icmp eq i64 %25, %3
  br i1 %exitcond22.not, label %.loopexit, label %.preheader, !llvm.loop !16

.loopexit.loopexit.split.loop.exit:               ; preds = %18
  %26 = or disjoint i64 %.116, 3
  br label %.loopexit

.loopexit.loopexit.split.loop.exit29:             ; preds = %15
  %27 = or disjoint i64 %.116, 2
  br label %.loopexit

.loopexit.loopexit.split.loop.exit31:             ; preds = %12
  %28 = or disjoint i64 %.116, 1
  br label %.loopexit

.loopexit:                                        ; preds = %24, %.loopexit.loopexit.split.loop.exit, %.loopexit.loopexit.split.loop.exit29, %.loopexit.loopexit.split.loop.exit31, %9, %1
  %.012 = phi i64 [ 0, %1 ], [ %26, %.loopexit.loopexit.split.loop.exit ], [ %27, %.loopexit.loopexit.split.loop.exit29 ], [ %28, %.loopexit.loopexit.split.loop.exit31 ], [ %.116, %9 ], [ 0, %24 ]
  ret i64 %.012
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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