; LLVM IR from machinefi/psa-crypto-esp32 :: psa_layer (psa_crypto_porting)

; 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: nounwind uwtable
define dso_local i32 @iotex_int_to_string(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca [32 x i8], align 16
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %7) #3
  call void @llvm.memset.p0.i64(ptr align 16 %7, i8 0, i64 32, i1 false)
  br label %8

8:                                                ; preds = %12, %2
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = udiv i32 %9, 10
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %24

12:                                               ; preds = %8
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = urem i32 %13, 10
  %15 = add i32 %14, 48
  %16 = trunc i32 %15 to i8
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 %18
  store i8 %16, ptr %19, align 1, !tbaa !11
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = udiv i32 %20, 10
  store i32 %21, ptr %3, align 4, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %5, align 4, !tbaa !5
  br label %8, !llvm.loop !12

24:                                               ; preds = %8
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = add i32 %25, 48
  %27 = trunc i32 %26 to i8
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 %29
  store i8 %27, ptr %30, align 1, !tbaa !11
  %31 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %31, ptr %6, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %46, %24
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = icmp sge i32 %33, 0
  br i1 %34, label %35, label %49

35:                                               ; preds = %32
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %40 = load ptr, ptr %4, align 8, !tbaa !9
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = sub nsw i32 %41, %42
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i8, ptr %40, i64 %44
  store i8 %39, ptr %45, align 1, !tbaa !11
  br label %46

46:                                               ; preds = %35
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = add nsw i32 %47, -1
  store i32 %48, ptr %6, align 4, !tbaa !5
  br label %32, !llvm.loop !14

49:                                               ; preds = %32
  %50 = load ptr, ptr %4, align 8, !tbaa !9
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i8, ptr %50, i64 %53
  store i8 48, ptr %54, align 1, !tbaa !11
  %55 = load i32, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %55
}

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

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

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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(argmem: write) uwtable
define dso_local i32 @iotex_int_to_string(i32 noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %3, i8 0, i64 32, i1 false)
  %.not19 = icmp ult i32 %0, 10
  br i1 %.not19, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %2
  %4 = trunc nuw i32 %0 to i8
  %5 = or disjoint i8 %4, 48
  store i8 %5, ptr %3, align 16, !tbaa !5
  br label %iter.check

.lr.ph:                                           ; preds = %2, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %2 ]
  %.01720 = phi i32 [ %6, %.lr.ph ], [ %0, %2 ]
  %6 = udiv i32 %.01720, 10
  %7 = urem i32 %.01720, 10
  %8 = trunc nuw nsw i32 %7 to i8
  %9 = or disjoint i8 %8, 48
  %10 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 %indvars.iv
  store i8 %9, ptr %10, align 1, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.not = icmp ult i32 %.01720, 100
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph
  %11 = trunc nuw i64 %indvars.iv.next to i32
  %12 = trunc nuw i32 %6 to i8
  %13 = or disjoint i8 %12, 48
  %14 = and i64 %indvars.iv.next, 4294967295
  %15 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 %14
  store i8 %13, ptr %15, align 1, !tbaa !5
  %16 = icmp sgt i32 %11, -1
  br i1 %16, label %iter.check, label %._crit_edge26

