; LLVM IR from devicehive/esp8266-firmware :: firmware-src/sources (dhutils)

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

10:                                               ; preds = %40, %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load i32, ptr %8, align 4, !tbaa !9
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds i8, ptr %11, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !11
  %16 = sext i8 %15 to i32
  %17 = sub nsw i32 %16, 48
  %18 = trunc i32 %17 to i8
  store i8 %18, ptr %6, align 1, !tbaa !11
  %19 = zext i8 %18 to i32
  %20 = icmp slt i32 %19, 10
  br i1 %20, label %21, label %41

21:                                               ; preds = %10
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = add i32 %22, 1
  store i32 %23, ptr %8, align 4, !tbaa !9
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = icmp ult i32 %24, 429496729
  br i1 %25, label %33, label %26

26:                                               ; preds = %21
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = icmp eq i32 %27, 429496729
  br i1 %28, label %29, label %39

29:                                               ; preds = %26
  %30 = load i8, ptr %6, align 1, !tbaa !11
  %31 = zext i8 %30 to i32
  %32 = icmp ule i32 %31, 5
  br i1 %32, label %33, label %39

33:                                               ; preds = %29, %21
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = mul i32 %34, 10
  %36 = load i8, ptr %6, align 1, !tbaa !11
  %37 = zext i8 %36 to i32
  %38 = add i32 %35, %37
  store i32 %38, ptr %7, align 4, !tbaa !9
  br label %40

39:                                               ; preds = %29, %26
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %49

40:                                               ; preds = %33
  br label %10, !llvm.loop !12

41:                                               ; preds = %10
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %47

44:                                               ; preds = %41
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %45, ptr %46, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %44, %41
  %48 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %48, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %49

49:                                               ; preds = %47, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  %50 = load i32, ptr %3, align 4
  ret i32 %50
}

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 = !{!"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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local i32 @strToUInt(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = load i8, ptr %0, align 1, !tbaa !5
  %4 = add i8 %3, -48
  %5 = icmp ult i8 %4, 10
  br i1 %5, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %2, %13
  %6 = phi i8 [ %19, %13 ], [ %4, %2 ]
  %.020 = phi i32 [ %8, %13 ], [ 0, %2 ]
  %.01419 = phi i32 [ %15, %13 ], [ 0, %2 ]
  %7 = zext nneg i8 %6 to i32
  %8 = add i32 %.020, 1
  %9 = icmp ult i32 %.01419, 429496729
  br i1 %9, label %13, label %10

10:                                               ; preds = %.lr.ph
  %11 = icmp eq i32 %.01419, 429496729
  %12 = icmp ult i8 %6, 6
  %or.cond = and i1 %11, %12
  br i1 %or.cond, label %13, label %.loopexit

13:                                               ; preds = %10, %.lr.ph
  %14 = mul nuw i32 %.01419, 10
  %15 = add i32 %14, %7
  %16 = zext i32 %8 to i64
  %17 = getelementptr inbounds i8, ptr %0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = add i8 %18, -48
  %20 = icmp ult i8 %19, 10
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %13
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %.loopexit, label %21

21:                                               ; preds = %._crit_edge
  store i32 %15, ptr %1, align 4, !tbaa !10
  br label %.loopexit

.loopexit:                                        ; preds = %10, %2, %._crit_edge, %21
  %.015 = phi i32 [ %8, %21 ], [ 0, %._crit_edge ], [ 0, %2 ], [ 0, %10 ]
  ret i32 %.015
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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 = !{!"int", !6, i64 0}


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