; LLVM IR from carlk3/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico :: src/src (f_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"

%struct.DIR = type { %struct.FFOBJID, i32, i32, i64, ptr, [12 x i8], i32, ptr }
%struct.FFOBJID = type { ptr, i16, i8, i8, i32, i64, i32, i32, i32, i32, i32, i32 }
%struct.FILINFO = type { i64, i16, i16, i8, [13 x i8], [256 x i8] }

@.str.21 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [90 x i8], align 1
@__PRETTY_FUNCTION__.ls = external hidden unnamed_addr constant [22 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @FRESULT_str(i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare i32 @f_closedir(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local void @ls(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca [255 x i8], align 16
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.DIR, align 8
  %8 = alloca %struct.FILINFO, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 255, ptr %3) #5
  call void @llvm.memset.p0.i64(ptr align 16 %3, i8 0, i64 255, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 0
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = icmp ne i8 %15, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %1
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %18, ptr %5, align 8, !tbaa !5
  br label %31

19:                                               ; preds = %1
  %20 = getelementptr inbounds [255 x i8], ptr %3, i64 0, i64 0
  %21 = call i32 @f_getcwd(ptr noundef %20, i32 noundef 255)
  store i32 %21, ptr %4, align 4, !tbaa !10
  %22 = load i32, ptr %4, align 4, !tbaa !10
  %23 = icmp ne i32 0, %22
  br i1 %23, label %24, label %29

24:                                               ; preds = %19
  %25 = load i32, ptr %4, align 4, !tbaa !10
  %26 = call ptr @FRESULT_str(i32 noundef %25)
  %27 = load i32, ptr %4, align 4, !tbaa !10
  %28 = call i32 (ptr, ...) @printf(ptr noundef @.str.21, ptr noundef %26, i32 noundef %27)
  store i32 1, ptr %6, align 4
  br label %90

29:                                               ; preds = %19
  %30 = getelementptr inbounds [255 x i8], ptr %3, i64 0, i64 0
  store ptr %30, ptr %5, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %29, %17
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.22, ptr noundef %32)
  call void @llvm.lifetime.start.p0(i64 96, ptr %7) #5
  call void @llvm.memset.p0.i64(ptr align 8 %7, i8 0, i64 96, i1 false)
  call void @llvm.lifetime.start.p0(i64 288, ptr %8) #5
  call void @llvm.memset.p0.i64(ptr align 8 %8, i8 0, i64 288, i1 false)
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %37

36:                                               ; preds = %31
  br label %38

37:                                               ; preds = %31
  call void @__assert_fail(ptr noundef @.str.23, ptr noundef @.str.24, i32 noundef 127, ptr noundef @__PRETTY_FUNCTION__.ls) #6
  unreachable

38:                                               ; preds = %36
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = call i32 @f_findfirst(ptr noundef %7, ptr noundef %8, ptr noundef %39, ptr noundef @.str.25)
  store i32 %40, ptr %4, align 4, !tbaa !10
  %41 = load i32, ptr %4, align 4, !tbaa !10
  %42 = icmp ne i32 0, %41
  br i1 %42, label %43, label %48

43:                                               ; preds = %38
  %44 = load i32, ptr %4, align 4, !tbaa !10
  %45 = call ptr @FRESULT_str(i32 noundef %44)
  %46 = load i32, ptr %4, align 4, !tbaa !10
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.26, ptr noundef %45, i32 noundef %46)
  store i32 1, ptr %6, align 4
  br label %89

48:                                               ; preds = %38
  br label %49

49:                                               ; preds = %79, %48
  %50 = load i32, ptr %4, align 4, !tbaa !10
  %51 = icmp eq i32 %50, 0
  br i1 %51, label %52, label %58

52:                                               ; preds = %49
  %53 = getelementptr inbounds %struct.FILINFO, ptr %8, i32 0, i32 5
  %54 = getelementptr inbounds [256 x i8], ptr %53, i64 0, i64 0
  %55 = load i8, ptr %54, align 2, !tbaa !9
  %56 = sext i8 %55 to i32
  %57 = icmp ne i32 %56, 0
  br label %58

58:                                               ; preds = %52, %49
  %59 = phi i1 [ false, %49 ], [ %57, %52 ]
  br i1 %59, label %60, label %87

60:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store ptr @.str.27, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store ptr @.str.28, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store ptr @.str.29, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %61 = getelementptr inbounds %struct.FILINFO, ptr %8, i32 0, i32 3
  %62 = load i8, ptr %61, align 4, !tbaa !12
  %63 = zext i8 %62 to i32
  %64 = and i32 %63, 16
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %68

66:                                               ; preds = %60
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %67, ptr %12, align 8, !tbaa !5
  br label %79

68:                                               ; preds = %60
  %69 = getelementptr inbounds %struct.FILINFO, ptr %8, i32 0, i32 3
  %70 = load i8, ptr %69, align 4, !tbaa !12
  %71 = zext i8 %70 to i32
  %72 = and i32 %71, 1
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %76

74:                                               ; preds = %68
  %75 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %75, ptr %12, align 8, !tbaa !5
  br label %78

76:                                               ; preds = %68
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %77, ptr %12, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %76, %74
  br label %79

79:                                               ; preds = %78, %66
  %80 = getelementptr inbounds %struct.FILINFO, ptr %8, i32 0, i32 5
  %81 = getelementptr inbounds [256 x i8], ptr %80, i64 0, i64 0
  %82 = load ptr, ptr %12, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.FILINFO, ptr %8, i32 0, i32 0
  %84 = load i64, ptr %83, align 8, !tbaa !16
  %85 = call i32 (ptr, ...) @printf(ptr noundef @.str.30, ptr noundef %81, ptr noundef %82, i64 noundef %84)
  %86 = call i32 @f_findnext(ptr noundef %7, ptr noundef %8)
  store i32 %86, ptr %4, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %49, !llvm.loop !17

87:                                               ; preds = %58
  %88 = call i32 @f_closedir(ptr noundef %7)
  store i32 0, ptr %6, align 4
  br label %89

89:                                               ; preds = %87, %43
  call void @llvm.lifetime.end.p0(i64 288, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 96, ptr %7) #5
  br label %90

90:                                               ; preds = %89, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 255, ptr %3) #5
  %91 = load i32, ptr %6, align 4
  switch i32 %91, label %93 [
    i32 0, label %92
    i32 1, label %92
  ]

92:                                               ; preds = %90, %90
  ret void

93:                                               ; preds = %90
  unreachable
}

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

declare i32 @f_getcwd(ptr noundef, i32 noundef) #2

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

declare i32 @f_findfirst(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @f_findnext(ptr noundef, ptr noundef) #2

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { noreturn nounwind "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 #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !7, i64 12}
!13 = !{!"", !14, i64 0, !15, i64 8, !15, i64 10, !7, i64 12, !7, i64 13, !7, i64 26}
!14 = !{!"long", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!13, !14, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%struct.DIR = type { %struct.FFOBJID, i32, i32, i64, ptr, [12 x i8], i32, ptr }
%struct.FFOBJID = type { ptr, i16, i8, i8, i32, i64, i32, i32, i32, i32, i32, i32 }
%struct.FILINFO = type { i64, i16, i16, i8, [13 x i8], [256 x i8] }

@.str.21 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @FRESULT_str(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare i32 @f_closedir(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local void @ls(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca [255 x i8], align 16
  %3 = alloca %struct.DIR, align 8
  %4 = alloca %struct.FILINFO, align 8
  call void @llvm.lifetime.start.p0(i64 255, ptr nonnull %2) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(255) %2, i8 0, i64 255, i1 false)
  %5 = load i8, ptr %0, align 1, !tbaa !5
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %6, label %11

6:                                                ; preds = %1
  %7 = call i32 @f_getcwd(ptr noundef nonnull %2, i32 noundef 255) #5
  %.not19 = icmp eq i32 %7, 0
  br i1 %.not19, label %11, label %8

8:                                                ; preds = %6
  %9 = call ptr @FRESULT_str(i32 noundef %7)
  %10 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.21, ptr noundef %9, i32 noundef %7)
  br label %34

11:                                               ; preds = %6, %1
  %.016 = phi ptr [ %0, %1 ], [ %2, %6 ]
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.22, ptr noundef nonnull %.016)
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %3) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(96) %3, i8 0, i64 96, i1 false)
  call void @llvm.lifetime.start.p0(i64 288, ptr nonnull %4) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(288) %4, i8 0, i64 288, i1 false)
  %13 = call i32 @f_findfirst(ptr noundef nonnull %3, ptr noundef nonnull %4, ptr noundef nonnull %.016, ptr noundef nonnull @.str.25) #5
  %.not20 = icmp eq i32 %13, 0
  br i1 %.not20, label %.preheader, label %17

.preheader:                                       ; preds = %11
  %14 = getelementptr inbounds i8, ptr %4, i64 26
  %15 = load i8, ptr %14, align 2
  %.not23 = icmp eq i8 %15, 0
  br i1 %.not23, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %16 = getelementptr inbounds i8, ptr %4, i64 12
  br label %20

17:                                               ; preds = %11
  %18 = call ptr @FRESULT_str(i32 noundef %13)
  %19 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.26, ptr noundef %18, i32 noundef %13)
  br label %33