iter.check:                                       ; preds = %._crit_edge.thread, %._crit_edge
  %17 = phi i64 [ 0, %._crit_edge.thread ], [ %14, %._crit_edge ]
  %.016.lcssa35 = phi i32 [ 0, %._crit_edge.thread ], [ %11, %._crit_edge ]
  %18 = zext nneg i32 %.016.lcssa35 to i64
  %19 = add nuw nsw i64 %18, 1
  %min.iters.check = icmp ult i32 %.016.lcssa35, 7
  br i1 %min.iters.check, label %.lr.ph25.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %iter.check
  %min.iters.check37 = icmp ult i32 %.016.lcssa35, 31
  br i1 %min.iters.check37, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %19, 4294967264
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = sub i64 %18, %index
  %20 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 %offset.idx
  %21 = getelementptr inbounds i8, ptr %20, i64 -15
  %22 = getelementptr inbounds i8, ptr %20, i64 -31
  %wide.load = load <16 x i8>, ptr %21, align 1, !tbaa !5
  %reverse = shufflevector <16 x i8> %wide.load, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
  %wide.load38 = load <16 x i8>, ptr %22, align 1, !tbaa !5
  %reverse39 = shufflevector <16 x i8> %wide.load38, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
  %23 = getelementptr inbounds i8, ptr %1, i64 %index
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  store <16 x i8> %reverse, ptr %23, align 1, !tbaa !5
  store <16 x i8> %reverse39, ptr %24, align 1, !tbaa !5
  %index.next = add nuw i64 %index, 32
  %25 = icmp eq i64 %index.next, %n.vec
  br i1 %25, label %middle.block, label %vector.body, !llvm.loop !10

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %19, %n.vec
  br i1 %cmp.n, label %._crit_edge26, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %ind.end42 = sub nsw i64 %18, %n.vec
  %n.vec.remaining = and i64 %19, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %.lr.ph25.preheader, label %vec.epilog.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec41 = and i64 %19, 4294967288
  %ind.end = sub nsw i64 %18, %n.vec41
  %invariant.gep = getelementptr i8, ptr %3, i64 -7
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index43 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next47, %vec.epilog.vector.body ]
  %offset.idx44 = sub i64 %18, %index43
  %gep = getelementptr [32 x i8], ptr %invariant.gep, i64 0, i64 %offset.idx44
  %wide.load45 = load <8 x i8>, ptr %gep, align 1, !tbaa !5
  %reverse46 = shufflevector <8 x i8> %wide.load45, <8 x i8> poison, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
  %26 = getelementptr inbounds i8, ptr %1, i64 %index43
  store <8 x i8> %reverse46, ptr %26, align 1, !tbaa !5
  %index.next47 = add nuw i64 %index43, 8
  %27 = icmp eq i64 %index.next47, %n.vec41
  br i1 %27, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !13

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n48 = icmp eq i64 %19, %n.vec41
  br i1 %cmp.n48, label %._crit_edge26, label %.lr.ph25.preheader

.lr.ph25.preheader:                               ; preds = %vec.epilog.middle.block, %iter.check, %vec.epilog.iter.check
  %indvars.iv29.ph = phi i64 [ %18, %iter.check ], [ %ind.end42, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  br label %.lr.ph25

.lr.ph25:                                         ; preds = %.lr.ph25.preheader, %.lr.ph25
  %indvars.iv29 = phi i64 [ %indvars.iv.next30, %.lr.ph25 ], [ %indvars.iv29.ph, %.lr.ph25.preheader ]
  %28 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 %indvars.iv29
  %29 = load i8, ptr %28, align 1, !tbaa !5
  %30 = sub nuw nsw i64 %18, %indvars.iv29
  %31 = getelementptr inbounds i8, ptr %1, i64 %30
  store i8 %29, ptr %31, align 1, !tbaa !5
  %indvars.iv.next30 = add nsw i64 %indvars.iv29, -1
  %.not36 = icmp eq i64 %indvars.iv29, 0
  br i1 %.not36, label %._crit_edge26, label %.lr.ph25, !llvm.loop !14

._crit_edge26:                                    ; preds = %.lr.ph25, %middle.block, %vec.epilog.middle.block, %._crit_edge
  %32 = phi i64 [ %14, %._crit_edge ], [ %17, %vec.epilog.middle.block ], [ %17, %middle.block ], [ %17, %.lr.ph25 ]
  %.016.lcssa34 = phi i32 [ %11, %._crit_edge ], [ %.016.lcssa35, %vec.epilog.middle.block ], [ %.016.lcssa35, %middle.block ], [ %.016.lcssa35, %.lr.ph25 ]
  %33 = getelementptr inbounds i8, ptr %1, i64 %32
  %34 = getelementptr inbounds i8, ptr %33, i64 1
  store i8 48, ptr %34, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #3
  ret i32 %.016.lcssa34
}

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

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

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: write) 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9, !11, !12}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !9, !11, !12}
!14 = distinct !{!14, !9, !12, !11}


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