; 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 @ultoa(i64 noundef %0, ptr noundef %1, i32 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca [65 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 i64 %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 65, ptr %9) #4
  call void @llvm.memset.p0.i64(ptr align 16 %9, i8 0, i64 65, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %15 = getelementptr inbounds [65 x i8], ptr %9, i64 0, i64 63
  store ptr %15, ptr %10, align 8, !tbaa !9
  %16 = load i64, ptr %5, align 8, !tbaa !5
  %17 = icmp ult i64 %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 !13
  %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 i64, ptr %5, align 8, !tbaa !5
  %23 = mul i64 %22, -1
  store i64 %23, ptr %5, align 8, !tbaa !5
  br label %34

24:                                               ; preds = %3
  %25 = load i64, ptr %5, align 8, !tbaa !5
  %26 = icmp eq i64 %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 !13
  %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 !13
  %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 %90

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 !11
  br label %35

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

39:                                               ; preds = %35
  %40 = load i64, ptr %5, align 8, !tbaa !5
  %41 = icmp ne i64 %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 %77

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

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

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

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

66:                                               ; preds = %60, %57
  br label %67

67:                                               ; preds = %66, %52
  %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 !11
  %71 = sext i32 %70 to i64
  %72 = load i64, ptr %5, align 8, !tbaa !5
  %73 = udiv i64 %72, %71
  store i64 %73, ptr %5, align 8, !tbaa !5
  br label %74

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

77:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %78 = load ptr, ptr %10, align 8, !tbaa !9
  %79 = getelementptr inbounds i8, ptr %78, i64 1
  store ptr %79, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %80 = getelementptr inbounds [65 x i8], ptr %9, i64 0, i64 64
  %81 = load ptr, ptr %10, align 8, !tbaa !9
  %82 = ptrtoint ptr %80 to i64
  %83 = ptrtoint ptr %81 to i64
  %84 = sub i64 %82, %83
  store i64 %84, ptr %14, align 8, !tbaa !5
  %85 = load ptr, ptr %6, align 8, !tbaa !9
  %86 = load ptr, ptr %13, align 8, !tbaa !9
  %87 = load i64, ptr %14, align 8, !tbaa !5
  %88 = call ptr @strncpy(ptr noundef %85, ptr noundef %86, i64 noundef %87) #4
  %89 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %89, 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 %90

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

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 = !{!"long", !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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; 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 @ultoa(i64 noundef %0, ptr noundef returned %1, i32 noundef %2) local_unnamed_addr #3 {
  %4 = alloca [65 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 65, ptr nonnull %4) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(65) %4, i8 0, i64 65, i1 false)
  %5 = icmp eq i64 %0, 0
  br i1 %5, label %25, label %.preheader

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

.preheader.split.us:                              ; preds = %.preheader, %19
  %.136.us = phi i64 [ %10, %19 ], [ %0, %.preheader ]
  %.02935.us = phi i32 [ %21, %19 ], [ 0, %.preheader ]
  %.13134.us = phi ptr [ %20, %19 ], [ %6, %.preheader ]
  %9 = urem i64 %.136.us, %7
  %10 = udiv i64 %.136.us, %7
  %11 = icmp ult i64 %9, 10
  br i1 %11, label %16, label %12

12:                                               ; preds = %.preheader.split.us
  %13 = add nsw i64 %9, -10
  %14 = getelementptr inbounds [7 x i8], ptr @.str, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !5
  br label %19

16:                                               ; preds = %.preheader.split.us
  %17 = trunc nuw i64 %9 to i8
  %18 = or disjoint i8 %17, 48
  br label %19

19:                                               ; preds = %16, %12
  %storemerge = phi i8 [ %15, %12 ], [ %18, %16 ]
  store i8 %storemerge, ptr %.13134.us, align 1, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %.13134.us, i64 -1
  %21 = add nuw nsw i32 %.02935.us, 1
  %22 = icmp ult i32 %.02935.us, 63
  %23 = icmp uge i64 %.136.us, %7
  %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, %19
  %.us-phi = phi ptr [ %20, %19 ], [ %40, %39 ]
  %27 = getelementptr inbounds i8, ptr %.us-phi, i64 1
  %28 = getelementptr inbounds i8, ptr %4, i64 64
  %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 i64 [ %34, %39 ], [ %0, %.preheader ]
  %.02935 = phi i32 [ %41, %39 ], [ 0, %.preheader ]
  %.13134 = phi ptr [ %40, %39 ], [ %6, %.preheader ]
  %33 = urem i64 %.136, %7
  %34 = udiv i64 %.136, %7
  %35 = icmp ult i64 %33, 10
  br i1 %35, label %36, label %39

36:                                               ; preds = %.preheader.split
  %37 = trunc nuw i64 %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, 63
  %43 = icmp uge i64 %.136, %7
  %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 65, 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: DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass