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

%class.InitialInteractiveLoaderSM = type <{ %class.Efsm, i32, i32, i32, i32, i32, i32, i32, [4 x i8], ptr, i32, i32, i32, [4 x i8] }>
%class.Efsm = type { { i64, i64 } }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z13int2hexStringjPci(i32 noundef, ptr noundef, i32 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

declare void @sendString(ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN26InitialInteractiveLoaderSM10runCommandEii(ptr noundef nonnull align 8 dereferenceable(68) %0, i32 noundef %1, i32 noundef %2) #3 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca [80 x i8], align 16
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %13 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 80, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = inttoptr i64 %15 to ptr
  store ptr %16, ptr %9, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %72, %3
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %20, label %82

20:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = getelementptr inbounds [80 x i8], ptr %7, i64 0, i64 0
  %23 = call noundef ptr @_Z13int2hexStringjPci(i32 noundef %21, ptr noundef %22, i32 noundef 8)
  store ptr %23, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i32 1
  store ptr %25, ptr %8, align 8, !tbaa !5
  store i8 62, ptr %24, align 1, !tbaa !11
  br label %26

26:                                               ; preds = %71, %20
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = icmp slt i32 %27, 16
  br i1 %28, label %29, label %32

29:                                               ; preds = %26
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = icmp sgt i32 %30, 0
  br label %32

32:                                               ; preds = %29, %26
  %33 = phi i1 [ false, %26 ], [ %31, %29 ]
  br i1 %33, label %34, label %72

34:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = getelementptr inbounds i32, ptr %35, i32 1
  store ptr %36, ptr %9, align 8, !tbaa !5
  %37 = load volatile i32, ptr %35, align 4, !tbaa !9
  store i32 %37, ptr %12, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %70, %34
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = icmp sgt i32 %39, 0
  br i1 %40, label %41, label %71

41:                                               ; preds = %38
  %42 = getelementptr inbounds %class.InitialInteractiveLoaderSM, ptr %13, i32 0, i32 5
  %43 = load i32, ptr %42, align 8, !tbaa !12
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = sub nsw i32 %44, %43
  store i32 %45, ptr %11, align 4, !tbaa !9
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i32 1
  store ptr %47, ptr %8, align 8, !tbaa !5
  store i8 32, ptr %46, align 1, !tbaa !11
  %48 = load i32, ptr %12, align 4, !tbaa !9
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %class.InitialInteractiveLoaderSM, ptr %13, i32 0, i32 5
  %51 = load i32, ptr %50, align 8, !tbaa !12
  %52 = mul nsw i32 2, %51
  %53 = call noundef ptr @_Z13int2hexStringjPci(i32 noundef %48, ptr noundef %49, i32 noundef %52)
  store ptr %53, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds %class.InitialInteractiveLoaderSM, ptr %13, i32 0, i32 5
  %55 = load i32, ptr %54, align 8, !tbaa !12
  %56 = mul nsw i32 8, %55
  %57 = load i32, ptr %12, align 4, !tbaa !9
  %58 = lshr i32 %57, %56
  store i32 %58, ptr %12, align 4, !tbaa !9
  %59 = getelementptr inbounds %class.InitialInteractiveLoaderSM, ptr %13, i32 0, i32 5
  %60 = load i32, ptr %59, align 8, !tbaa !12
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = sub nsw i32 %61, %60
  store i32 %62, ptr %6, align 4, !tbaa !9
  %63 = getelementptr inbounds %class.InitialInteractiveLoaderSM, ptr %13, i32 0, i32 5
  %64 = load i32, ptr %63, align 8, !tbaa !12
  %65 = load i32, ptr %10, align 4, !tbaa !9
  %66 = add nsw i32 %65, %64
  store i32 %66, ptr %10, align 4, !tbaa !9
  %67 = load i32, ptr %6, align 4, !tbaa !9
  %68 = icmp sle i32 %67, 0
  br i1 %68, label %69, label %70

69:                                               ; preds = %41
  br label %71

70:                                               ; preds = %41
  br label %38, !llvm.loop !15

71:                                               ; preds = %69, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %26, !llvm.loop !17

72:                                               ; preds = %32
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %73, i32 1
  store ptr %74, ptr %8, align 8, !tbaa !5
  store i8 13, ptr %73, align 1, !tbaa !11
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = getelementptr inbounds i8, ptr %75, i32 1
  store ptr %76, ptr %8, align 8, !tbaa !5
  store i8 10, ptr %75, align 1, !tbaa !11
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = getelementptr inbounds i8, ptr %77, i32 1
  store ptr %78, ptr %8, align 8, !tbaa !5
  store i8 0, ptr %77, align 1, !tbaa !11
  %79 = load i32, ptr %5, align 4, !tbaa !9
  %80 = add nsw i32 %79, 16
  store i32 %80, ptr %5, align 4, !tbaa !9
  %81 = getelementptr inbounds [80 x i8], ptr %7, i64 0, i64 0
  call void @sendString(ptr noundef %81)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %17, !llvm.loop !18

82:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 80, ptr %7) #4
  ret void
}

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 = { "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 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 #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 32}
!13 = !{!"_ZTS26InitialInteractiveLoaderSM", !14, i64 0, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !6, i64 48, !10, i64 56, !10, i64 60, !10, i64 64}
!14 = !{!"_ZTS4EfsmIcE", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !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: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z13int2hexStringjPci(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare void @sendString(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN26InitialInteractiveLoaderSM10runCommandEii(ptr nocapture noundef nonnull readonly align 8 dereferenceable(68) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #3 align 2 {
  %4 = alloca [80 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %4) #4
  %5 = icmp sgt i32 %2, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %6 = sext i32 %1 to i64
  %7 = inttoptr i64 %6 to ptr
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  br label %9

9:                                                ; preds = %.lr.ph, %32
  %.02441 = phi ptr [ %7, %.lr.ph ], [ %29, %32 ]
  %.02940 = phi i32 [ %2, %.lr.ph ], [ %24, %32 ]
  %.03239 = phi i32 [ %1, %.lr.ph ], [ %35, %32 ]
  %10 = call noundef ptr @_Z13int2hexStringjPci(i32 noundef %.03239, ptr noundef nonnull %4, i32 noundef 8)
  %11 = getelementptr inbounds i8, ptr %10, i64 1
  store i8 62, ptr %10, align 1, !tbaa !5
  %.pre.pre = load i32, ptr %8, align 8, !tbaa !8
  br label %12

12:                                               ; preds = %9, %28
  %.pre = phi i32 [ %.pre.pre, %9 ], [ %21, %28 ]
  %.02338 = phi i32 [ 0, %9 ], [ %25, %28 ]
  %.12537 = phi ptr [ %.02441, %9 ], [ %29, %28 ]
  %.02636 = phi ptr [ %11, %9 ], [ %20, %28 ]
  %.13035 = phi i32 [ %.02940, %9 ], [ %24, %28 ]
  %13 = load volatile i32, ptr %.12537, align 4, !tbaa !13
  br label %14

14:                                               ; preds = %12, %14
  %15 = phi i32 [ %.pre, %12 ], [ %21, %14 ]
  %.231 = phi i32 [ %.13035, %12 ], [ %24, %14 ]
  %.127 = phi ptr [ %.02636, %12 ], [ %20, %14 ]
  %.1 = phi i32 [ %.02338, %12 ], [ %25, %14 ]
  %.022 = phi i32 [ 4, %12 ], [ %16, %14 ]
  %.0 = phi i32 [ %13, %12 ], [ %23, %14 ]
  %16 = sub nsw i32 %.022, %15
  %17 = getelementptr inbounds i8, ptr %.127, i64 1
  store i8 32, ptr %.127, align 1, !tbaa !5
  %18 = load i32, ptr %8, align 8, !tbaa !8
  %19 = shl nsw i32 %18, 1
  %20 = call noundef ptr @_Z13int2hexStringjPci(i32 noundef %.0, ptr noundef nonnull %17, i32 noundef %19)
  %21 = load i32, ptr %8, align 8, !tbaa !8
  %22 = shl nsw i32 %21, 3
  %23 = lshr i32 %.0, %22
  %24 = sub nsw i32 %.231, %21
  %25 = add nsw i32 %21, %.1
  %26 = icmp sgt i32 %24, 0
  %27 = icmp sgt i32 %16, 0
  %or.cond = select i1 %26, i1 %27, i1 false
  br i1 %or.cond, label %14, label %28, !llvm.loop !14

28:                                               ; preds = %14
  %29 = getelementptr inbounds i8, ptr %.12537, i64 4
  %30 = icmp slt i32 %25, 16
  %31 = and i1 %26, %30
  br i1 %31, label %12, label %32, !llvm.loop !16

32:                                               ; preds = %28
  %33 = getelementptr inbounds i8, ptr %20, i64 1
  store i8 13, ptr %20, align 1, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %20, i64 2
  store i8 10, ptr %33, align 1, !tbaa !5
  store i8 0, ptr %34, align 1, !tbaa !5
  %35 = add nsw i32 %.03239, 16
  call void @sendString(ptr noundef nonnull %4)
  br i1 %26, label %9, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %32, %3
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %4) #4
  ret void
}

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 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 #4 = { 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++ TBAA"}
!8 = !{!9, !11, i64 32}
!9 = !{!"_ZTS26InitialInteractiveLoaderSM", !10, i64 0, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !12, i64 48, !11, i64 56, !11, i64 60, !11, i64 64}
!10 = !{!"_ZTS4EfsmIcE", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"any pointer", !6, i64 0}
!13 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}


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