; LLVM IR from caryll/otfcc :: dep/extern (sds)

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

11:                                               ; preds = %2
  %12 = load i64, ptr %4, align 8, !tbaa !9
  %13 = sub nsw i64 0, %12
  br label %16

14:                                               ; preds = %2
  %15 = load i64, ptr %4, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %14, %11
  %17 = phi i64 [ %13, %11 ], [ %15, %14 ]
  store i64 %17, ptr %7, align 8, !tbaa !9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %18, ptr %5, align 8, !tbaa !5
  br label %19

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

28:                                               ; preds = %19
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = icmp ne i64 %29, 0
  br i1 %30, label %19, label %31, !llvm.loop !12

31:                                               ; preds = %28
  %32 = load i64, ptr %4, align 8, !tbaa !9
  %33 = icmp slt i64 %32, 0
  br i1 %33, label %34, label %37

34:                                               ; preds = %31
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i32 1
  store ptr %36, ptr %5, align 8, !tbaa !5
  store i8 45, ptr %35, align 1, !tbaa !11
  br label %37

37:                                               ; preds = %34, %31
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = ptrtoint ptr %38 to i64
  %41 = ptrtoint ptr %39 to i64
  %42 = sub i64 %40, %41
  store i64 %42, ptr %8, align 8, !tbaa !14
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 0, ptr %43, align 1, !tbaa !11
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %44, i32 -1
  store ptr %45, ptr %5, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %50, %37
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = icmp ult ptr %47, %48
  br i1 %49, label %50, label %62

50:                                               ; preds = %46
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = load i8, ptr %51, align 1, !tbaa !11
  store i8 %52, ptr %6, align 1, !tbaa !11
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  store i8 %54, ptr %55, align 1, !tbaa !11
  %56 = load i8, ptr %6, align 1, !tbaa !11
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %56, ptr %57, align 1, !tbaa !11
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %58, i32 1
  store ptr %59, ptr %3, align 8, !tbaa !5
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i32 -1
  store ptr %61, ptr %5, align 8, !tbaa !5
  br label %46, !llvm.loop !16

62:                                               ; preds = %46
  %63 = load i64, ptr %8, align 8, !tbaa !14
  %64 = trunc i64 %63 to i32
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i32 %64
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !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}
!16 = distinct !{!16, !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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @sdsll2str(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i64 @llvm.abs.i64(i64 %1, i1 true)
  br label %4

4:                                                ; preds = %4, %2
  %.024 = phi ptr [ %0, %2 ], [ %8, %4 ]
  %.023 = phi i64 [ %3, %2 ], [ %9, %4 ]
  %5 = urem i64 %.023, 10
  %6 = trunc nuw nsw i64 %5 to i8
  %7 = or disjoint i8 %6, 48
  %8 = getelementptr inbounds i8, ptr %.024, i64 1
  store i8 %7, ptr %.024, align 1, !tbaa !5
  %9 = udiv i64 %.023, 10
  %.not = icmp ult i64 %.023, 10
  br i1 %.not, label %10, label %4, !llvm.loop !8

10:                                               ; preds = %4
  %11 = icmp slt i64 %1, 0
  br i1 %11, label %12, label %14

12:                                               ; preds = %10
  %13 = getelementptr inbounds i8, ptr %.024, i64 2
  store i8 45, ptr %8, align 1, !tbaa !5
  br label %14

14:                                               ; preds = %12, %10
  %.1 = phi ptr [ %13, %12 ], [ %8, %10 ]
  store i8 0, ptr %.1, align 1, !tbaa !5
  %.225 = getelementptr inbounds i8, ptr %.1, i64 -1
  %15 = icmp ugt ptr %.225, %0
  br i1 %15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %14, %.lr.ph
  %.227 = phi ptr [ %.2, %.lr.ph ], [ %.225, %14 ]
  %.026 = phi ptr [ %18, %.lr.ph ], [ %0, %14 ]
  %16 = load i8, ptr %.026, align 1, !tbaa !5
  %17 = load i8, ptr %.227, align 1, !tbaa !5
  store i8 %17, ptr %.026, align 1, !tbaa !5
  store i8 %16, ptr %.227, align 1, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.026, i64 1
  %.2 = getelementptr inbounds i8, ptr %.227, i64 -1
  %19 = icmp ult ptr %18, %.2
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph, %14
  %20 = ptrtoint ptr %.1 to i64
  %21 = ptrtoint ptr %0 to i64
  %22 = sub i64 %20, %21
  %23 = trunc i64 %22 to i32
  ret i32 %23
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.abs.i64(i64, i1 immarg) #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" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass