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

; 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.FATFS = type { i8, i8, i8, i8, i8, i8, i16, i16, i16, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i64, i64, i64, i64, i64, i64, [512 x i8] }

@FatFs = external hidden global [4 x ptr], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @f_mount(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i8 %2, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %13, ptr %11, align 8, !tbaa !5
  %14 = call i32 @get_ldnumber(ptr noundef %11)
  store i32 %14, ptr %9, align 4, !tbaa !10
  %15 = load i32, ptr %9, align 4, !tbaa !10
  %16 = icmp slt i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %3
  store i32 11, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %54

18:                                               ; preds = %3
  %19 = load i32, ptr %9, align 4, !tbaa !10
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [4 x ptr], ptr @FatFs, i64 0, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  store ptr %22, ptr %8, align 8, !tbaa !5
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %32

25:                                               ; preds = %18
  %26 = load i32, ptr %9, align 4, !tbaa !10
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [4 x ptr], ptr @FatFs, i64 0, i64 %27
  store ptr null, ptr %28, align 8, !tbaa !5
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  call void @clear_share(ptr noundef %29)
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.FATFS, ptr %30, i32 0, i32 0
  store i8 0, ptr %31, align 8, !tbaa !12
  br label %32

32:                                               ; preds = %25, %18
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %46

35:                                               ; preds = %32
  %36 = load i32, ptr %9, align 4, !tbaa !10
  %37 = trunc i32 %36 to i8
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.FATFS, ptr %38, i32 0, i32 1
  store i8 %37, ptr %39, align 1, !tbaa !16
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.FATFS, ptr %40, i32 0, i32 0
  store i8 0, ptr %41, align 8, !tbaa !12
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i32, ptr %9, align 4, !tbaa !10
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [4 x ptr], ptr @FatFs, i64 0, i64 %44
  store ptr %42, ptr %45, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %35, %32
  %47 = load i8, ptr %7, align 1, !tbaa !9
  %48 = zext i8 %47 to i32
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %46
  store i32 0, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %54

51:                                               ; preds = %46
  %52 = call i32 @mount_volume(ptr noundef %6, ptr noundef %5, i8 noundef zeroext 0)
  store i32 %52, ptr %10, align 4, !tbaa !10
  %53 = load i32, ptr %10, align 4, !tbaa !10
  store i32 %53, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %54

54:                                               ; preds = %51, %50, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %55 = load i32, ptr %4, align 4
  ret i32 %55
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @get_ldnumber(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @clear_share(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @mount_volume(ptr noundef, ptr noundef, i8 noundef zeroext) #0

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

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 }

!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 0}
!13 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !14, i64 6, !14, i64 8, !14, i64 10, !6, i64 16, !6, i64 24, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !15, i64 64, !15, i64 72, !15, i64 80, !15, i64 88, !15, i64 96, !15, i64 104, !7, i64 112}
!14 = !{!"short", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!13, !7, i64 1}


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

@FatFs = external hidden local_unnamed_addr global [4 x ptr], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @f_mount(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  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 8, ptr nonnull %6) #2
  store ptr %1, ptr %6, align 8, !tbaa !5
  %7 = call i32 @get_ldnumber(ptr noundef nonnull %6)
  %8 = icmp slt i32 %7, 0
  br i1 %8, label %22, label %9

9:                                                ; preds = %3
  %10 = zext nneg i32 %7 to i64
  %11 = getelementptr inbounds [4 x ptr], ptr @FatFs, i64 0, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %14, label %13

13:                                               ; preds = %9
  store ptr null, ptr %11, align 8, !tbaa !5
  call void @clear_share(ptr noundef nonnull %12)
  store i8 0, ptr %12, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %13, %9
  %.not13 = icmp eq ptr %0, null
  br i1 %.not13, label %18, label %15

15:                                               ; preds = %14
  %16 = trunc i32 %7 to i8
  %17 = getelementptr inbounds i8, ptr %0, i64 1
  store i8 %16, ptr %17, align 1, !tbaa !14
  store i8 0, ptr %0, align 8, !tbaa !9
  store ptr %0, ptr %11, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %15, %14
  %19 = icmp eq i8 %2, 0
  br i1 %19, label %22, label %20

20:                                               ; preds = %18
  %21 = call i32 @mount_volume(ptr noundef nonnull %5, ptr noundef nonnull %4, i8 noundef zeroext 0)
  br label %22

22:                                               ; preds = %18, %3, %20
  %.0 = phi i32 [ %21, %20 ], [ 11, %3 ], [ 0, %18 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #2
  ret i32 %.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: nounwind uwtable
declare hidden i32 @get_ldnumber(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @clear_share(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @mount_volume(ptr noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

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

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 = { 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 = !{!10, !7, i64 0}
!10 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !11, i64 6, !11, i64 8, !11, i64 10, !6, i64 16, !6, i64 24, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !12, i64 56, !12, i64 60, !13, i64 64, !13, i64 72, !13, i64 80, !13, i64 88, !13, i64 96, !13, i64 104, !7, i64 112}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !7, i64 1}


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