; LLVM IR from asllop/AppOS :: app (utils)

; 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 [72 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @itoa(i64 noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i8, align 1
  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) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %13 = load i32, ptr %7, align 4, !tbaa !11
  %14 = icmp slt i32 %13, 2
  br i1 %14, label %18, label %15

15:                                               ; preds = %3
  %16 = load i32, ptr %7, align 4, !tbaa !11
  %17 = icmp sgt i32 %16, 36
  br i1 %17, label %18, label %21

18:                                               ; preds = %15, %3
  %19 = load ptr, ptr %6, align 8, !tbaa !9
  store i8 0, ptr %19, align 1, !tbaa !13
  %20 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %20, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %69

21:                                               ; preds = %15
  %22 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %22, ptr %9, align 8, !tbaa !9
  store ptr %22, ptr %8, align 8, !tbaa !9
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = icmp slt i64 %23, 0
  br i1 %24, label %25, label %31

25:                                               ; preds = %21
  %26 = load i32, ptr %7, align 4, !tbaa !11
  %27 = icmp eq i32 %26, 10
  br i1 %27, label %28, label %31

28:                                               ; preds = %25
  %29 = load ptr, ptr %9, align 8, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %29, i32 1
  store ptr %30, ptr %9, align 8, !tbaa !9
  store i8 45, ptr %29, align 1, !tbaa !13
  br label %31

31:                                               ; preds = %28, %25, %21
  %32 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %32, ptr %10, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %47, %31
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = load i32, ptr %7, align 4, !tbaa !11
  %36 = sext i32 %35 to i64
  %37 = srem i64 %34, %36
  %38 = add nsw i64 35, %37
  %39 = getelementptr inbounds [72 x i8], ptr @.str, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !13
  %41 = load ptr, ptr %9, align 8, !tbaa !9
  %42 = getelementptr inbounds i8, ptr %41, i32 1
  store ptr %42, ptr %9, align 8, !tbaa !9
  store i8 %40, ptr %41, align 1, !tbaa !13
  %43 = load i32, ptr %7, align 4, !tbaa !11
  %44 = sext i32 %43 to i64
  %45 = load i64, ptr %5, align 8, !tbaa !5
  %46 = sdiv i64 %45, %44
  store i64 %46, ptr %5, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %33
  %48 = load i64, ptr %5, align 8, !tbaa !5
  %49 = icmp ne i64 %48, 0
  br i1 %49, label %33, label %50, !llvm.loop !14

50:                                               ; preds = %47
  %51 = load ptr, ptr %9, align 8, !tbaa !9
  %52 = getelementptr inbounds i8, ptr %51, i32 -1
  store ptr %52, ptr %9, align 8, !tbaa !9
  store i8 0, ptr %51, align 1, !tbaa !13
  br label %53

53:                                               ; preds = %57, %50
  %54 = load ptr, ptr %10, align 8, !tbaa !9
  %55 = load ptr, ptr %9, align 8, !tbaa !9
  %56 = icmp ult ptr %54, %55
  br i1 %56, label %57, label %67

57:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #2
  %58 = load ptr, ptr %10, align 8, !tbaa !9
  %59 = load i8, ptr %58, align 1, !tbaa !13
  store i8 %59, ptr %12, align 1, !tbaa !13
  %60 = load ptr, ptr %9, align 8, !tbaa !9
  %61 = load i8, ptr %60, align 1, !tbaa !13
  %62 = load ptr, ptr %10, align 8, !tbaa !9
  %63 = getelementptr inbounds i8, ptr %62, i32 1
  store ptr %63, ptr %10, align 8, !tbaa !9
  store i8 %61, ptr %62, align 1, !tbaa !13
  %64 = load i8, ptr %12, align 1, !tbaa !13
  %65 = load ptr, ptr %9, align 8, !tbaa !9
  %66 = getelementptr inbounds i8, ptr %65, i32 -1
  store ptr %66, ptr %9, align 8, !tbaa !9
  store i8 %64, ptr %65, align 1, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #2
  br label %53, !llvm.loop !16

67:                                               ; preds = %53
  %68 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %68, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %69

69:                                               ; preds = %67, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %70 = load ptr, ptr %4, align 8
  ret ptr %70
}

; 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 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 = { 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 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"}
!16 = distinct !{!16, !15}


; 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 [72 x i8], align 1

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef ptr @itoa(i64 noundef %0, ptr noundef returned %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = add i32 %2, -37
  %or.cond = icmp ult i32 %4, -35
  br i1 %or.cond, label %5, label %6

5:                                                ; preds = %3
  store i8 0, ptr %1, align 1, !tbaa !5
  br label %.loopexit

6:                                                ; preds = %3
  %7 = icmp slt i64 %0, 0
  %8 = icmp eq i32 %2, 10
  %or.cond3 = and i1 %7, %8
  br i1 %or.cond3, label %9, label %11

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 45, ptr %1, align 1, !tbaa !5
  br label %11

11:                                               ; preds = %9, %6
  %.028 = phi ptr [ %10, %9 ], [ %1, %6 ]
  %12 = zext nneg i32 %2 to i64
  br label %13

13:                                               ; preds = %13, %11
  %.029 = phi i64 [ %0, %11 ], [ %19, %13 ]
  %.1 = phi ptr [ %.028, %11 ], [ %18, %13 ]
  %14 = srem i64 %.029, %12
  %15 = add nsw i64 %14, 35
  %16 = getelementptr inbounds [72 x i8], ptr @.str, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.1, i64 1
  store i8 %17, ptr %.1, align 1, !tbaa !5
  %19 = sdiv i64 %.029, %12
  %.not = icmp eq i64 %19, 0
  br i1 %.not, label %20, label %13, !llvm.loop !8

20:                                               ; preds = %13
  store i8 0, ptr %18, align 1, !tbaa !5
  %21 = icmp ult ptr %.028, %.1
  br i1 %21, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %20, %.lr.ph
  %.02731 = phi ptr [ %24, %.lr.ph ], [ %.028, %20 ]
  %.230 = phi ptr [ %25, %.lr.ph ], [ %.1, %20 ]
  %22 = load i8, ptr %.02731, align 1, !tbaa !5
  %23 = load i8, ptr %.230, align 1, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %.02731, i64 1
  store i8 %23, ptr %.02731, align 1, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %.230, i64 -1
  store i8 %22, ptr %.230, align 1, !tbaa !5
  %26 = icmp ult ptr %24, %25
  br i1 %26, label %.lr.ph, label %.loopexit, !llvm.loop !10

.loopexit:                                        ; preds = %.lr.ph, %20, %5
  ret ptr %1
}

attributes #0 = { nofree norecurse nosync 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" }

!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"}
!10 = distinct !{!10, !9}


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