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

; 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 i32 @_Z24ConvertOctStringToUInt32PKcPS0_(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %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 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %47, %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 !9
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = icmp ult i32 %19, 48
  br i1 %20, label %24, label %21

21:                                               ; preds = %15
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %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 i32, ptr %6, align 4, !tbaa !9
  store i32 %31, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %44

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

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

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

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

46:                                               ; preds = %44
  br label %47

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

50:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %51 = load i32, ptr %3, align 4
  ret i32 %51
}

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 = !{!"int", !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: mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z24ConvertOctStringToUInt32PKcPS0_(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 = %8, %4
  %.020.lcssa = phi ptr [ %0, %4 ], [ %13, %8 ]
  %.018.lcssa = phi i32 [ 0, %4 ], [ %12, %8 ]
  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, %8
  %.in = phi i8 [ %14, %8 ], [ %5, %4 ]
  %.01833 = phi i32 [ %12, %8 ], [ 0, %4 ]
  %.02032 = phi ptr [ %13, %8 ], [ %0, %4 ]
  %.not24 = icmp ult i32 %.01833, 536870912
  br i1 %.not24, label %8, label %.loopexit

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

.loopexit:                                        ; preds = %.lr.ph, %7, %._crit_edge
  %.1.ph = phi i32 [ %.018.lcssa, %._crit_edge ], [ %.018.lcssa, %7 ], [ 0, %.lr.ph ]
  ret i32 %.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