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

; 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
declare dso_local noundef i32 @_Z21ConvertStringToUInt32PKwPS0_(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z20ConvertStringToInt32PKwPS0_(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %15

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

15:                                               ; preds = %12, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %16, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = icmp eq i32 %18, 45
  br i1 %19, label %20, label %23

20:                                               ; preds = %15
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds i32, ptr %21, i32 1
  store ptr %22, ptr %6, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %20, %15
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %23
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %61

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call noundef i32 @_Z21ConvertStringToUInt32PKwPS0_(ptr noundef %29, ptr noundef %8) #2
  store i32 %30, ptr %9, align 4, !tbaa !11
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = icmp eq i32 %32, 45
  br i1 %33, label %34, label %39

34:                                               ; preds = %28
  %35 = load i32, ptr %9, align 4, !tbaa !11
  %36 = icmp ugt i32 %35, -2147483648
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %60

38:                                               ; preds = %34
  br label %45

39:                                               ; preds = %28
  %40 = load i32, ptr %9, align 4, !tbaa !11
  %41 = and i32 %40, -2147483648
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %39
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %60

44:                                               ; preds = %39
  br label %45

45:                                               ; preds = %44, %38
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %51

48:                                               ; preds = %45
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %49, ptr %50, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %48, %45
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = icmp eq i32 %53, 45
  br i1 %54, label %55, label %58

55:                                               ; preds = %51
  %56 = load i32, ptr %9, align 4, !tbaa !11
  %57 = sub nsw i32 0, %56
  store i32 %57, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %60

58:                                               ; preds = %51
  %59 = load i32, ptr %9, align 4, !tbaa !11
  store i32 %59, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %60

60:                                               ; preds = %58, %55, %43, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %61

61:                                               ; preds = %60, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %62 = load i32, ptr %3, align 4
  ret i32 %62
}

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 = !{!"wchar_t", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


; 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 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: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z21ConvertStringToUInt32PKwPS0_(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z20ConvertStringToInt32PKwPS0_(ptr noundef %0, ptr noundef writeonly %1) local_unnamed_addr #1 {
  %3 = alloca ptr, align 8
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %5, label %4

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

5:                                                ; preds = %4, %2
  %6 = load i32, ptr %0, align 4, !tbaa !9
  %7 = icmp eq i32 %6, 45
  %spec.select.idx = select i1 %7, i64 4, i64 0
  %spec.select = getelementptr inbounds i8, ptr %0, i64 %spec.select.idx
  %8 = load i32, ptr %spec.select, align 4, !tbaa !9
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %23, label %10

10:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #2
  %11 = call noundef i32 @_Z21ConvertStringToUInt32PKwPS0_(ptr noundef nonnull %spec.select, ptr noundef nonnull %3) #2
  %12 = load i32, ptr %0, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 45
  br i1 %13, label %14, label %16

14:                                               ; preds = %10
  %15 = icmp ugt i32 %11, -2147483648
  br i1 %15, label %22, label %17

16:                                               ; preds = %10
  %.not19 = icmp sgt i32 %11, -1
  br i1 %.not19, label %17, label %22

17:                                               ; preds = %16, %14
  br i1 %.not, label %20, label %18

18:                                               ; preds = %17
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %19, ptr %1, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %18, %17
  %21 = sub nsw i32 0, %11
  %spec.select20 = select i1 %13, i32 %21, i32 %11
  br label %22

22:                                               ; preds = %20, %16, %14
  %.0 = phi i32 [ 0, %14 ], [ 0, %16 ], [ %spec.select20, %20 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #2
  br label %23

23:                                               ; preds = %5, %22
  %.1 = phi i32 [ %.0, %22 ], [ 0, %5 ]
  ret i32 %.1
}

attributes #0 = { mustprogress 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 = !{!"wchar_t", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass