; LLVM IR from tenok-rtos/tenok :: kernel (printf)

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

@.str = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.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) #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
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @utoa(i32 noundef %0, ptr noundef %1, i32 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca [33 x i8], align 16
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 33, ptr %9) #4
  call void @llvm.memset.p0.i64(ptr align 16 %9, i8 0, i64 33, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %15 = getelementptr inbounds [33 x i8], ptr %9, i64 0, i64 31
  store ptr %15, ptr %10, align 8, !tbaa !9
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = icmp ult i32 %16, 0
  br i1 %17, label %18, label %24

18:                                               ; preds = %3
  %19 = load ptr, ptr %10, align 8, !tbaa !9
  store i8 45, ptr %19, align 1, !tbaa !11
  %20 = load ptr, ptr %10, align 8, !tbaa !9
  %21 = getelementptr inbounds i8, ptr %20, i32 -1
  store ptr %21, ptr %10, align 8, !tbaa !9
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = mul i32 %22, -1
  store i32 %23, ptr %5, align 4, !tbaa !5
  br label %34

24:                                               ; preds = %3
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %33

27:                                               ; preds = %24
  %28 = load ptr, ptr %6, align 8, !tbaa !9
  %29 = getelementptr inbounds i8, ptr %28, i64 0
  store i8 48, ptr %29, align 1, !tbaa !11
  %30 = load ptr, ptr %6, align 8, !tbaa !9
  %31 = getelementptr inbounds i8, ptr %30, i64 1
  store i8 0, ptr %31, align 1, !tbaa !11
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %32, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %89

33:                                               ; preds = %24
  br label %34

34:                                               ; preds = %33, %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %73, %34
  %36 = load i32, ptr %12, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = icmp ult i64 %37, 32
  br i1 %38, label %39, label %42

39:                                               ; preds = %35
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = icmp ne i32 %40, 0
  br label %42

42:                                               ; preds = %39, %35
  %43 = phi i1 [ false, %35 ], [ %41, %39 ]
  br i1 %43, label %45, label %44

44:                                               ; preds = %42
  store i32 2, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %76

45:                                               ; preds = %42
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = urem i32 %46, %47
  store i32 %48, ptr %8, align 4, !tbaa !5
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = icmp ult i32 %49, 10
  br i1 %50, label %51, label %56

51:                                               ; preds = %45
  %52 = load i32, ptr %8, align 4, !tbaa !5
  %53 = add i32 %52, 48
  %54 = trunc i32 %53 to i8
  %55 = load ptr, ptr %10, align 8, !tbaa !9
  store i8 %54, ptr %55, align 1, !tbaa !11
  br label %67

56:                                               ; preds = %45
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = icmp eq i32 %57, 16
  br i1 %58, label %59, label %66

59:                                               ; preds = %56
  %60 = load i32, ptr %8, align 4, !tbaa !5
  %61 = sub i32 %60, 10
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds [7 x i8], ptr @.str, i64 0, i64 %62
  %64 = load i8, ptr %63, align 1, !tbaa !11
  %65 = load ptr, ptr %10, align 8, !tbaa !9
  store i8 %64, ptr %65, align 1, !tbaa !11
  br label %66

66:                                               ; preds = %59, %56
  br label %67

67:                                               ; preds = %66, %51
  %68 = load ptr, ptr %10, align 8, !tbaa !9
  %69 = getelementptr inbounds i8, ptr %68, i32 -1
  store ptr %69, ptr %10, align 8, !tbaa !9
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = udiv i32 %71, %70
  store i32 %72, ptr %5, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %67
  %74 = load i32, ptr %12, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %12, align 4, !tbaa !5
  br label %35, !llvm.loop !12

76:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %77 = load ptr, ptr %10, align 8, !tbaa !9
  %78 = getelementptr inbounds i8, ptr %77, i64 1
  store ptr %78, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %79 = getelementptr inbounds [33 x i8], ptr %9, i64 0, i64 32
  %80 = load ptr, ptr %10, align 8, !tbaa !9
  %81 = ptrtoint ptr %79 to i64
  %82 = ptrtoint ptr %80 to i64
  %83 = sub i64 %81, %82
  store i64 %83, ptr %14, align 8, !tbaa !14
  %84 = load ptr, ptr %6, align 8, !tbaa !9
  %85 = load ptr, ptr %13, align 8, !tbaa !9
  %86 = load i64, ptr %14, align 8, !tbaa !14
  %87 = call ptr @strncpy(ptr noundef %84, ptr noundef %85, i64 noundef %86) #4
  %88 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %88, ptr %4, align 8
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %89

89:                                               ; preds = %76, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 33, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %90 = load ptr, ptr %4, align 8
  ret ptr %90
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nounwind "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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/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"}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}


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

