; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/NetworkPkg/UefiPxeBcDxe_ (PxeBcUniHexToUint8)

; 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: nounwind uwtable
define dso_local i64 @PxeBcUniHexToUint8(ptr noundef %0, i16 noundef zeroext %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  %6 = load i16, ptr %5, align 2, !tbaa !9
  %7 = zext i16 %6 to i32
  %8 = icmp sge i32 %7, 48
  br i1 %8, label %9, label %19

9:                                                ; preds = %2
  %10 = load i16, ptr %5, align 2, !tbaa !9
  %11 = zext i16 %10 to i32
  %12 = icmp sle i32 %11, 57
  br i1 %12, label %13, label %19

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

19:                                               ; preds = %9, %2
  %20 = load i16, ptr %5, align 2, !tbaa !9
  %21 = zext i16 %20 to i32
  %22 = icmp sge i32 %21, 65
  br i1 %22, label %23, label %34

23:                                               ; preds = %19
  %24 = load i16, ptr %5, align 2, !tbaa !9
  %25 = zext i16 %24 to i32
  %26 = icmp sle i32 %25, 70
  br i1 %26, label %27, label %34

27:                                               ; preds = %23
  %28 = load i16, ptr %5, align 2, !tbaa !9
  %29 = zext i16 %28 to i32
  %30 = sub nsw i32 %29, 65
  %31 = add nsw i32 %30, 10
  %32 = trunc i32 %31 to i8
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  store i8 %32, ptr %33, align 1, !tbaa !11
  store i64 0, ptr %3, align 8
  br label %50

34:                                               ; preds = %23, %19
  %35 = load i16, ptr %5, align 2, !tbaa !9
  %36 = zext i16 %35 to i32
  %37 = icmp sge i32 %36, 97
  br i1 %37, label %38, label %49

38:                                               ; preds = %34
  %39 = load i16, ptr %5, align 2, !tbaa !9
  %40 = zext i16 %39 to i32
  %41 = icmp sle i32 %40, 102
  br i1 %41, label %42, label %49

42:                                               ; preds = %38
  %43 = load i16, ptr %5, align 2, !tbaa !9
  %44 = zext i16 %43 to i32
  %45 = sub nsw i32 %44, 97
  %46 = add nsw i32 %45, 10
  %47 = trunc i32 %46 to i8
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  store i8 %47, ptr %48, align 1, !tbaa !11
  store i64 0, ptr %3, align 8
  br label %50

49:                                               ; preds = %38, %34
  store i64 -9223372036854775806, ptr %3, align 8
  br label %50

50:                                               ; preds = %49, %42, %27, %13
  %51 = load i64, ptr %3, align 8
  ret i64 %51
}

attributes #0 = { 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" }

!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 = !{!"short", !7, i64 0}
!11 = !{!7, !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 nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local range(i64 -9223372036854775806, 1) i64 @PxeBcUniHexToUint8(ptr nocapture noundef writeonly %0, i16 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = add i16 %1, -48
  %or.cond = icmp ult i16 %3, 10
  br i1 %or.cond, label %.sink.split, label %4

4:                                                ; preds = %2
  %5 = add i16 %1, -65
  %or.cond5 = icmp ult i16 %5, 6
  br i1 %or.cond5, label %.sink.split, label %6

6:                                                ; preds = %4
  %7 = add i16 %1, -97
  %or.cond8 = icmp ult i16 %7, 6
  br i1 %or.cond8, label %.sink.split, label %10

.sink.split:                                      ; preds = %6, %4, %2
  %.sink22 = phi i8 [ -48, %2 ], [ -55, %4 ], [ -87, %6 ]
  %8 = trunc nuw i16 %1 to i8
  %9 = add nsw i8 %.sink22, %8
  store i8 %9, ptr %0, align 1, !tbaa !5
  br label %10

10:                                               ; preds = %.sink.split, %6
  %.0 = phi i64 [ -9223372036854775806, %6 ], [ 0, %.sink.split ]
  ret i64 %.0
}

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


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