; LLVM IR from artagnon/phoenixfs :: xdiff (xutils)

; 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.1 = external hidden unnamed_addr constant [11 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 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 @xdl_num_out(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [32 x i8], align 16
  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 8, ptr %6) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %8, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %7) #2
  %9 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 0
  %10 = getelementptr inbounds i8, ptr %9, i64 32
  %11 = getelementptr inbounds i8, ptr %10, i64 -1
  store ptr %11, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 0, ptr %12, align 1, !tbaa !11
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = icmp slt i64 %13, 0
  br i1 %14, label %15, label %20

15:                                               ; preds = %2
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i32 -1
  store ptr %17, ptr %5, align 8, !tbaa !5
  store i8 45, ptr %17, align 1, !tbaa !11
  %18 = load i64, ptr %4, align 8, !tbaa !9
  %19 = sub nsw i64 0, %18
  store i64 %19, ptr %4, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %15, %2
  br label %21

21:                                               ; preds = %37, %20
  %22 = load i64, ptr %4, align 8, !tbaa !9
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %24, label %28

24:                                               ; preds = %21
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 0
  %27 = icmp ugt ptr %25, %26
  br label %28

28:                                               ; preds = %24, %21
  %29 = phi i1 [ false, %21 ], [ %27, %24 ]
  br i1 %29, label %30, label %40

30:                                               ; preds = %28
  %31 = load i64, ptr %4, align 8, !tbaa !9
  %32 = srem i64 %31, 10
  %33 = getelementptr inbounds [11 x i8], ptr @.str.1, i64 0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !11
  %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 %34, ptr %36, align 1, !tbaa !11
  br label %37

37:                                               ; preds = %30
  %38 = load i64, ptr %4, align 8, !tbaa !9
  %39 = sdiv i64 %38, 10
  store i64 %39, ptr %4, align 8, !tbaa !9
  br label %21, !llvm.loop !12

40:                                               ; preds = %28
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i8, ptr %41, align 1, !tbaa !11
  %43 = icmp ne i8 %42, 0
  br i1 %43, label %44, label %59

44:                                               ; preds = %40
  br label %45

45:                                               ; preds = %53, %44
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i8, ptr %46, align 1, !tbaa !11
  %48 = icmp ne i8 %47, 0
  br i1 %48, label %49, label %58

49:                                               ; preds = %45
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load i8, ptr %50, align 1, !tbaa !11
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  store i8 %51, ptr %52, align 1, !tbaa !11
  br label %53

53:                                               ; preds = %49
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i32 1
  store ptr %55, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i32 1
  store ptr %57, ptr %6, align 8, !tbaa !5
  br label %45, !llvm.loop !14

58:                                               ; preds = %45
  br label %62

59:                                               ; preds = %40
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i32 1
  store ptr %61, ptr %6, align 8, !tbaa !5
  store i8 48, ptr %60, align 1, !tbaa !11
  br label %62

62:                                               ; preds = %59, %58
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  store i8 0, ptr %63, align 1, !tbaa !11
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = ptrtoint ptr %64 to i64
  %67 = ptrtoint ptr %65 to i64
  %68 = sub i64 %66, %67
  %69 = trunc i64 %68 to i32
  call void @llvm.lifetime.end.p0(i64 32, 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
  ret i32 %69
}

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", !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"

@.str.1 = external hidden unnamed_addr constant [11 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nofree norecurse nosync nounwind memory(write, inaccessiblemem: none) uwtable
define dso_local noundef i32 @xdl_num_out(ptr noundef %0, i64 noundef %1) local_unnamed_addr #1 {
  %3 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #2
  %4 = getelementptr inbounds i8, ptr %3, i64 31
  store i8 0, ptr %4, align 1, !tbaa !5
  %5 = icmp slt i64 %1, 0
  br i1 %5, label %.thread, label %8

.thread:                                          ; preds = %2
  %6 = getelementptr inbounds i8, ptr %3, i64 30
  store i8 45, ptr %6, align 2, !tbaa !5
  %7 = sub nsw i64 0, %1
  br label %.lr.ph.preheader

8:                                                ; preds = %2
  %.not31 = icmp eq i64 %1, 0
  br i1 %.not31, label %._crit_edge.thread, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.thread, %8
  %.12028.ph = phi ptr [ %4, %8 ], [ %6, %.thread ]
  %.12227.ph = phi i64 [ %1, %8 ], [ %7, %.thread ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.12028 = phi ptr [ %12, %.lr.ph ], [ %.12028.ph, %.lr.ph.preheader ]
  %.12227 = phi i64 [ %13, %.lr.ph ], [ %.12227.ph, %.lr.ph.preheader ]
  %9 = urem i64 %.12227, 10
  %10 = getelementptr inbounds [11 x i8], ptr @.str.1, i64 0, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %.12028, i64 -1
  store i8 %11, ptr %12, align 1, !tbaa !5
  %13 = udiv i64 %.12227, 10
  %14 = icmp ugt i64 %.12227, 9
  %15 = icmp ugt ptr %12, %3
  %16 = and i1 %14, %15
  br i1 %16, label %.lr.ph, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph
  %.not = icmp eq i8 %11, 0
  br i1 %.not, label %._crit_edge.thread, label %.preheader

.preheader:                                       ; preds = %._crit_edge, %.preheader
  %.030 = phi ptr [ %19, %.preheader ], [ %0, %._crit_edge ]
  %.229 = phi ptr [ %18, %.preheader ], [ %12, %._crit_edge ]
  %17 = phi i8 [ %.pr, %.preheader ], [ %11, %._crit_edge ]
  store i8 %17, ptr %.030, align 1, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.229, i64 1
  %19 = getelementptr inbounds i8, ptr %.030, i64 1
  %.pr = load i8, ptr %18, align 1, !tbaa !5
  %.not26 = icmp eq i8 %.pr, 0
  br i1 %.not26, label %.loopexit, label %.preheader, !llvm.loop !10

._crit_edge.thread:                               ; preds = %8, %._crit_edge
  %20 = getelementptr inbounds i8, ptr %0, i64 1
  store i8 48, ptr %0, align 1, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %._crit_edge.thread
  %.1 = phi ptr [ %20, %._crit_edge.thread ], [ %19, %.preheader ]
  store i8 0, ptr %.1, align 1, !tbaa !5
  %21 = ptrtoint ptr %.1 to i64
  %22 = ptrtoint ptr %0 to i64
  %23 = sub i64 %21, %22
  %24 = trunc i64 %23 to i32
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #2
  ret i32 %24
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree norecurse nosync nounwind memory(write, 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 #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 = distinct !{!10, !9}


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