; LLVM IR from alekras/ao.rtos.cpp :: Tools/ARM-Raspberry_Pi/Initial_Interactive_Loader (InitialInteractiveLoaderSM)

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

@_ZZ13int2hexStringjPciE6digits = external hidden global [16 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_Z13int2hexStringjPci(i32 noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %8 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %8, ptr %7, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %12, %3
  %10 = load i32, ptr %7, align 4, !tbaa !5
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %12, label %25

12:                                               ; preds = %9
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = and i32 %13, 15
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds [16 x i8], ptr @_ZZ13int2hexStringjPciE6digits, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = add nsw i32 %19, -1
  store i32 %20, ptr %7, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %18, i64 %21
  store i8 %17, ptr %22, align 1, !tbaa !11
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = lshr i32 %23, 4
  store i32 %24, ptr %4, align 4, !tbaa !5
  br label %9, !llvm.loop !12

25:                                               ; preds = %9
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i8, ptr %26, i64 %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret ptr %29
}

; 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

attributes #0 = { mustprogress 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple 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"}


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

@_ZZ13int2hexStringjPciE6digits = external hidden local_unnamed_addr global [16 x i8], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(read, argmem: write, inaccessiblemem: none) uwtable
define dso_local noundef ptr @_Z13int2hexStringjPci(i32 noundef %0, ptr noundef writeonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %2, 0
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %5 = zext nneg i32 %2 to i64
  %xtraiter = and i64 %5, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.lr.ph.prol ], [ %5, %.lr.ph.preheader ]
  %.078.prol = phi i32 [ %11, %.lr.ph.prol ], [ %0, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %6 = and i32 %.078.prol, 15
  %7 = zext nneg i32 %6 to i64
  %8 = getelementptr inbounds [16 x i8], ptr @_ZZ13int2hexStringjPciE6digits, i64 0, i64 %7
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %indvars.iv.next.prol = add nsw i64 %indvars.iv.prol, -1
  %10 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next.prol
  store i8 %9, ptr %10, align 1, !tbaa !5
  %11 = lshr i32 %.078.prol, 4
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !8

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ %5, %.lr.ph.preheader ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %.078.unr = phi i32 [ %0, %.lr.ph.preheader ], [ %11, %.lr.ph.prol ]
  %12 = icmp ult i32 %2, 4
  br i1 %12, label %._crit_edge, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.prol.loopexit
  %invariant.gep = getelementptr i8, ptr %1, i64 -1
  %invariant.gep11 = getelementptr i8, ptr %1, i64 -2
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ %indvars.iv.unr, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %.078 = phi i32 [ %.078.unr, %.lr.ph.preheader.new ], [ %34, %.lr.ph ]
  %13 = and i32 %.078, 15
  %14 = zext nneg i32 %13 to i64
  %15 = getelementptr inbounds [16 x i8], ptr @_ZZ13int2hexStringjPciE6digits, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %gep = getelementptr i8, ptr %invariant.gep, i64 %indvars.iv
  store i8 %16, ptr %gep, align 1, !tbaa !5
  %17 = lshr i32 %.078, 4
  %18 = and i32 %17, 15
  %19 = zext nneg i32 %18 to i64
  %20 = getelementptr inbounds [16 x i8], ptr @_ZZ13int2hexStringjPciE6digits, i64 0, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %gep12 = getelementptr i8, ptr %invariant.gep11, i64 %indvars.iv
  store i8 %21, ptr %gep12, align 1, !tbaa !5
  %22 = lshr i32 %.078, 8
  %23 = and i32 %22, 15
  %24 = zext nneg i32 %23 to i64
  %25 = getelementptr inbounds [16 x i8], ptr @_ZZ13int2hexStringjPciE6digits, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %indvars.iv.next.2 = add nsw i64 %indvars.iv, -3
  %27 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next.2
  store i8 %26, ptr %27, align 1, !tbaa !5
  %28 = lshr i32 %.078, 12
  %29 = and i32 %28, 15
  %30 = zext nneg i32 %29 to i64
  %31 = getelementptr inbounds [16 x i8], ptr @_ZZ13int2hexStringjPciE6digits, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, -4
  %33 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next.3
  store i8 %32, ptr %33, align 1, !tbaa !5
  %34 = lshr i32 %.078, 16
  %35 = icmp ugt i64 %indvars.iv.next.2, 1
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %3
  %36 = sext i32 %2 to i64
  %37 = getelementptr inbounds i8, ptr %1, i64 %36
  ret ptr %37
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(read, argmem: write, 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.unroll.disable"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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