; 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: nounwind uwtable
define dso_local void @UARTPutNum(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca [10 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 10, ptr %3) #3
  call void @llvm.memset.p0.i64(ptr align 1 %3, i8 0, i64 10, 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
  %8 = icmp slt i32 %7, 0
  br i1 %8, label %9, label %12

9:                                                ; preds = %1
  call void @UARTPutc(i8 noundef zeroext 45)
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sub nsw i32 0, %10
  store i32 %11, ptr %2, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %9, %1
  %13 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %13, ptr %5, align 4, !tbaa !5
  br label %14

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

25:                                               ; preds = %14
  br label %33

26:                                               ; preds = %14
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %6, align 4, !tbaa !5
  %29 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %29, ptr %5, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %26
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = icmp slt i32 %31, 10
  br i1 %32, label %14, label %33, !llvm.loop !10

33:                                               ; preds = %30, %25
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = icmp eq i32 10, %34
  br i1 %35, label %36, label %39

36:                                               ; preds = %33
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr %6, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %36, %33
  br label %40

40:                                               ; preds = %49, %39
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = add nsw i32 %41, -1
  store i32 %42, ptr %6, align 4, !tbaa !5
  %43 = sext i32 %41 to i64
  %44 = getelementptr inbounds [10 x i8], ptr %3, i64 0, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !9
  %46 = zext i8 %45 to i32
  %47 = add nsw i32 %46, 48
  %48 = trunc i32 %47 to i8
  call void @UARTPutc(i8 noundef zeroext %48)
  br label %49

49:                                               ; preds = %40
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = icmp sge i32 %50, 0
  br i1 %51, label %40, label %52, !llvm.loop !12

52:                                               ; preds = %49
  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 10, ptr %3) #3
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 @UARTPutNum(i32 noundef %0) local_unnamed_addr #1 {
  %2 = alloca [10 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 10, ptr nonnull %2) #3
  %3 = getelementptr inbounds i8, ptr %2, i64 1
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(10) %3, i8 0, i64 9, i1 false)
  %4 = icmp slt i32 %0, 0
  br i1 %4, label %5, label %7

5:                                                ; preds = %1
  tail call void @UARTPutc(i8 noundef zeroext 45)
  %6 = sub nsw i32 0, %0
  br label %7

7:                                                ; preds = %5, %1
  %.015 = phi i32 [ %6, %5 ], [ %0, %1 ]
  %8 = urem i32 %.015, 10
  %9 = udiv i32 %.015, 10
  %10 = trunc nuw nsw i32 %8 to i8
  store i8 %10, ptr %2, align 1, !tbaa !5
  %11 = icmp ult i32 %.015, 10
  br i1 %11, label %select.unfold.preheader, label %12

12:                                               ; preds = %7
  %13 = urem i32 %9, 10
  %14 = trunc nuw nsw i32 %13 to i8
  %15 = getelementptr inbounds i8, ptr %2, i64 1
  store i8 %14, ptr %15, align 1, !tbaa !5
  %16 = icmp ult i32 %.015, 100
  br i1 %16, label %select.unfold.preheader, label %17

17:                                               ; preds = %12
  %18 = udiv i32 %.015, 100
  %19 = urem i32 %18, 10
  %20 = trunc nuw nsw i32 %19 to i8
  %21 = getelementptr inbounds i8, ptr %2, i64 2
  store i8 %20, ptr %21, align 1, !tbaa !5
  %22 = icmp ult i32 %.015, 1000
  br i1 %22, label %select.unfold.preheader, label %23

23:                                               ; preds = %17
  %24 = udiv i32 %.015, 1000
  %25 = urem i32 %24, 10
  %26 = trunc nuw nsw i32 %25 to i8
  %27 = getelementptr inbounds i8, ptr %2, i64 3
  store i8 %26, ptr %27, align 1, !tbaa !5
  %28 = icmp ult i32 %.015, 10000
  br i1 %28, label %select.unfold.preheader, label %29

29:                                               ; preds = %23
  %30 = udiv i32 %.015, 10000
  %31 = urem i32 %30, 10
  %32 = trunc nuw nsw i32 %31 to i8
  %33 = getelementptr inbounds i8, ptr %2, i64 4
  store i8 %32, ptr %33, align 1, !tbaa !5
  %34 = icmp ult i32 %.015, 100000
  br i1 %34, label %select.unfold.preheader, label %35

35:                                               ; preds = %29
  %36 = udiv i32 %.015, 100000
  %.lhs.trunc = trunc nuw i32 %36 to i16
  %37 = urem i16 %.lhs.trunc, 10
  %38 = trunc nuw nsw i16 %37 to i8
  %39 = getelementptr inbounds i8, ptr %2, i64 5
  store i8 %38, ptr %39, align 1, !tbaa !5
  %40 = icmp ult i32 %.015, 1000000
  br i1 %40, label %select.unfold.preheader, label %41

41:                                               ; preds = %35
  %42 = udiv i32 %.015, 1000000
  %.lhs.trunc23 = trunc nuw nsw i32 %42 to i16
  %43 = urem i16 %.lhs.trunc23, 10
  %44 = trunc nuw nsw i16 %43 to i8
  %45 = getelementptr inbounds i8, ptr %2, i64 6
  store i8 %44, ptr %45, align 1, !tbaa !5
  %46 = icmp ult i32 %.015, 10000000
  br i1 %46, label %select.unfold.preheader, label %47

47:                                               ; preds = %41
  %48 = udiv i32 %.015, 10000000
  %.lhs.trunc25 = trunc i32 %48 to i8
  %49 = urem i8 %.lhs.trunc25, 10
  %50 = getelementptr inbounds i8, ptr %2, i64 7
  store i8 %49, ptr %50, align 1, !tbaa !5
  %51 = icmp ult i32 %.015, 100000000
  br i1 %51, label %select.unfold.preheader, label %52

52:                                               ; preds = %47
  %53 = udiv i32 %.015, 100000000
  %.lhs.trunc27 = trunc nuw nsw i32 %53 to i8
  %54 = urem i8 %.lhs.trunc27, 10
  %55 = getelementptr inbounds i8, ptr %2, i64 8
  store i8 %54, ptr %55, align 1, !tbaa !5
  %56 = icmp ult i32 %.015, 1000000000
  br i1 %56, label %select.unfold.preheader, label %57

57:                                               ; preds = %52
  %58 = udiv i32 %.015, 1000000000
  %59 = trunc nuw nsw i32 %58 to i8
  %60 = getelementptr inbounds i8, ptr %2, i64 9
  store i8 %59, ptr %60, align 1, !tbaa !5
  br label %select.unfold.preheader

select.unfold.preheader:                          ; preds = %57, %52, %47, %41, %35, %29, %23, %17, %12, %7
  %indvars.iv.ph = phi i64 [ 9, %57 ], [ 8, %52 ], [ 7, %47 ], [ 6, %41 ], [ 5, %35 ], [ 4, %29 ], [ 3, %23 ], [ 2, %17 ], [ 1, %12 ], [ 0, %7 ]
  br label %select.unfold

select.unfold:                                    ; preds = %select.unfold.preheader, %select.unfold
  %indvars.iv = phi i64 [ %indvars.iv.next, %select.unfold ], [ %indvars.iv.ph, %select.unfold.preheader ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %61 = getelementptr inbounds [10 x i8], ptr %2, i64 0, i64 %indvars.iv
  %62 = load i8, ptr %61, align 1, !tbaa !5
  %63 = add i8 %62, 48
  tail call void @UARTPutc(i8 noundef zeroext %63)
  %.not = icmp eq i64 %indvars.iv, 0
  br i1 %.not, label %64, label %select.unfold, !llvm.loop !8

64:                                               ; preds = %select.unfold
  call void @llvm.lifetime.end.p0(i64 10, ptr nonnull %2) #3
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { 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"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,DivRemPairsPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass