; LLVM IR from quantumlib/Stim :: src/stim/diagram/base64.ll (Z17u6_to_base64_charh)

; 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 signext i8 @_Z17u6_to_base64_charh(i8 noundef zeroext %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 = zext i8 %4 to i32
  %6 = icmp slt i32 %5, 26
  br i1 %6, label %7, label %12

7:                                                ; preds = %1
  %8 = load i8, ptr %3, align 1, !tbaa !5
  %9 = zext i8 %8 to i32
  %10 = add nsw i32 65, %9
  %11 = trunc i32 %10 to i8
  store i8 %11, ptr %2, align 1
  br label %38

12:                                               ; preds = %1
  %13 = load i8, ptr %3, align 1, !tbaa !5
  %14 = zext i8 %13 to i32
  %15 = icmp slt i32 %14, 52
  br i1 %15, label %16, label %22

16:                                               ; preds = %12
  %17 = load i8, ptr %3, align 1, !tbaa !5
  %18 = zext i8 %17 to i32
  %19 = add nsw i32 97, %18
  %20 = sub nsw i32 %19, 26
  %21 = trunc i32 %20 to i8
  store i8 %21, ptr %2, align 1
  br label %38

22:                                               ; preds = %12
  %23 = load i8, ptr %3, align 1, !tbaa !5
  %24 = zext i8 %23 to i32
  %25 = icmp slt i32 %24, 62
  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 = add nsw i32 48, %28
  %30 = sub nsw i32 %29, 52
  %31 = trunc i32 %30 to i8
  store i8 %31, ptr %2, align 1
  br label %38

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

36:                                               ; preds = %32
  store i8 43, ptr %2, align 1
  br label %38

37:                                               ; preds = %32
  store i8 47, ptr %2, align 1
  br label %38

38:                                               ; preds = %37, %36, %26, %16, %7
  %39 = load i8, ptr %2, align 1
  ret i8 %39
}

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 signext range(i8 43, 123) i8 @_Z17u6_to_base64_charh(i8 noundef zeroext %0) local_unnamed_addr #0 {
  %2 = icmp ult i8 %0, 26
  br i1 %2, label %3, label %4

3:                                                ; preds = %1
  %narrow = add nuw nsw i8 %0, 65
  br label %14

4:                                                ; preds = %1
  %5 = icmp ult i8 %0, 52
  br i1 %5, label %6, label %8

6:                                                ; preds = %4
  %7 = add nuw nsw i8 %0, 71
  br label %14

8:                                                ; preds = %4
  %9 = icmp ult i8 %0, 62
  br i1 %9, label %10, label %12

10:                                               ; preds = %8
  %11 = add nsw i8 %0, -4
  br label %14

12:                                               ; preds = %8
  %13 = icmp eq i8 %0, 62
  %. = select i1 %13, i8 43, i8 47
  br label %14

14:                                               ; preds = %12, %10, %6, %3
  %.0 = phi i8 [ %narrow, %3 ], [ %7, %6 ], [ %11, %10 ], [ %., %12 ]
  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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass