; LLVM IR from FrancesoM/Bisc8FX :: sdk_projects/bisc8_platform/ps7_cortexa9_0/standalone_domain/bsp/ps7_cortexa9_0_ (ConvertCharToNibble)

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

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

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
  %18 = load ptr, ptr %4, align 8, !tbaa !8
  store i8 %17, ptr %18, align 1, !tbaa !5
  store i32 0, ptr %5, align 4, !tbaa !10
  br label %52

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

23:                                               ; preds = %19
  %24 = load i8, ptr %3, align 1, !tbaa !5
  %25 = zext i8 %24 to i32
  %26 = icmp sle i32 %25, 102
  br i1 %26, label %27, label %34

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

34:                                               ; preds = %23, %19
  %35 = load i8, ptr %3, align 1, !tbaa !5
  %36 = zext i8 %35 to i32
  %37 = icmp sge i32 %36, 65
  br i1 %37, label %38, label %49

38:                                               ; preds = %34
  %39 = load i8, ptr %3, align 1, !tbaa !5
  %40 = zext i8 %39 to i32
  %41 = icmp sle i32 %40, 70
  br i1 %41, label %42, label %49

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

49:                                               ; preds = %38, %34
  store i32 1, ptr %5, align 4, !tbaa !10
  br label %50

50:                                               ; preds = %49, %42
  br label %51

51:                                               ; preds = %50, %27
  br label %52

52:                                               ; preds = %51, %13
  %53 = load i32, ptr %5, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %53
}

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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"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(argmem: write) uwtable
define dso_local range(i32 0, 2) i32 @Xil_ConvertCharToNibble(i8 noundef zeroext %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = add i8 %0, -48
  %or.cond = icmp ult i8 %3, 10
  br i1 %or.cond, label %.sink.split, label %4

4:                                                ; preds = %2
  %5 = add i8 %0, -97
  %or.cond5 = icmp ult i8 %5, 6
  br i1 %or.cond5, label %6, label %8

6:                                                ; preds = %4
  %7 = add nsw i8 %0, -87
  br label %.sink.split

8:                                                ; preds = %4
  %9 = add i8 %0, -65
  %or.cond8 = icmp ult i8 %9, 6
  br i1 %or.cond8, label %10, label %12

10:                                               ; preds = %8
  %11 = add nsw i8 %0, -55
  br label %.sink.split

.sink.split:                                      ; preds = %2, %10, %6
  %.sink = phi i8 [ %7, %6 ], [ %11, %10 ], [ %3, %2 ]
  store i8 %.sink, ptr %1, align 1, !tbaa !5
  br label %12

12:                                               ; preds = %.sink.split, %8
  %.0 = phi i32 [ 1, %8 ], [ 0, %.sink.split ]
  ret i32 %.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,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass