; LLVM IR from HANDS-FREE/OpenRE :: 3_OS/STM32F1/FATFS (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, i64, i64, i64, i64, i64, i64, i64, i64, i64, [512 x i8] }

@FatFs = external hidden global [1 x ptr], 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 i32 @f_mount(i8 noundef zeroext %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store i8 %0, ptr %4, align 1, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %8 = load i8, ptr %4, align 1, !tbaa !5
  %9 = zext i8 %8 to i32
  %10 = icmp sge i32 %9, 1
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  store i32 11, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %33

12:                                               ; preds = %2
  %13 = load i8, ptr %4, align 1, !tbaa !5
  %14 = zext i8 %13 to i64
  %15 = getelementptr inbounds [1 x ptr], ptr @FatFs, i64 0, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !8
  store ptr %16, ptr %6, align 8, !tbaa !8
  %17 = load ptr, ptr %6, align 8, !tbaa !8
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %22

19:                                               ; preds = %12
  %20 = load ptr, ptr %6, align 8, !tbaa !8
  %21 = getelementptr inbounds %struct.FATFS, ptr %20, i32 0, i32 0
  store i8 0, ptr %21, align 8, !tbaa !10
  br label %22

22:                                               ; preds = %19, %12
  %23 = load ptr, ptr %5, align 8, !tbaa !8
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %28

25:                                               ; preds = %22
  %26 = load ptr, ptr %5, align 8, !tbaa !8
  %27 = getelementptr inbounds %struct.FATFS, ptr %26, i32 0, i32 0
  store i8 0, ptr %27, align 8, !tbaa !10
  br label %28

28:                                               ; preds = %25, %22
  %29 = load ptr, ptr %5, align 8, !tbaa !8
  %30 = load i8, ptr %4, align 1, !tbaa !5
  %31 = zext i8 %30 to i64
  %32 = getelementptr inbounds [1 x ptr], ptr @FatFs, i64 0, i64 %31
  store ptr %29, ptr %32, align 8, !tbaa !8
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %33

33:                                               ; preds = %28, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %34 = load i32, ptr %3, align 4
  ret i32 %34
}

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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !6, i64 0}
!11 = !{!"", !6, i64 0, !6, i64 1, !6, i64 2, !6, i64 3, !6, i64 4, !6, i64 5, !12, i64 6, !12, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !13, i64 72, !13, i64 80, !6, i64 88}
!12 = !{!"short", !6, i64 0}
!13 = !{!"long", !6, i64 0}


; 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 [1 x ptr], align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 12) i32 @f_mount(i8 noundef zeroext %0, ptr noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq i8 %0, 0
  br i1 %.not, label %3, label %9

3:                                                ; preds = %2
  %4 = load ptr, ptr @FatFs, align 8, !tbaa !5
  %.not10 = icmp eq ptr %4, null
  br i1 %.not10, label %6, label %5

5:                                                ; preds = %3
  store i8 0, ptr %4, align 8, !tbaa !9
  br label %6

6:                                                ; preds = %5, %3
  %.not11 = icmp eq ptr %1, null
  br i1 %.not11, label %8, label %7

7:                                                ; preds = %6
  store i8 0, ptr %1, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %7, %6
  store ptr %1, ptr @FatFs, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %2, %8
  %.0 = phi i32 [ 0, %8 ], [ 11, %2 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, 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)"}
!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, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !7, i64 88}
!11 = !{!"short", !7, i64 0}
!12 = !{!"long", !7, i64 0}


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