; LLVM IR from krig/LISP :: komplott (itos)

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

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @intern_string(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @itos(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca [256 x i8], align 16
  %4 = alloca [256 x i8], align 16
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 256, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 256, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %8 = getelementptr inbounds [256 x i8], ptr %3, i64 0, i64 0
  store ptr %8, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %9 = getelementptr inbounds [256 x i8], ptr %4, i64 0, i64 0
  store ptr %9, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %10 = load i64, ptr %2, align 8, !tbaa !5
  store i64 %10, ptr %7, align 8, !tbaa !5
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = icmp slt i64 %11, 0
  br i1 %12, label %13, label %19

13:                                               ; preds = %1
  %14 = load ptr, ptr %5, align 8, !tbaa !9
  %15 = getelementptr inbounds i8, ptr %14, i32 1
  store ptr %15, ptr %5, align 8, !tbaa !9
  store i8 45, ptr %14, align 1, !tbaa !11
  %16 = load i64, ptr %7, align 8, !tbaa !5
  %17 = xor i64 %16, -1
  %18 = add i64 %17, 1
  store i64 %18, ptr %7, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %13, %1
  br label %20

20:                                               ; preds = %31, %19
  %21 = load i64, ptr %7, align 8, !tbaa !5
  %22 = urem i64 %21, 10
  %23 = trunc i64 %22 to i8
  %24 = sext i8 %23 to i32
  %25 = add nsw i32 %24, 48
  %26 = trunc i32 %25 to i8
  %27 = load ptr, ptr %6, align 8, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %27, i32 1
  store ptr %28, ptr %6, align 8, !tbaa !9
  store i8 %26, ptr %27, align 1, !tbaa !11
  %29 = load i64, ptr %7, align 8, !tbaa !5
  %30 = udiv i64 %29, 10
  store i64 %30, ptr %7, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %20
  %32 = load i64, ptr %7, align 8, !tbaa !5
  %33 = icmp ugt i64 %32, 0
  br i1 %33, label %20, label %34, !llvm.loop !12

34:                                               ; preds = %31
  br label %35

35:                                               ; preds = %41, %34
  %36 = load ptr, ptr %6, align 8, !tbaa !9
  %37 = getelementptr inbounds i8, ptr %36, i32 -1
  store ptr %37, ptr %6, align 8, !tbaa !9
  %38 = load i8, ptr %37, align 1, !tbaa !11
  %39 = load ptr, ptr %5, align 8, !tbaa !9
  %40 = getelementptr inbounds i8, ptr %39, i32 1
  store ptr %40, ptr %5, align 8, !tbaa !9
  store i8 %38, ptr %39, align 1, !tbaa !11
  br label %41

41:                                               ; preds = %35
  %42 = load ptr, ptr %6, align 8, !tbaa !9
  %43 = getelementptr inbounds [256 x i8], ptr %4, i64 0, i64 0
  %44 = icmp ne ptr %42, %43
  br i1 %44, label %35, label %45, !llvm.loop !14

45:                                               ; preds = %41
  %46 = load ptr, ptr %5, align 8, !tbaa !9
  store i8 0, ptr %46, align 1, !tbaa !11
  %47 = getelementptr inbounds [256 x i8], ptr %3, i64 0, i64 0
  %48 = call ptr @intern_string(ptr noundef %47)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 256, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 256, ptr %3) #2
  ret ptr %48
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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", !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 = distinct !{!14, !13}


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

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @intern_string(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @itos(i64 noundef %0) local_unnamed_addr #1 {
  %2 = alloca [256 x i8], align 16
  %3 = alloca [256 x i8], align 16
  %4 = ptrtoint ptr %3 to i64
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %2) #2
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %3) #2
  %5 = icmp slt i64 %0, 0
  br i1 %5, label %6, label %9

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %2, i64 1
  store i8 45, ptr %2, align 16, !tbaa !5
  %8 = sub i64 0, %0
  br label %9

9:                                                ; preds = %6, %1
  %.013 = phi ptr [ %7, %6 ], [ %2, %1 ]
  %.0 = phi i64 [ %8, %6 ], [ %0, %1 ]
  br label %10

10:                                               ; preds = %10, %9
  %indvar = phi i64 [ %indvar.next, %10 ], [ 0, %9 ]
  %.011 = phi ptr [ %14, %10 ], [ %3, %9 ]
  %.1 = phi i64 [ %15, %10 ], [ %.0, %9 ]
  %11 = urem i64 %.1, 10
  %12 = trunc nuw nsw i64 %11 to i8
  %13 = or disjoint i8 %12, 48
  %14 = getelementptr i8, ptr %.011, i64 1
  store i8 %13, ptr %.011, align 1, !tbaa !5
  %15 = udiv i64 %.1, 10
  %.not = icmp ult i64 %.1, 10
  %indvar.next = add i64 %indvar, 1
  br i1 %.not, label %.preheader.preheader, label %10, !llvm.loop !8

.preheader.preheader:                             ; preds = %10
  %16 = add i64 %indvar, 1
  %min.iters.check = icmp ult i64 %16, 32
  br i1 %min.iters.check, label %.preheader.preheader31, label %vector.memcheck

vector.memcheck:                                  ; preds = %.preheader.preheader
  %17 = add i64 %indvar, 1
  %scevgep = getelementptr i8, ptr %.013, i64 %17
  %bound0 = icmp ult ptr %.013, %14
  %bound1 = icmp ult ptr %3, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %.preheader.preheader31, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %16, -32
  %ind.end = getelementptr i8, ptr %.013, i64 %n.vec
  %18 = sub i64 0, %n.vec
  %ind.end24 = getelementptr i8, ptr %14, i64 %18
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %next.gep = getelementptr i8, ptr %.013, i64 %index
  %offset.idx = sub i64 0, %index
  %next.gep27 = getelementptr i8, ptr %14, i64 %offset.idx
  %19 = getelementptr inbounds i8, ptr %next.gep27, i64 -16
  %20 = getelementptr inbounds i8, ptr %next.gep27, i64 -32
  %wide.load = load <16 x i8>, ptr %19, align 1, !tbaa !5, !alias.scope !10
  %reverse = shufflevector <16 x i8> %wide.load, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
  %wide.load29 = load <16 x i8>, ptr %20, align 1, !tbaa !5, !alias.scope !10
  %reverse30 = shufflevector <16 x i8> %wide.load29, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
  %21 = getelementptr i8, ptr %next.gep, i64 16
  store <16 x i8> %reverse, ptr %next.gep, align 1, !tbaa !5, !alias.scope !13, !noalias !10
  store <16 x i8> %reverse30, ptr %21, align 1, !tbaa !5, !alias.scope !13, !noalias !10
  %index.next = add nuw i64 %index, 32
  %22 = icmp eq i64 %index.next, %n.vec
  br i1 %22, label %middle.block, label %vector.body, !llvm.loop !15

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %16, %n.vec
  br i1 %cmp.n, label %.loopexit, label %.preheader.preheader31

.preheader.preheader31:                           ; preds = %middle.block, %vector.memcheck, %.preheader.preheader
  %.114.ph = phi ptr [ %.013, %vector.memcheck ], [ %.013, %.preheader.preheader ], [ %ind.end, %middle.block ]
  %.112.ph = phi ptr [ %14, %vector.memcheck ], [ %14, %.preheader.preheader ], [ %ind.end24, %middle.block ]
  %.112.ph34 = ptrtoint ptr %.112.ph to i64
  %xtraiter = and i64 %.112.ph34, 7
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader.prol.loopexit, label %.preheader.prol

.preheader.prol:                                  ; preds = %.preheader.preheader31, %.preheader.prol
  %.114.prol = phi ptr [ %25, %.preheader.prol ], [ %.114.ph, %.preheader.preheader31 ]
  %.112.prol = phi ptr [ %23, %.preheader.prol ], [ %.112.ph, %.preheader.preheader31 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.preheader.prol ], [ 0, %.preheader.preheader31 ]
  %23 = getelementptr inbounds i8, ptr %.112.prol, i64 -1
  %24 = load i8, ptr %23, align 1, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %.114.prol, i64 1
  store i8 %24, ptr %.114.prol, align 1, !tbaa !5
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.preheader.prol.loopexit, label %.preheader.prol, !llvm.loop !18

.preheader.prol.loopexit:                         ; preds = %.preheader.prol, %.preheader.preheader31
  %.lcssa32.unr = phi ptr [ poison, %.preheader.preheader31 ], [ %25, %.preheader.prol ]
  %.114.unr = phi ptr [ %.114.ph, %.preheader.preheader31 ], [ %25, %.preheader.prol ]
  %.112.unr = phi ptr [ %.112.ph, %.preheader.preheader31 ], [ %23, %.preheader.prol ]
  %26 = sub i64 %4, %.112.ph34
  %27 = icmp ugt i64 %26, -8
  br i1 %27, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %.preheader.prol.loopexit, %.preheader
  %.114 = phi ptr [ %51, %.preheader ], [ %.114.unr, %.preheader.prol.loopexit ]
  %.112 = phi ptr [ %49, %.preheader ], [ %.112.unr, %.preheader.prol.loopexit ]
  %28 = getelementptr inbounds i8, ptr %.112, i64 -1
  %29 = load i8, ptr %28, align 1, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %.114, i64 1
  store i8 %29, ptr %.114, align 1, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %.112, i64 -2
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %.114, i64 2
  store i8 %32, ptr %30, align 1, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %.112, i64 -3
  %35 = load i8, ptr %34, align 1, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %.114, i64 3
  store i8 %35, ptr %33, align 1, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %.112, i64 -4
  %38 = load i8, ptr %37, align 1, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %.114, i64 4
  store i8 %38, ptr %36, align 1, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %.112, i64 -5
  %41 = load i8, ptr %40, align 1, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %.114, i64 5
  store i8 %41, ptr %39, align 1, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %.112, i64 -6
  %44 = load i8, ptr %43, align 1, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %.114, i64 6
  store i8 %44, ptr %42, align 1, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %.112, i64 -7
  %47 = load i8, ptr %46, align 1, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %.114, i64 7
  store i8 %47, ptr %45, align 1, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %.112, i64 -8
  %50 = load i8, ptr %49, align 1, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %.114, i64 8
  store i8 %50, ptr %48, align 1, !tbaa !5
  %.not18.7 = icmp eq ptr %49, %3
  br i1 %.not18.7, label %.loopexit, label %.preheader, !llvm.loop !20

.loopexit:                                        ; preds = %.preheader.prol.loopexit, %.preheader, %middle.block
  %.lcssa = phi ptr [ %ind.end, %middle.block ], [ %.lcssa32.unr, %.preheader.prol.loopexit ], [ %51, %.preheader ]
  store i8 0, ptr %.lcssa, align 1, !tbaa !5
  %52 = call ptr @intern_string(ptr noundef nonnull %2)
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %3) #2
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %2) #2
  ret ptr %52
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11}
!11 = distinct !{!11, !12}
!12 = distinct !{!12, !"LVerDomain"}
!13 = !{!14}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !9, !16, !17}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}
!20 = distinct !{!20, !9, !16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopLoadEliminationPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass