; LLVM IR from erwincoumans/tiny-differentiable-simulator :: third_party/crossguid/guid.ll (ZN2xg14hexDigitToCharEc)

; 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: mustprogress nounwind uwtable
define dso_local noundef zeroext i8 @_ZN2xg14hexDigitToCharEc(i8 noundef signext %0) #0 {
  %2 = alloca i8, align 1
  %3 = alloca i8, align 1
  store i8 %0, ptr %3, align 1, !tbaa !5
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %5 = sext i8 %4 to i32
  %6 = icmp sgt i32 %5, 47
  br i1 %6, label %7, label %16

7:                                                ; preds = %1
  %8 = load i8, ptr %3, align 1, !tbaa !5
  %9 = sext i8 %8 to i32
  %10 = icmp slt i32 %9, 58
  br i1 %10, label %11, label %16

11:                                               ; preds = %7
  %12 = load i8, ptr %3, align 1, !tbaa !5
  %13 = sext i8 %12 to i32
  %14 = sub nsw i32 %13, 48
  %15 = trunc i32 %14 to i8
  store i8 %15, ptr %2, align 1
  br label %43

16:                                               ; preds = %7, %1
  %17 = load i8, ptr %3, align 1, !tbaa !5
  %18 = sext i8 %17 to i32
  %19 = icmp sgt i32 %18, 96
  br i1 %19, label %20, label %29

20:                                               ; preds = %16
  %21 = load i8, ptr %3, align 1, !tbaa !5
  %22 = sext i8 %21 to i32
  %23 = icmp slt i32 %22, 103
  br i1 %23, label %24, label %29

24:                                               ; preds = %20
  %25 = load i8, ptr %3, align 1, !tbaa !5
  %26 = sext i8 %25 to i32
  %27 = sub nsw i32 %26, 87
  %28 = trunc i32 %27 to i8
  store i8 %28, ptr %2, align 1
  br label %43

29:                                               ; preds = %20, %16
  %30 = load i8, ptr %3, align 1, !tbaa !5
  %31 = sext i8 %30 to i32
  %32 = icmp sgt i32 %31, 64
  br i1 %32, label %33, label %42

33:                                               ; preds = %29
  %34 = load i8, ptr %3, align 1, !tbaa !5
  %35 = sext i8 %34 to i32
  %36 = icmp slt i32 %35, 71
  br i1 %36, label %37, label %42

37:                                               ; preds = %33
  %38 = load i8, ptr %3, align 1, !tbaa !5
  %39 = sext i8 %38 to i32
  %40 = sub nsw i32 %39, 55
  %41 = trunc i32 %40 to i8
  store i8 %41, ptr %2, align 1
  br label %43

42:                                               ; preds = %33, %29
  store i8 0, ptr %2, align 1
  br label %43

43:                                               ; preds = %42, %37, %24, %11
  %44 = load i8, ptr %2, align 1
  ret i8 %44
}

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

!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"}


; 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 @_ZN2xg14hexDigitToCharEc(i8 noundef signext %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, -97
  %or.cond5 = icmp ult i8 %4, 6
  br i1 %or.cond5, label %5, label %7

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

7:                                                ; preds = %3
  %8 = add i8 %0, -65
  %or.cond8 = icmp ult i8 %8, 6
  %9 = add nsw i8 %0, -55
  %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,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass