; LLVM IR from adventure-db/adventure :: lib/sds (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: nounwind uwtable
declare dso_local ptr @sdsnewlen(ptr noundef, i64 noundef) #0

; 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

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

8:                                                ; preds = %1
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = sub nsw i64 0, %9
  br label %13

11:                                               ; preds = %1
  %12 = load i64, ptr %2, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %11, %8
  %14 = phi i64 [ %10, %8 ], [ %12, %11 ]
  store i64 %14, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 0
  %16 = getelementptr inbounds i8, ptr %15, i64 31
  store ptr %16, ptr %4, align 8, !tbaa !9
  br label %17

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

26:                                               ; preds = %17
  %27 = load i64, ptr %5, align 8, !tbaa !5
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %17, label %29, !llvm.loop !12

29:                                               ; preds = %26
  %30 = load i64, ptr %2, align 8, !tbaa !5
  %31 = icmp slt i64 %30, 0
  br i1 %31, label %32, label %35

32:                                               ; preds = %29
  %33 = load ptr, ptr %4, align 8, !tbaa !9
  %34 = getelementptr inbounds i8, ptr %33, i32 -1
  store ptr %34, ptr %4, align 8, !tbaa !9
  store i8 45, ptr %33, align 1, !tbaa !11
  br label %35

35:                                               ; preds = %32, %29
  %36 = load ptr, ptr %4, align 8, !tbaa !9
  %37 = getelementptr inbounds i8, ptr %36, i32 1
  store ptr %37, ptr %4, align 8, !tbaa !9
  %38 = load ptr, ptr %4, align 8, !tbaa !9
  %39 = load ptr, ptr %4, align 8, !tbaa !9
  %40 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 0
  %41 = ptrtoint ptr %39 to i64
  %42 = ptrtoint ptr %40 to i64
  %43 = sub i64 %41, %42
  %44 = sub nsw i64 32, %43
  %45 = call ptr @sdsnewlen(ptr noundef %38, i64 noundef %44)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr %3) #2
  ret ptr %45
}

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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

; Function Attrs: nounwind uwtable
declare dso_local ptr @sdsnewlen(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @sdsfromlonglong(i64 noundef %0) local_unnamed_addr #0 {
  %2 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #3
  %3 = tail call i64 @llvm.abs.i64(i64 %0, i1 true)
  %4 = getelementptr inbounds i8, ptr %2, i64 31
  br label %5

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

11:                                               ; preds = %5
  %12 = icmp slt i64 %0, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %11
  store i8 45, ptr %9, align 1, !tbaa !5
  br label %14

14:                                               ; preds = %13, %11
  %15 = phi i64 [ -2, %13 ], [ -1, %11 ]
  %16 = getelementptr inbounds i8, ptr %.011, i64 %15
  %17 = getelementptr inbounds i8, ptr %16, i64 1
  %18 = ptrtoint ptr %17 to i64
  %19 = ptrtoint ptr %2 to i64
  %.neg = add i64 %19, 32
  %20 = sub i64 %.neg, %18
  %21 = call ptr @sdsnewlen(ptr noundef nonnull %17, i64 noundef %20)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #3
  ret ptr %21
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.abs.i64(i64, i1 immarg) #2

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass