; 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 @ltoa(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 slt 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 nsw 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 = srem i64 %46, %48
  store i64 %49, ptr %8, align 8, !tbaa !5
  %50 = load i64, ptr %8, align 8, !tbaa !5
  %51 = icmp slt i64 %50, 10
  br i1 %51, label %52, label %57

52:                                               ; preds = %45
  %53 = load i64, ptr %8, align 8, !tbaa !5
  %54 = add nsw 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 nsw 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 = sdiv 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(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef ptr @ltoa(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 = getelementptr inbounds i8, ptr %4, i64 63
  %6 = icmp slt i64 %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 62
  %9 = sub nsw i64 0, %0
  br label %.lr.ph

10:                                               ; preds = %3
  %11 = icmp eq i64 %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 %50

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

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

19:                                               ; preds = %.lr.ph.split.us
  %20 = add nsw i64 %16, -10
  %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 i64 %16 to i8
  %25 = add i8 %24, 48
  br label %26

26:                                               ; preds = %23, %19
  %storemerge = phi i8 [ %22, %19 ], [ %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, 63
  %30 = icmp ne i64 %17, 0
  %31 = and i1 %29, %30
  br i1 %31, label %.lr.ph.split.us, label %._crit_edge, !llvm.loop !8

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

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

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

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

50:                                               ; preds = %._crit_edge, %12
  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(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 #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