; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/Common/StringToInt.ll (Z24ConvertOctStringToUInt64PKcPS0_)

; 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: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z24ConvertOctStringToUInt64PKcPS0_(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %14

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %12, ptr %13, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %11, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %48, %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = zext i8 %17 to i32
  store i32 %18, ptr %7, align 4, !tbaa !12
  %19 = load i32, ptr %7, align 4, !tbaa !12
  %20 = icmp ult i32 %19, 48
  br i1 %20, label %24, label %21

21:                                               ; preds = %15
  %22 = load i32, ptr %7, align 4, !tbaa !12
  %23 = icmp ugt i32 %22, 55
  br i1 %23, label %24, label %32

24:                                               ; preds = %21, %15
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %30

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

30:                                               ; preds = %27, %24
  %31 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %31, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %45

32:                                               ; preds = %21
  %33 = load i64, ptr %6, align 8, !tbaa !9
  %34 = and i64 %33, -2305843009213693952
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %32
  store i64 0, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %45

37:                                               ; preds = %32
  %38 = load i64, ptr %6, align 8, !tbaa !9
  %39 = shl i64 %38, 3
  store i64 %39, ptr %6, align 8, !tbaa !9
  %40 = load i32, ptr %7, align 4, !tbaa !12
  %41 = sub i32 %40, 48
  %42 = zext i32 %41 to i64
  %43 = load i64, ptr %6, align 8, !tbaa !9
  %44 = or i64 %43, %42
  store i64 %44, ptr %6, align 8, !tbaa !9
  store i32 0, ptr %8, align 4
  br label %45

45:                                               ; preds = %37, %36, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  %46 = load i32, ptr %8, align 4
  switch i32 %46, label %51 [
    i32 0, label %47
  ]

47:                                               ; preds = %45
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i32 1
  store ptr %50, ptr %4, align 8, !tbaa !5
  br label %15, !llvm.loop !14

51:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %52 = load i64, ptr %3, align 8
  ret i64 %52
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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: mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_Z24ConvertOctStringToUInt64PKcPS0_(ptr noundef %0, ptr noundef writeonly %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %4, label %3

3:                                                ; preds = %2
  store ptr %0, ptr %1, align 8, !tbaa !5
  br label %4

4:                                                ; preds = %3, %2
  %5 = load i8, ptr %0, align 1, !tbaa !9
  %6 = add i8 %5, -56
  %or.cond31 = icmp ult i8 %6, -8
  br i1 %or.cond31, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %9, %4
  %.020.lcssa = phi ptr [ %0, %4 ], [ %14, %9 ]
  %.018.lcssa = phi i64 [ 0, %4 ], [ %13, %9 ]
  br i1 %.not, label %.loopexit, label %7

7:                                                ; preds = %._crit_edge
  store ptr %.020.lcssa, ptr %1, align 8, !tbaa !5
  br label %.loopexit

.lr.ph:                                           ; preds = %4, %9
  %8 = phi i8 [ %15, %9 ], [ %5, %4 ]
  %.01833 = phi i64 [ %13, %9 ], [ 0, %4 ]
  %.02032 = phi ptr [ %14, %9 ], [ %0, %4 ]
  %.not24 = icmp ult i64 %.01833, 2305843009213693952
  br i1 %.not24, label %9, label %.loopexit

9:                                                ; preds = %.lr.ph
  %10 = shl nuw i64 %.01833, 3
  %11 = and i8 %8, 7
  %12 = zext nneg i8 %11 to i64
  %13 = or disjoint i64 %10, %12
  %14 = getelementptr inbounds i8, ptr %.02032, i64 1
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = add i8 %15, -56
  %or.cond = icmp ult i8 %16, -8
  br i1 %or.cond, label %._crit_edge, label %.lr.ph, !llvm.loop !10

.loopexit:                                        ; preds = %.lr.ph, %7, %._crit_edge
  %.1.ph = phi i64 [ %.018.lcssa, %._crit_edge ], [ %.018.lcssa, %7 ], [ 0, %.lr.ph ]
  ret i64 %.1.ph
}

attributes #0 = { mustprogress 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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