20:                                               ; preds = %.lr.ph, %20
  %21 = load i8, ptr %16, align 4, !tbaa !8
  %22 = zext i8 %21 to i32
  %23 = and i32 %22, 16
  %.not21 = icmp eq i32 %23, 0
  %24 = and i32 %22, 1
  %.not22 = icmp eq i32 %24, 0
  %.str.27..str.28 = select i1 %.not22, ptr @.str.27, ptr @.str.28
  %.0 = select i1 %.not21, ptr %.str.27..str.28, ptr @.str.29
  %25 = load i64, ptr %4, align 8, !tbaa !12
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.30, ptr noundef nonnull %14, ptr noundef nonnull %.0, i64 noundef %25)
  %27 = call i32 @f_findnext(ptr noundef nonnull %3, ptr noundef nonnull %4) #5
  %28 = icmp eq i32 %27, 0
  %29 = load i8, ptr %14, align 2
  %30 = icmp ne i8 %29, 0
  %31 = select i1 %28, i1 %30, i1 false
  br i1 %31, label %20, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %20, %.preheader
  %32 = call i32 @f_closedir(ptr noundef nonnull %3) #5
  br label %33

33:                                               ; preds = %._crit_edge, %17
  call void @llvm.lifetime.end.p0(i64 288, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %3) #5
  br label %34

34:                                               ; preds = %33, %8
  call void @llvm.lifetime.end.p0(i64 255, ptr nonnull %2) #5
  ret void
}

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

declare i32 @f_getcwd(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

declare i32 @f_findfirst(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @f_findnext(ptr noundef, ptr noundef) local_unnamed_addr #2

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nofree nounwind "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 #5 = { 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, !6, i64 12}
!9 = !{!"", !10, i64 0, !11, i64 8, !11, i64 10, !6, i64 12, !6, i64 13, !6, i64 26}
!10 = !{!"long", !6, i64 0}
!11 = !{!"short", !6, i64 0}
!12 = !{!9, !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass