; LLVM IR from wichue/nethello :: src/base/util.ll (ZN3chw8HextoIntEh)

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

9:                                                ; preds = %1
  %10 = load i8, ptr %3, align 1, !tbaa !5
  %11 = zext i8 %10 to i32
  %12 = icmp sge i32 57, %11
  br i1 %12, label %13, label %18

13:                                               ; preds = %9
  %14 = load i8, ptr %3, align 1, !tbaa !5
  %15 = zext i8 %14 to i32
  %16 = sub nsw i32 %15, 48
  %17 = trunc i32 %16 to i8
  store i8 %17, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %49

18:                                               ; preds = %9, %1
  %19 = load i8, ptr %3, align 1, !tbaa !5
  %20 = zext i8 %19 to i32
  %21 = icmp sle i32 65, %20
  br i1 %21, label %22, label %32

22:                                               ; preds = %18
  %23 = load i8, ptr %3, align 1, !tbaa !5
  %24 = zext i8 %23 to i32
  %25 = icmp sge i32 70, %24
  br i1 %25, label %26, label %32

26:                                               ; preds = %22
  %27 = load i8, ptr %3, align 1, !tbaa !5
  %28 = zext i8 %27 to i32
  %29 = sub nsw i32 %28, 65
  %30 = add nsw i32 %29, 10
  %31 = trunc i32 %30 to i8
  store i8 %31, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %49

32:                                               ; preds = %22, %18
  %33 = load i8, ptr %3, align 1, !tbaa !5
  %34 = zext i8 %33 to i32
  %35 = icmp sle i32 97, %34
  br i1 %35, label %36, label %46

36:                                               ; preds = %32
  %37 = load i8, ptr %3, align 1, !tbaa !5
  %38 = zext i8 %37 to i32
  %39 = icmp sge i32 102, %38
  br i1 %39, label %40, label %46

40:                                               ; preds = %36
  %41 = load i8, ptr %3, align 1, !tbaa !5
  %42 = zext i8 %41 to i32
  %43 = sub nsw i32 %42, 97
  %44 = add nsw i32 %43, 10
  %45 = trunc i32 %44 to i8
  store i8 %45, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %49

46:                                               ; preds = %36, %32
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  store i8 0, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %49

49:                                               ; preds = %48, %40, %26, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %50 = load i8, ptr %2, align 1
  ret i8 %50
}

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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, 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 nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef zeroext range(i8 0, 16) i8 @_ZN3chw8HextoIntEh(i8 noundef zeroext %0) local_unnamed_addr #0 {
  %2 = add i8 %0, -48
  %or.cond = icmp ult i8 %2, 10
  br i1 %or.cond, label %10, label %3

3:                                                ; preds = %1
  %4 = add i8 %0, -65
  %or.cond5 = icmp ult i8 %4, 6
  br i1 %or.cond5, label %5, label %7

5:                                                ; preds = %3
  %6 = add nsw i8 %0, -55
  br label %10

7:                                                ; preds = %3
  %8 = add i8 %0, -97
  %or.cond8 = icmp ult i8 %8, 6
  %9 = add nsw i8 %0, -87
  %spec.select = select i1 %or.cond8, i8 %9, i8 0
  br label %10

10:                                               ; preds = %1, %7, %5
  %.0 = phi i8 [ %6, %5 ], [ %spec.select, %7 ], [ %2, %1 ]
  ret i8 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(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)"}


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