@.str = external hidden unnamed_addr constant [7 x i8], align 1

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind memory(argmem: readwrite) uwtable
define dso_local noundef ptr @utoa(i32 noundef %0, ptr noundef returned %1, i32 noundef %2) local_unnamed_addr #3 {
  %4 = alloca [33 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 33, ptr nonnull %4) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(33) %4, i8 0, i64 33, i1 false)
  %5 = icmp eq i32 %0, 0
  br i1 %5, label %25, label %.preheader

.preheader:                                       ; preds = %3
  %6 = getelementptr inbounds i8, ptr %4, i64 31
  %7 = icmp eq i32 %2, 16
  br i1 %7, label %.preheader.split.us, label %.preheader.split

.preheader.split.us:                              ; preds = %.preheader, %18
  %.136.us = phi i32 [ %20, %18 ], [ %0, %.preheader ]
  %.02935.us = phi i32 [ %21, %18 ], [ 0, %.preheader ]
  %.13134.us = phi ptr [ %19, %18 ], [ %6, %.preheader ]
  %8 = and i32 %.136.us, 15
  %9 = icmp ult i32 %8, 10
  br i1 %9, label %15, label %10

10:                                               ; preds = %.preheader.split.us
  %11 = add nsw i32 %8, -10
  %12 = zext nneg i32 %11 to i64
  %13 = getelementptr inbounds [7 x i8], ptr @.str, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !5
  br label %18

15:                                               ; preds = %.preheader.split.us
  %16 = trunc nuw nsw i32 %8 to i8
  %17 = or disjoint i8 %16, 48
  br label %18

18:                                               ; preds = %15, %10
  %storemerge = phi i8 [ %14, %10 ], [ %17, %15 ]
  store i8 %storemerge, ptr %.13134.us, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.13134.us, i64 -1
  %20 = lshr i32 %.136.us, 4
  %21 = add nuw nsw i32 %.02935.us, 1
  %22 = icmp ult i32 %.02935.us, 31
  %23 = icmp ugt i32 %.136.us, 15
  %24 = and i1 %22, %23
  br i1 %24, label %.preheader.split.us, label %.split.us, !llvm.loop !8

25:                                               ; preds = %3
  store i8 48, ptr %1, align 1, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 0, ptr %26, align 1, !tbaa !5
  br label %45

.split.us:                                        ; preds = %39, %18
  %.us-phi = phi ptr [ %19, %18 ], [ %40, %39 ]
  %27 = getelementptr inbounds i8, ptr %.us-phi, i64 1
  %28 = getelementptr inbounds i8, ptr %4, i64 32
  %29 = ptrtoint ptr %28 to i64
  %30 = ptrtoint ptr %.us-phi to i64
  %31 = sub i64 %29, %30
  %32 = call ptr @strncpy(ptr noundef %1, ptr noundef nonnull %27, i64 noundef %31) #4
  br label %45

.preheader.split:                                 ; preds = %.preheader, %39
  %.136 = phi i32 [ %34, %39 ], [ %0, %.preheader ]
  %.02935 = phi i32 [ %41, %39 ], [ 0, %.preheader ]
  %.13134 = phi ptr [ %40, %39 ], [ %6, %.preheader ]
  %33 = urem i32 %.136, %2
  %34 = udiv i32 %.136, %2
  %35 = icmp ult i32 %33, 10
  br i1 %35, label %36, label %39

36:                                               ; preds = %.preheader.split
  %37 = trunc nuw i32 %33 to i8
  %38 = or disjoint i8 %37, 48
  store i8 %38, ptr %.13134, align 1, !tbaa !5
  br label %39

39:                                               ; preds = %.preheader.split, %36
  %40 = getelementptr inbounds i8, ptr %.13134, i64 -1
  %41 = add nuw nsw i32 %.02935, 1
  %42 = icmp ult i32 %.02935, 31
  %43 = icmp uge i32 %.136, %2
  %44 = and i1 %42, %43
  br i1 %44, label %.preheader.split, label %.split.us, !llvm.loop !8

45:                                               ; preds = %.split.us, %25
  call void @llvm.lifetime.end.p0(i64 33, ptr nonnull %4) #4
  ret ptr %1
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 = { nofree nounwind memory(argmem: readwrite) 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/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass