; LLVM IR from lfarcaro/ARINC653_ARMV7A_Z7000 :: ARINC653_ARMV7A_Z7000.sw/ARINC653_ARMV7A_Z7000_bsp/ps7_cortexa9_0/libsrc (putnum)

; 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 void @putnum(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca [9 x i8], align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 9, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %15, %1
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 9
  br i1 %10, label %11, label %18

11:                                               ; preds = %8
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [9 x i8], ptr %3, i64 0, i64 %13
  store i8 48, ptr %14, align 1, !tbaa !9
  br label %15

15:                                               ; preds = %11
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %5, align 4, !tbaa !5
  br label %8, !llvm.loop !10

18:                                               ; preds = %8
  %19 = getelementptr inbounds [9 x i8], ptr %3, i64 0, i64 0
  store ptr %19, ptr %6, align 8, !tbaa !12
  store i32 7, ptr %4, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %56, %18
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = icmp sge i32 %21, 0
  br i1 %22, label %23, label %59

23:                                               ; preds = %20
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = mul i32 %25, 4
  %27 = lshr i32 %24, %26
  %28 = and i32 %27, 15
  store i32 %28, ptr %7, align 4, !tbaa !5
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = icmp ule i32 %29, 9
  br i1 %30, label %31, label %42

31:                                               ; preds = %23
  %32 = load ptr, ptr %6, align 8, !tbaa !12
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %42

34:                                               ; preds = %31
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = add i32 %35, 48
  store i32 %36, ptr %7, align 4, !tbaa !5
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = trunc i32 %37 to i8
  %39 = load ptr, ptr %6, align 8, !tbaa !12
  store i8 %38, ptr %39, align 1, !tbaa !9
  %40 = load ptr, ptr %6, align 8, !tbaa !12
  %41 = getelementptr inbounds i8, ptr %40, i64 1
  store ptr %41, ptr %6, align 8, !tbaa !12
  br label %55

42:                                               ; preds = %31, %23
  %43 = load ptr, ptr %6, align 8, !tbaa !12
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %53

45:                                               ; preds = %42
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = add i32 %46, 87
  store i32 %47, ptr %7, align 4, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = trunc i32 %48 to i8
  %50 = load ptr, ptr %6, align 8, !tbaa !12
  store i8 %49, ptr %50, align 1, !tbaa !9
  %51 = load ptr, ptr %6, align 8, !tbaa !12
  %52 = getelementptr inbounds i8, ptr %51, i64 1
  store ptr %52, ptr %6, align 8, !tbaa !12
  br label %54

53:                                               ; preds = %42
  br label %54

54:                                               ; preds = %53, %45
  br label %55

55:                                               ; preds = %54, %34
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = add nsw i32 %57, -1
  store i32 %58, ptr %4, align 4, !tbaa !5
  br label %20, !llvm.loop !14

59:                                               ; preds = %20
  %60 = load ptr, ptr %6, align 8, !tbaa !12
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %64

62:                                               ; preds = %59
  %63 = load ptr, ptr %6, align 8, !tbaa !12
  store i8 0, ptr %63, align 1, !tbaa !9
  br label %64

64:                                               ; preds = %62, %59
  %65 = getelementptr inbounds [9 x i8], ptr %3, i64 0, i64 0
  call void @print(ptr noundef %65)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, 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 9, ptr %3) #3
  ret void
}

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

declare void @print(ptr noundef) #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 = { "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 = { 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 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = distinct !{!14, !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: nounwind uwtable
define dso_local void @putnum(i32 noundef %0) local_unnamed_addr #0 {
.preheader.preheader:
  %1 = alloca [9 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 9, ptr nonnull %1) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(9) %1, i8 48, i64 9, i1 false), !tbaa !5
  %2 = lshr i32 %0, 28
  %3 = icmp ult i32 %0, -1610612736
  %4 = trunc nuw nsw i32 %2 to i8
  %5 = add nuw nsw i8 %4, 87
  %6 = or disjoint i8 %4, 48
  %storemerge = select i1 %3, i8 %6, i8 %5
  store i8 %storemerge, ptr %1, align 1, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %1, i64 1
  %8 = lshr i32 %0, 24
  %9 = and i32 %8, 15
  %10 = icmp ult i32 %9, 10
  %11 = trunc nuw nsw i32 %9 to i8
  %12 = or disjoint i8 %11, 48
  %13 = add nuw nsw i8 %11, 87
  %.sink = select i1 %10, i8 %12, i8 %13
  store i8 %.sink, ptr %7, align 1, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %1, i64 2
  %15 = lshr i32 %0, 20
  %16 = and i32 %15, 15
  %17 = icmp ult i32 %16, 10
  %18 = trunc nuw nsw i32 %16 to i8
  %19 = or disjoint i8 %18, 48
  %20 = trunc nuw nsw i32 %16 to i8
  %21 = add nuw nsw i8 %20, 87
  %.sink27 = select i1 %17, i8 %19, i8 %21
  store i8 %.sink27, ptr %14, align 1, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %1, i64 3
  %23 = lshr i32 %0, 16
  %24 = and i32 %23, 15
  %25 = icmp ult i32 %24, 10
  %26 = trunc nuw nsw i32 %24 to i8
  %27 = or disjoint i8 %26, 48
  %28 = trunc nuw nsw i32 %24 to i8
  %29 = add nuw nsw i8 %28, 87
  %.sink28 = select i1 %25, i8 %27, i8 %29
  store i8 %.sink28, ptr %22, align 1, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %1, i64 4
  %31 = lshr i32 %0, 12
  %32 = lshr i32 %0, 8
  %33 = lshr i32 %0, 4
  %34 = insertelement <4 x i32> poison, i32 %31, i64 0
  %35 = insertelement <4 x i32> %34, i32 %32, i64 1
  %36 = insertelement <4 x i32> %35, i32 %33, i64 2
  %37 = insertelement <4 x i32> %36, i32 %0, i64 3
  %38 = and <4 x i32> %37, <i32 15, i32 15, i32 15, i32 15>
  %39 = icmp ult <4 x i32> %38, <i32 10, i32 10, i32 10, i32 10>
  %40 = trunc nuw nsw <4 x i32> %38 to <4 x i8>
  %41 = or disjoint <4 x i8> %40, <i8 48, i8 48, i8 48, i8 48>
  %42 = trunc nuw nsw <4 x i32> %38 to <4 x i8>
  %43 = add nuw nsw <4 x i8> %42, <i8 87, i8 87, i8 87, i8 87>
  %44 = select <4 x i1> %39, <4 x i8> %41, <4 x i8> %43
  store <4 x i8> %44, ptr %30, align 1, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %1, i64 8
  store i8 0, ptr %45, align 1, !tbaa !5
  call void @print(ptr noundef nonnull %1) #4
  call void @llvm.lifetime.end.p0(i64 9, ptr nonnull %1) #4
  ret void
}

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

declare void @print(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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) #3

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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass