; LLVM IR from erthink/libmdbx :: src (osal)

; 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.statvfs = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, [6 x i32] }

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

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

; 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 @osal_check_fs_rdonly(i32 noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca %struct.statvfs, align 8
  %9 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 112, ptr %8) #4
  %10 = load i32, ptr %7, align 4, !tbaa !5
  %11 = icmp ne i32 %10, 2
  br i1 %11, label %12, label %34

12:                                               ; preds = %3
  %13 = load ptr, ptr %6, align 8, !tbaa !9
  %14 = call i32 @statvfs64(ptr noundef %13, ptr noundef %8) #4
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %26

16:                                               ; preds = %12
  %17 = getelementptr inbounds %struct.statvfs, ptr %8, i32 0, i32 9
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = and i64 %18, 1
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  br label %24

22:                                               ; preds = %16
  %23 = load i32, ptr %7, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %22, %21
  %25 = phi i32 [ 0, %21 ], [ %23, %22 ]
  store i32 %25, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %55

26:                                               ; preds = %12
  %27 = call ptr @__errno_location() #5
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = icmp ne i32 %28, 2
  br i1 %29, label %30, label %33

30:                                               ; preds = %26
  %31 = call ptr @__errno_location() #5
  %32 = load i32, ptr %31, align 4, !tbaa !5
  store i32 %32, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %55

33:                                               ; preds = %26
  br label %34

34:                                               ; preds = %33, %3
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = call i32 @fstatvfs64(i32 noundef %35, ptr noundef %8) #4
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %41

38:                                               ; preds = %34
  %39 = call ptr @__errno_location() #5
  %40 = load i32, ptr %39, align 4, !tbaa !5
  store i32 %40, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %55

41:                                               ; preds = %34
  %42 = getelementptr inbounds %struct.statvfs, ptr %8, i32 0, i32 9
  %43 = load i64, ptr %42, align 8, !tbaa !11
  %44 = and i64 %43, 1
  %45 = icmp eq i64 %44, 0
  br i1 %45, label %46, label %54

46:                                               ; preds = %41
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = icmp eq i32 %47, 2
  br i1 %48, label %49, label %50

49:                                               ; preds = %46
  br label %52

50:                                               ; preds = %46
  %51 = load i32, ptr %7, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %50, %49
  %53 = phi i32 [ 13, %49 ], [ %51, %50 ]
  store i32 %53, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %55

54:                                               ; preds = %41
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %55

55:                                               ; preds = %54, %52, %38, %30, %24
  call void @llvm.lifetime.end.p0(i64 112, ptr %8) #4
  %56 = load i32, ptr %4, align 4
  ret i32 %56
}

; Function Attrs: nounwind
declare i32 @statvfs64(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind
declare i32 @fstatvfs64(i32 noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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 #4 = { nounwind }
attributes #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 72}
!12 = !{!"statvfs", !13, i64 0, !13, 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, !7, i64 88}
!13 = !{!"long", !7, 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"

%struct.statvfs = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, [6 x i32] }

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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #1

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

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @osal_check_fs_rdonly(i32 noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = alloca %struct.statvfs, align 8
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %4) #4
  %.not = icmp eq i32 %2, 2
  br i1 %.not, label %16, label %5

5:                                                ; preds = %3
  %6 = call i32 @statvfs64(ptr noundef %1, ptr noundef nonnull %4) #4
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %13

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %4, i64 72
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = and i64 %10, 1
  %.not10 = icmp eq i64 %11, 0
  %12 = select i1 %.not10, i32 %2, i32 0
  br label %27

13:                                               ; preds = %5
  %14 = tail call ptr @__errno_location() #5
  %15 = load i32, ptr %14, align 4, !tbaa !10
  %.not8 = icmp eq i32 %15, 2
  br i1 %.not8, label %16, label %27

16:                                               ; preds = %13, %3
  %17 = call i32 @fstatvfs64(i32 noundef %0, ptr noundef nonnull %4) #4
  %.not9 = icmp eq i32 %17, 0
  br i1 %.not9, label %21, label %18

18:                                               ; preds = %16
  %19 = tail call ptr @__errno_location() #5
  %20 = load i32, ptr %19, align 4, !tbaa !10
  br label %27

21:                                               ; preds = %16
  %22 = getelementptr inbounds i8, ptr %4, i64 72
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = and i64 %23, 1
  %25 = icmp eq i64 %24, 0
  %26 = select i1 %.not, i32 13, i32 %2
  %spec.select = select i1 %25, i32 %26, i32 0
  br label %27

27:                                               ; preds = %21, %13, %18, %8
  %.0 = phi i32 [ %12, %8 ], [ %20, %18 ], [ %15, %13 ], [ %spec.select, %21 ]
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %4) #4
  ret i32 %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @statvfs64(ptr nocapture noundef readonly, ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fstatvfs64(i32 noundef, ptr nocapture noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nofree 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 #3 = { 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 #4 = { nounwind }
attributes #5 = { 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, !7, i64 72}
!6 = !{!"statvfs", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !8, i64 88}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !8, i64 0}


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