; LLVM IR from lfarcaro/ARINC653_ARMV7A_AM335X :: Hardware (uartStdio)

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

; Function Attrs: nounwind uwtable
declare dso_local void @UARTPutc(i8 noundef zeroext) #1

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

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

8:                                                ; preds = %24, %1
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = udiv i32 %9, 16
  store i32 %10, ptr %4, align 4, !tbaa !5
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = urem i32 %11, 16
  %13 = trunc i32 %12 to i8
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [8 x i8], ptr %3, i64 0, i64 %15
  store i8 %13, ptr %16, align 1, !tbaa !9
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = icmp eq i32 0, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %8
  br label %27

20:                                               ; preds = %8
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %6, align 4, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %23, ptr %5, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %20
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = icmp slt i32 %25, 8
  br i1 %26, label %8, label %27, !llvm.loop !10

27:                                               ; preds = %24, %19
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = icmp eq i32 8, %28
  br i1 %29, label %30, label %33

30:                                               ; preds = %27
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = add nsw i32 %31, -1
  store i32 %32, ptr %6, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %30, %27
  call void @UARTPutc(i8 noundef zeroext 48)
  call void @UARTPutc(i8 noundef zeroext 120)
  br label %34

34:                                               ; preds = %63, %33
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = icmp sge i32 %35, 0
  br i1 %36, label %37, label %64

37:                                               ; preds = %34
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [8 x i8], ptr %3, i64 0, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !9
  %42 = zext i8 %41 to i32
  %43 = sub nsw i32 16, %42
  %44 = icmp sle i32 %43, 6
  br i1 %44, label %45, label %54

45:                                               ; preds = %37
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = add nsw i32 %46, -1
  store i32 %47, ptr %6, align 4, !tbaa !5
  %48 = sext i32 %46 to i64
  %49 = getelementptr inbounds [8 x i8], ptr %3, i64 0, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !9
  %51 = zext i8 %50 to i32
  %52 = add nsw i32 %51, 55
  %53 = trunc i32 %52 to i8
  call void @UARTPutc(i8 noundef zeroext %53)
  br label %63

54:                                               ; preds = %37
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = add nsw i32 %55, -1
  store i32 %56, ptr %6, align 4, !tbaa !5
  %57 = sext i32 %55 to i64
  %58 = getelementptr inbounds [8 x i8], ptr %3, i64 0, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !9
  %60 = zext i8 %59 to i32
  %61 = add nsw i32 %60, 48
  %62 = trunc i32 %61 to i8
  call void @UARTPutc(i8 noundef zeroext %62)
  br label %63

63:                                               ; preds = %54, %45
  br label %34, !llvm.loop !12

64:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

; Function Attrs: nounwind uwtable
declare dso_local void @UARTPutc(i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: mustprogress 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 void @UARTPutHexNum(i32 noundef %0) local_unnamed_addr #1 {
  %2 = alloca [8 x i8], align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #2
  store i64 0, ptr %2, align 8
  %3 = trunc i32 %0 to i8
  %4 = and i8 %3, 15
  store i8 %4, ptr %2, align 8, !tbaa !5
  %5 = icmp ult i32 %0, 16
  br i1 %5, label %.lr.ph.preheader, label %6

6:                                                ; preds = %1
  %7 = trunc i32 %0 to i8
  %8 = lshr i8 %7, 4
  %9 = getelementptr inbounds i8, ptr %2, i64 1
  store i8 %8, ptr %9, align 1, !tbaa !5
  %10 = icmp ult i32 %0, 256
  br i1 %10, label %.lr.ph.preheader, label %11

11:                                               ; preds = %6
  %12 = lshr i32 %0, 8
  %13 = trunc i32 %12 to i8
  %14 = and i8 %13, 15
  %15 = getelementptr inbounds i8, ptr %2, i64 2
  store i8 %14, ptr %15, align 2, !tbaa !5
  %16 = icmp ult i32 %0, 4096
  br i1 %16, label %.lr.ph.preheader, label %17

17:                                               ; preds = %11
  %18 = lshr i32 %0, 12
  %19 = trunc i32 %18 to i8
  %20 = and i8 %19, 15
  %21 = getelementptr inbounds i8, ptr %2, i64 3
  store i8 %20, ptr %21, align 1, !tbaa !5
  %22 = icmp ult i32 %0, 65536
  br i1 %22, label %.lr.ph.preheader, label %23

23:                                               ; preds = %17
  %24 = lshr i32 %0, 16
  %25 = trunc i32 %24 to i8
  %26 = and i8 %25, 15
  %27 = getelementptr inbounds i8, ptr %2, i64 4
  store i8 %26, ptr %27, align 4, !tbaa !5
  %28 = icmp ult i32 %0, 1048576
  br i1 %28, label %.lr.ph.preheader, label %29

29:                                               ; preds = %23
  %30 = lshr i32 %0, 20
  %31 = trunc i32 %30 to i8
  %32 = and i8 %31, 15
  %33 = getelementptr inbounds i8, ptr %2, i64 5
  store i8 %32, ptr %33, align 1, !tbaa !5
  %34 = icmp ult i32 %0, 16777216
  br i1 %34, label %.lr.ph.preheader, label %35

35:                                               ; preds = %29
  %36 = lshr i32 %0, 24
  %37 = trunc nuw i32 %36 to i8
  %38 = and i8 %37, 15
  %39 = getelementptr inbounds i8, ptr %2, i64 6
  store i8 %38, ptr %39, align 2, !tbaa !5
  %40 = icmp ult i32 %0, 268435456
  br i1 %40, label %.lr.ph.preheader, label %41

41:                                               ; preds = %35
  %42 = lshr i32 %0, 28
  %43 = trunc nuw nsw i32 %42 to i8
  %44 = getelementptr inbounds i8, ptr %2, i64 7
  store i8 %43, ptr %44, align 1, !tbaa !5
  br label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1, %6, %11, %17, %23, %29, %35, %41
  %.1 = phi i64 [ 0, %1 ], [ 1, %6 ], [ 2, %11 ], [ 3, %17 ], [ 4, %23 ], [ 5, %29 ], [ 6, %35 ], [ 7, %41 ]
  tail call void @UARTPutc(i8 noundef zeroext 48)
  tail call void @UARTPutc(i8 noundef zeroext 120)
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %.1, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %45 = getelementptr inbounds [8 x i8], ptr %2, i64 0, i64 %indvars.iv
  %46 = load i8, ptr %45, align 1, !tbaa !5
  %47 = icmp ugt i8 %46, 9
  %48 = or disjoint i8 %46, 48
  %49 = add i8 %46, 55
  %.sink = select i1 %47, i8 %49, i8 %48
  tail call void @UARTPutc(i8 noundef zeroext %.sink)
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %50 = icmp sgt i64 %indvars.iv, 0
  br i1 %50, label %.lr.ph, label %select.unfold._crit_edge, !llvm.loop !8

select.unfold._crit_edge:                         ; preds = %.lr.ph
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #2
  ret void
}

attributes #0 = { mustprogress 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass