; LLVM IR from carlk3/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico :: src/src (util)

; 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"

@uint8_binary_str.b = external hidden global [9 x i8], align 1

; 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 ptr @uint8_binary_str(i8 noundef zeroext %0) #1 {
  %2 = alloca i8, align 1
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  store i8 %0, ptr %2, align 1, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 1 @uint8_binary_str.b, i8 0, i64 9, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 0, ptr %3, align 8, !tbaa !8
  br label %5

5:                                                ; preds = %27, %1
  %6 = load i64, ptr %3, align 8, !tbaa !8
  %7 = icmp ult i64 %6, 8
  br i1 %7, label %9, label %8

8:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %30

9:                                                ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %10 = load i64, ptr %3, align 8, !tbaa !8
  %11 = trunc i64 %10 to i32
  %12 = shl i32 1, %11
  store i32 %12, ptr %4, align 4, !tbaa !10
  %13 = load i8, ptr %2, align 1, !tbaa !5
  %14 = zext i8 %13 to i32
  %15 = load i32, ptr %4, align 4, !tbaa !10
  %16 = and i32 %14, %15
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %22

18:                                               ; preds = %9
  %19 = load i64, ptr %3, align 8, !tbaa !8
  %20 = sub i64 7, %19
  %21 = getelementptr inbounds [9 x i8], ptr @uint8_binary_str.b, i64 0, i64 %20
  store i8 49, ptr %21, align 1, !tbaa !5
  br label %26

22:                                               ; preds = %9
  %23 = load i64, ptr %3, align 8, !tbaa !8
  %24 = sub i64 7, %23
  %25 = getelementptr inbounds [9 x i8], ptr @uint8_binary_str.b, i64 0, i64 %24
  store i8 48, ptr %25, align 1, !tbaa !5
  br label %26

26:                                               ; preds = %22, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %27

27:                                               ; preds = %26
  %28 = load i64, ptr %3, align 8, !tbaa !8
  %29 = add i64 %28, 1
  store i64 %29, ptr %3, align 8, !tbaa !8
  br label %5, !llvm.loop !12

30:                                               ; preds = %8
  ret ptr @uint8_binary_str.b
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 = !{!"long", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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"

@uint8_binary_str.b = external hidden global [9 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef nonnull ptr @uint8_binary_str(i8 noundef zeroext %0) local_unnamed_addr #0 {
  store i8 0, ptr getelementptr inbounds (i8, ptr @uint8_binary_str.b, i64 8), align 1
  %2 = zext i8 %0 to i32
  %3 = insertelement <4 x i32> poison, i32 %2, i64 0
  %4 = shufflevector <4 x i32> %3, <4 x i32> poison, <4 x i32> zeroinitializer
  %5 = and <4 x i32> %4, <i32 8, i32 4, i32 2, i32 1>
  %6 = icmp eq <4 x i32> %5, zeroinitializer
  %7 = insertelement <2 x i32> poison, i32 %2, i64 0
  %8 = shufflevector <2 x i32> %7, <2 x i32> poison, <2 x i32> zeroinitializer
  %9 = and <2 x i32> %8, <i32 32, i32 16>
  %10 = icmp eq <2 x i32> %9, zeroinitializer
  %11 = and i32 %2, 64
  %.not.6 = icmp eq i32 %11, 0
  %.not.7 = icmp sgt i8 %0, -1
  %12 = insertelement <8 x i1> poison, i1 %.not.7, i64 0
  %13 = insertelement <8 x i1> %12, i1 %.not.6, i64 1
  %14 = shufflevector <2 x i1> %10, <2 x i1> poison, <8 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
  %15 = shufflevector <8 x i1> %13, <8 x i1> %14, <8 x i32> <i32 0, i32 1, i32 8, i32 9, i32 poison, i32 poison, i32 poison, i32 poison>
  %16 = shufflevector <4 x i1> %6, <4 x i1> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison>
  %17 = shufflevector <8 x i1> %15, <8 x i1> %16, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11>
  %18 = select <8 x i1> %17, <8 x i8> <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>, <8 x i8> <i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49>
  store <8 x i8> %18, ptr @uint8_binary_str.b, align 1
  ret ptr @uint8_binary_str.b
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: 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: DSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass