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

; 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.FF_FindData_t = type { %struct.DIR, %struct.FILINFO, ptr, i32 }
%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.6 = external hidden unnamed_addr constant [2 x i8], align 1

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

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #2

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

declare i32 @f_chdir(ptr noundef) #3

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

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

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

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %17 = getelementptr inbounds [250 x i8], ptr %6, i64 0, i64 0
  %18 = call i32 @f_getcwd(ptr noundef %17, i32 noundef 250)
  store i32 %18, ptr %7, align 4, !tbaa !10
  %19 = load i32, ptr %7, align 4, !tbaa !10
  %20 = call i32 @fresult2errno(i32 noundef %19)
  %21 = call ptr @__errno_location() #6
  store i32 %20, ptr %21, align 4, !tbaa !10
  %22 = load i32, ptr %7, align 4, !tbaa !10
  %23 = icmp ne i32 0, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %16
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %35

25:                                               ; preds = %16
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = call i32 @f_chdir(ptr noundef %26)
  store i32 %27, ptr %7, align 4, !tbaa !10
  %28 = load i32, ptr %7, align 4, !tbaa !10
  %29 = call i32 @fresult2errno(i32 noundef %28)
  %30 = call ptr @__errno_location() #6
  store i32 %29, ptr %30, align 4, !tbaa !10
  %31 = load i32, ptr %7, align 4, !tbaa !10
  %32 = icmp ne i32 0, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %25
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %35

34:                                               ; preds = %25
  store i32 0, ptr %8, align 4
  br label %35

35:                                               ; preds = %34, %33, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  %36 = load i32, ptr %8, align 4
  switch i32 %36, label %86 [
    i32 0, label %37
  ]

37:                                               ; preds = %35
  br label %38

38:                                               ; preds = %37, %2
  call void @llvm.lifetime.start.p0(i64 250, ptr %9) #5
  call void @llvm.memset.p0.i64(ptr align 16 %9, i8 0, i64 250, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %39 = getelementptr inbounds [250 x i8], ptr %9, i64 0, i64 0
  %40 = call i32 @f_getcwd(ptr noundef %39, i32 noundef 250)
  store i32 %40, ptr %10, align 4, !tbaa !10
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.FF_FindData_t, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.FF_FindData_t, ptr %43, i32 0, i32 1
  %45 = getelementptr inbounds [250 x i8], ptr %9, i64 0, i64 0
  %46 = call i32 @f_findfirst(ptr noundef %42, ptr noundef %44, ptr noundef %45, ptr noundef @.str.6)
  store i32 %46, ptr %10, align 4, !tbaa !10
  %47 = load i32, ptr %10, align 4, !tbaa !10
  %48 = call i32 @fresult2errno(i32 noundef %47)
  %49 = call ptr @__errno_location() #6
  store i32 %48, ptr %49, align 4, !tbaa !10
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.FF_FindData_t, ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds %struct.FILINFO, ptr %51, i32 0, i32 5
  %53 = getelementptr inbounds [256 x i8], ptr %52, i64 0, i64 0
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.FF_FindData_t, ptr %54, i32 0, i32 2
  store ptr %53, ptr %55, align 8, !tbaa !12
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.FF_FindData_t, ptr %56, i32 0, i32 1
  %58 = getelementptr inbounds %struct.FILINFO, ptr %57, i32 0, i32 0
  %59 = load i64, ptr %58, align 8, !tbaa !19
  %60 = trunc i64 %59 to i32
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.FF_FindData_t, ptr %61, i32 0, i32 3
  store i32 %60, ptr %62, align 8, !tbaa !20
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %63, i64 0
  %65 = load i8, ptr %64, align 1, !tbaa !9
  %66 = icmp ne i8 %65, 0
  br i1 %66, label %67, label %80

67:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %68 = getelementptr inbounds [250 x i8], ptr %6, i64 0, i64 0
  %69 = call i32 @f_chdir(ptr noundef %68)
  store i32 %69, ptr %11, align 4, !tbaa !10
  %70 = load i32, ptr %11, align 4, !tbaa !10
  %71 = call i32 @fresult2errno(i32 noundef %70)
  %72 = call ptr @__errno_location() #6
  store i32 %71, ptr %72, align 4, !tbaa !10
  %73 = load i32, ptr %11, align 4, !tbaa !10
  %74 = icmp ne i32 0, %73
  br i1 %74, label %75, label %76

75:                                               ; preds = %67
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %77

76:                                               ; preds = %67
  store i32 0, ptr %8, align 4
  br label %77

77:                                               ; preds = %76, %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  %78 = load i32, ptr %8, align 4
  switch i32 %78, label %85 [
    i32 0, label %79
  ]

79:                                               ; preds = %77
  br label %80

80:                                               ; preds = %79, %38
  %81 = load i32, ptr %10, align 4, !tbaa !10
  %82 = icmp eq i32 0, %81
  br i1 %82, label %83, label %84

83:                                               ; preds = %80
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %85

84:                                               ; preds = %80
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %85

85:                                               ; preds = %84, %83, %77
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 250, ptr %9) #5
  br label %86

86:                                               ; preds = %85, %35
  call void @llvm.lifetime.end.p0(i64 250, ptr %6) #5
  %87 = load i32, ptr %3, align 4
  ret i32 %87
}

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

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 = { nounwind willreturn memory(none) "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 = { "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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(none) }

!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, !6, i64 384}
!13 = !{!"", !14, i64 0, !18, i64 96, !6, i64 384, !11, i64 392}
!14 = !{!"", !15, i64 0, !11, i64 48, !11, i64 52, !17, i64 56, !6, i64 64, !7, i64 72, !11, i64 84, !6, i64 88}
!15 = !{!"", !6, i64 0, !16, i64 8, !7, i64 10, !7, i64 11, !11, i64 12, !17, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44}
!16 = !{!"short", !7, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!"", !17, i64 0, !16, i64 8, !16, i64 10, !7, i64 12, !7, i64 13, !7, i64 26}
!19 = !{!13, !17, i64 96}
!20 = !{!13, !11, i64 392}


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

@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @fresult2errno(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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() 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

declare i32 @f_chdir(ptr noundef) local_unnamed_addr #3

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @ff_findfirst(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca [250 x i8], align 16
  %4 = alloca [250 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 250, ptr nonnull %3) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(250) %3, i8 0, i64 250, i1 false)
  %5 = load i8, ptr %0, align 1, !tbaa !5
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %13, label %6

6:                                                ; preds = %2
  %7 = call i32 @f_getcwd(ptr noundef nonnull %3, i32 noundef 250) #5
  %8 = call i32 @fresult2errno(i32 noundef %7)
  %9 = tail call ptr @__errno_location() #6
  store i32 %8, ptr %9, align 4, !tbaa !8
  %.not22 = icmp eq i32 %7, 0
  br i1 %.not22, label %10, label %.critedge

10:                                               ; preds = %6
  %11 = call i32 @f_chdir(ptr noundef nonnull %0) #5
  %12 = call i32 @fresult2errno(i32 noundef %11)
  store i32 %12, ptr %9, align 4, !tbaa !8
  %.not23 = icmp eq i32 %11, 0
  br i1 %.not23, label %13, label %.critedge

13:                                               ; preds = %10, %2
  call void @llvm.lifetime.start.p0(i64 250, ptr nonnull %4) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(250) %4, i8 0, i64 250, i1 false)
  %14 = call i32 @f_getcwd(ptr noundef nonnull %4, i32 noundef 250) #5
  %15 = getelementptr inbounds i8, ptr %1, i64 96
  %16 = call i32 @f_findfirst(ptr noundef %1, ptr noundef nonnull %15, ptr noundef nonnull %4, ptr noundef nonnull @.str.6) #5
  %17 = call i32 @fresult2errno(i32 noundef %16)
  %18 = tail call ptr @__errno_location() #6
  store i32 %17, ptr %18, align 4, !tbaa !8
  %19 = getelementptr inbounds i8, ptr %1, i64 122
  %20 = getelementptr inbounds i8, ptr %1, i64 384
  store ptr %19, ptr %20, align 8, !tbaa !10
  %21 = load i64, ptr %15, align 8, !tbaa !18
  %22 = trunc i64 %21 to i32
  %23 = getelementptr inbounds i8, ptr %1, i64 392
  store i32 %22, ptr %23, align 8, !tbaa !19
  %24 = load i8, ptr %0, align 1, !tbaa !5
  %.not24 = icmp eq i8 %24, 0
  br i1 %.not24, label %28, label %25

25:                                               ; preds = %13
  %26 = call i32 @f_chdir(ptr noundef nonnull %3) #5
  %27 = call i32 @fresult2errno(i32 noundef %26)
  store i32 %27, ptr %18, align 4, !tbaa !8
  %.not25 = icmp eq i32 %26, 0
  br i1 %.not25, label %28, label %30

28:                                               ; preds = %25, %13
  %29 = icmp ne i32 %16, 0
  %.26 = sext i1 %29 to i32
  br label %30

30:                                               ; preds = %28, %25
  %.3 = phi i32 [ -1, %25 ], [ %.26, %28 ]
  call void @llvm.lifetime.end.p0(i64 250, ptr nonnull %4) #5
  br label %.critedge

.critedge:                                        ; preds = %6, %10, %30
  %.4 = phi i32 [ %.3, %30 ], [ -1, %10 ], [ -1, %6 ]
  call void @llvm.lifetime.end.p0(i64 250, ptr nonnull %3) #5
  ret i32 %.4
}

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

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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { "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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(none) }

!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 = !{!"int", !6, i64 0}
!10 = !{!11, !14, i64 384}
!11 = !{!"", !12, i64 0, !17, i64 96, !14, i64 384, !9, i64 392}
!12 = !{!"", !13, i64 0, !9, i64 48, !9, i64 52, !16, i64 56, !14, i64 64, !6, i64 72, !9, i64 84, !14, i64 88}
!13 = !{!"", !14, i64 0, !15, i64 8, !6, i64 10, !6, i64 11, !9, i64 12, !16, i64 16, !9, i64 24, !9, i64 28, !9, i64 32, !9, i64 36, !9, i64 40, !9, i64 44}
!14 = !{!"any pointer", !6, i64 0}
!15 = !{!"short", !6, i64 0}
!16 = !{!"long", !6, i64 0}
!17 = !{!"", !16, i64 0, !15, i64 8, !15, i64 10, !6, i64 12, !6, i64 13, !6, i64 26}
!18 = !{!11, !16, i64 96}
!19 = !{!11, !9, i64 392}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass