; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/Middlewares/Third_Party/FatFs/src (ff_gen_drv)

; 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.Disk_drvTypeDef = type { [2 x i8], [2 x ptr], [2 x i8], i8 }

@disk = external dso_local global %struct.Disk_drvTypeDef, align 8

; 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 zeroext i8 @FATFS_UnLinkDriverEx(ptr noundef %0, i8 noundef zeroext %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #2
  store i8 0, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  store i8 1, ptr %6, align 1, !tbaa !9
  %7 = load volatile i8, ptr getelementptr inbounds (%struct.Disk_drvTypeDef, ptr @disk, i32 0, i32 3), align 2, !tbaa !10
  %8 = zext i8 %7 to i32
  %9 = icmp sge i32 %8, 1
  br i1 %9, label %10, label %32

10:                                               ; preds = %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 0
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = sext i8 %13 to i32
  %15 = sub nsw i32 %14, 48
  %16 = trunc i32 %15 to i8
  store i8 %16, ptr %5, align 1, !tbaa !9
  %17 = load i8, ptr %5, align 1, !tbaa !9
  %18 = zext i8 %17 to i64
  %19 = getelementptr inbounds [2 x ptr], ptr getelementptr inbounds (%struct.Disk_drvTypeDef, ptr @disk, i32 0, i32 1), i64 0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %31

22:                                               ; preds = %10
  %23 = load i8, ptr %5, align 1, !tbaa !9
  %24 = zext i8 %23 to i64
  %25 = getelementptr inbounds [2 x ptr], ptr getelementptr inbounds (%struct.Disk_drvTypeDef, ptr @disk, i32 0, i32 1), i64 0, i64 %24
  store ptr null, ptr %25, align 8, !tbaa !5
  %26 = load i8, ptr %5, align 1, !tbaa !9
  %27 = zext i8 %26 to i64
  %28 = getelementptr inbounds [2 x i8], ptr getelementptr inbounds (%struct.Disk_drvTypeDef, ptr @disk, i32 0, i32 2), i64 0, i64 %27
  store i8 0, ptr %28, align 1, !tbaa !9
  %29 = load volatile i8, ptr getelementptr inbounds (%struct.Disk_drvTypeDef, ptr @disk, i32 0, i32 3), align 2, !tbaa !10
  %30 = add i8 %29, -1
  store volatile i8 %30, ptr getelementptr inbounds (%struct.Disk_drvTypeDef, ptr @disk, i32 0, i32 3), align 2, !tbaa !10
  store i8 0, ptr %6, align 1, !tbaa !9
  br label %31

31:                                               ; preds = %22, %10
  br label %32

32:                                               ; preds = %31, %2
  %33 = load i8, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  ret i8 %33
}

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 = { 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, !7, i64 26}
!11 = !{!"", !7, i64 0, !7, i64 8, !7, i64 24, !7, i64 26}


; 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.Disk_drvTypeDef = type { [2 x i8], [2 x ptr], [2 x i8], i8 }

@disk = external dso_local global %struct.Disk_drvTypeDef, align 8

; Function Attrs: nofree norecurse nounwind memory(readwrite, argmem: read) uwtable
define dso_local zeroext range(i8 0, 2) i8 @FATFS_UnLinkDriverEx(ptr nocapture noundef readonly %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = load volatile i8, ptr getelementptr inbounds (i8, ptr @disk, i64 26), align 2, !tbaa !5
  %.not = icmp eq i8 %3, 0
  br i1 %.not, label %14, label %4

4:                                                ; preds = %2
  %5 = load i8, ptr %0, align 1, !tbaa !9
  %6 = add i8 %5, -48
  %7 = zext i8 %6 to i64
  %8 = getelementptr inbounds [2 x ptr], ptr getelementptr inbounds (i8, ptr @disk, i64 8), i64 0, i64 %7
  %9 = load ptr, ptr %8, align 8, !tbaa !10
  %.not4 = icmp eq ptr %9, null
  br i1 %.not4, label %14, label %10

10:                                               ; preds = %4
  store ptr null, ptr %8, align 8, !tbaa !10
  %11 = getelementptr inbounds [2 x i8], ptr getelementptr inbounds (i8, ptr @disk, i64 24), i64 0, i64 %7
  store i8 0, ptr %11, align 1, !tbaa !9
  %12 = load volatile i8, ptr getelementptr inbounds (i8, ptr @disk, i64 26), align 2, !tbaa !5
  %13 = add i8 %12, -1
  store volatile i8 %13, ptr getelementptr inbounds (i8, ptr @disk, i64 26), align 2, !tbaa !5
  br label %14

14:                                               ; preds = %4, %10, %2
  %.0 = phi i8 [ 0, %10 ], [ 1, %4 ], [ 1, %2 ]
  ret i8 %.0
}

attributes #0 = { nofree norecurse nounwind memory(readwrite, argmem: read) 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, !7, i64 26}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 24, !7, i64 26}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}


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