; 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: nounwind uwtable
define dso_local ptr @itoa(i32 noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %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 slt 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 nsw 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 = srem i32 %46, %47
  store i32 %48, ptr %8, align 4, !tbaa !5
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = icmp slt i32 %49, 10
  br i1 %50, label %51, label %56

51:                                               ; preds = %45
  %52 = load i32, ptr %8, align 4, !tbaa !5
  %53 = add nsw 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 nsw i32 %60, 10
  %62 = sext 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 = sdiv 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
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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: nofree nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef ptr @itoa(i32 noundef %0, ptr noundef returned %1, i32 noundef %2) local_unnamed_addr #0 {
  %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 = getelementptr inbounds i8, ptr %4, i64 31
  %6 = icmp slt i32 %0, 0
  br i1 %6, label %7, label %10

7:                                                ; preds = %3
  store i8 45, ptr %5, align 1, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %4, i64 30
  %9 = sub nsw i32 0, %0
  br label %.lr.ph

10:                                               ; preds = %3
  %11 = icmp eq i32 %0, 0
  br i1 %11, label %12, label %.lr.ph

12:                                               ; preds = %10
  store i8 48, ptr %1, align 1, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 0, ptr %13, align 1, !tbaa !5
  br label %51

.lr.ph:                                           ; preds = %7, %10
  %.030 = phi ptr [ %8, %7 ], [ %5, %10 ]
  %.028 = phi i32 [ %9, %7 ], [ %0, %10 ]
  %14 = icmp eq i32 %2, 16
  br i1 %14, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %26
  %.137.us = phi i32 [ %16, %26 ], [ %.028, %.lr.ph ]
  %.02936.us = phi i32 [ %28, %26 ], [ 0, %.lr.ph ]
  %.13135.us = phi ptr [ %27, %26 ], [ %.030, %.lr.ph ]
  %15 = srem i32 %.137.us, 16
  %16 = sdiv i32 %.137.us, 16
  %17 = icmp slt i32 %15, 10
  br i1 %17, label %23, label %18

18:                                               ; preds = %.lr.ph.split.us
  %19 = add nsw i32 %15, -10
  %20 = zext nneg i32 %19 to i64
  %21 = getelementptr inbounds [7 x i8], ptr @.str, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !5
  br label %26

23:                                               ; preds = %.lr.ph.split.us
  %24 = trunc nsw i32 %15 to i8
  %25 = add nsw i8 %24, 48
  br label %26

26:                                               ; preds = %23, %18
  %storemerge = phi i8 [ %22, %18 ], [ %25, %23 ]
  store i8 %storemerge, ptr %.13135.us, align 1, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %.13135.us, i64 -1
  %28 = add nuw nsw i32 %.02936.us, 1
  %29 = icmp ult i32 %.02936.us, 31
  %30 = add i32 %.137.us, -16
  %31 = icmp ult i32 %30, -31
  %32 = and i1 %29, %31
  br i1 %32, label %.lr.ph.split.us, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %45, %26
  %.131.lcssa = phi ptr [ %27, %26 ], [ %46, %45 ]
  %33 = getelementptr inbounds i8, ptr %.131.lcssa, i64 1
  %34 = getelementptr inbounds i8, ptr %4, i64 32
  %35 = ptrtoint ptr %34 to i64
  %36 = ptrtoint ptr %.131.lcssa to i64
  %37 = sub i64 %35, %36
  %38 = call ptr @strncpy(ptr noundef %1, ptr noundef nonnull %33, i64 noundef %37) #4
  br label %51

.lr.ph.split:                                     ; preds = %.lr.ph, %45
  %.137 = phi i32 [ %40, %45 ], [ %.028, %.lr.ph ]
  %.02936 = phi i32 [ %47, %45 ], [ 0, %.lr.ph ]
  %.13135 = phi ptr [ %46, %45 ], [ %.030, %.lr.ph ]
  %39 = srem i32 %.137, %2
  %40 = sdiv i32 %.137, %2
  %41 = icmp slt i32 %39, 10
  br i1 %41, label %42, label %45

42:                                               ; preds = %.lr.ph.split
  %43 = trunc i32 %39 to i8
  %44 = add i8 %43, 48
  store i8 %44, ptr %.13135, align 1, !tbaa !5
  br label %45

45:                                               ; preds = %.lr.ph.split, %42
  %46 = getelementptr inbounds i8, ptr %.13135, i64 -1
  %47 = add nuw nsw i32 %.02936, 1
  %48 = icmp ult i32 %.02936, 31
  %49 = icmp ne i32 %40, 0
  %50 = and i1 %48, %49
  br i1 %50, label %.lr.ph.split, label %._crit_edge, !llvm.loop !8

51:                                               ; preds = %._crit_edge, %12
  call void @llvm.lifetime.end.p0(i64 33, ptr nonnull %4) #4
  ret ptr %1
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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: 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 #3

attributes #0 = { nofree nounwind memory(readwrite, inaccessiblemem: none) 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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: DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass