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

; 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 i64 @xdl_atol(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %8, ptr %7, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %22, %2
  %10 = load ptr, ptr %7, align 8, !tbaa !5
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = sext i8 %11 to i32
  %13 = icmp sge i32 %12, 48
  br i1 %13, label %14, label %19

14:                                               ; preds = %9
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = sext i8 %16 to i32
  %18 = icmp sle i32 %17, 57
  br label %19

19:                                               ; preds = %14, %9
  %20 = phi i1 [ false, %9 ], [ %18, %14 ]
  br i1 %20, label %21, label %25

21:                                               ; preds = %19
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i32 1
  store ptr %24, ptr %7, align 8, !tbaa !5
  br label %9, !llvm.loop !10

25:                                               ; preds = %19
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %31

28:                                               ; preds = %25
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %29, ptr %30, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %28, %25
  store i64 0, ptr %5, align 8, !tbaa !12
  store i64 1, ptr %6, align 8, !tbaa !12
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i32 -1
  store ptr %33, ptr %7, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %48, %31
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = icmp uge ptr %35, %36
  br i1 %37, label %38, label %53

38:                                               ; preds = %34
  %39 = load i64, ptr %6, align 8, !tbaa !12
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load i8, ptr %40, align 1, !tbaa !9
  %42 = sext i8 %41 to i32
  %43 = sub nsw i32 %42, 48
  %44 = sext i32 %43 to i64
  %45 = mul nsw i64 %39, %44
  %46 = load i64, ptr %5, align 8, !tbaa !12
  %47 = add nsw i64 %46, %45
  store i64 %47, ptr %5, align 8, !tbaa !12
  br label %48

48:                                               ; preds = %38
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i32 -1
  store ptr %50, ptr %7, align 8, !tbaa !5
  %51 = load i64, ptr %6, align 8, !tbaa !12
  %52 = mul nsw i64 %51, 10
  store i64 %52, ptr %6, align 8, !tbaa !12
  br label %34, !llvm.loop !14

53:                                               ; preds = %34
  %54 = load i64, ptr %5, align 8, !tbaa !12
  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
  ret i64 %54
}

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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = distinct !{!14, !11}


; 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(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local i64 @xdl_atol(ptr noundef %0, ptr noundef writeonly %1) local_unnamed_addr #0 {
  br label %3

3:                                                ; preds = %3, %2
  %.0 = phi ptr [ %0, %2 ], [ %6, %3 ]
  %4 = load i8, ptr %.0, align 1, !tbaa !5
  %5 = add i8 %4, -48
  %or.cond = icmp ult i8 %5, 10
  %6 = getelementptr inbounds i8, ptr %.0, i64 1
  br i1 %or.cond, label %3, label %.critedge, !llvm.loop !8

.critedge:                                        ; preds = %3
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %8, label %7

7:                                                ; preds = %.critedge
  store ptr %.0, ptr %1, align 8, !tbaa !10
  br label %8

8:                                                ; preds = %7, %.critedge
  %.120 = getelementptr inbounds i8, ptr %.0, i64 -1
  %.not1921 = icmp ult ptr %.120, %0
  br i1 %.not1921, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8, %.lr.ph
  %.124 = phi ptr [ %.1, %.lr.ph ], [ %.120, %8 ]
  %.01523 = phi i64 [ %14, %.lr.ph ], [ 1, %8 ]
  %.01622 = phi i64 [ %13, %.lr.ph ], [ 0, %8 ]
  %9 = load i8, ptr %.124, align 1, !tbaa !5
  %10 = sext i8 %9 to i64
  %11 = add nsw i64 %10, -48
  %12 = mul nsw i64 %11, %.01523
  %13 = add nsw i64 %12, %.01622
  %14 = mul nuw nsw i64 %.01523, 10
  %.1 = getelementptr inbounds i8, ptr %.124, i64 -1
  %.not19 = icmp ult ptr %.1, %0
  br i1 %.not19, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %8
  %.016.lcssa = phi i64 [ 0, %8 ], [ %13, %.lr.ph ]
  ret i64 %.016.lcssa
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: 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 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = distinct !{!12, !9}


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