; LLVM IR from kmxz/overlayfs-tools :: fsck (main)

; 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.ovl_fs = type { %struct.ovl_layer, ptr, i32, %struct.ovl_layer }
%struct.ovl_layer = type { ptr, i32, i32, i32, i32 }

@ofs = external dso_local global %struct.ovl_fs, align 8
@flags = external dso_local global i32, align 4
@status = external dso_local global i32, align 4
@program_name = external global ptr, align 8

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

15:                                               ; preds = %2
  br label %38

16:                                               ; preds = %2
  %17 = call i32 @ovl_check_mount(ptr noundef @ofs, ptr noundef %6)
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  br label %38

20:                                               ; preds = %16
  %21 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %22 = trunc i8 %21 to i1
  br i1 %22, label %23, label %28

23:                                               ; preds = %20
  %24 = load i32, ptr @flags, align 4, !tbaa !5
  %25 = and i32 %24, 16
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  call void @set_abort(ptr noundef @status)
  br label %37

28:                                               ; preds = %23, %20
  %29 = call i32 @ovl_basic_check(ptr noundef @ofs)
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %28
  br label %38

32:                                               ; preds = %28
  %33 = call i32 @ovl_scan_fix(ptr noundef @ofs)
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %32
  br label %38

36:                                               ; preds = %32
  br label %37

37:                                               ; preds = %38, %36, %27
  call void @ovl_clean_dirs(ptr noundef @ofs)
  call void @fsck_exit()
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #5
  ret i32 0

38:                                               ; preds = %35, %31, %19, %15
  call void @set_abort(ptr noundef @status)
  br label %37
}

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

; Function Attrs: nounwind
declare ptr @__xpg_basename(ptr noundef) #2

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @set_abort(ptr noundef) #4

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

declare i32 @ovl_scan_fix(ptr noundef) #3

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

; Function Attrs: nounwind uwtable
declare hidden void @fsck_exit() #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 "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 = { inlinehint 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 #5 = { 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 = !{!"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, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}


; 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.ovl_fs = type { %struct.ovl_layer, ptr, i32, %struct.ovl_layer }
%struct.ovl_layer = type { ptr, i32, i32, i32, i32 }

@ofs = external dso_local global %struct.ovl_fs, align 8
@flags = external dso_local local_unnamed_addr global i32, align 4
@status = external dso_local global i32, align 4
@program_name = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #5
  store i8 0, ptr %3, align 1, !tbaa !5
  %4 = load ptr, ptr %1, align 8, !tbaa !9
  %5 = tail call ptr @__xpg_basename(ptr noundef %4) #5
  store ptr %5, ptr @program_name, align 8, !tbaa !9
  tail call void @parse_options(i32 noundef %0, ptr noundef nonnull %1)
  %6 = tail call i32 @ovl_open_dirs(ptr noundef nonnull @ofs)
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %.sink.split

7:                                                ; preds = %2
  %8 = call i32 @ovl_check_mount(ptr noundef nonnull @ofs, ptr noundef nonnull %3) #5
  %.not2 = icmp eq i32 %8, 0
  br i1 %.not2, label %9, label %.sink.split

9:                                                ; preds = %7
  %10 = load i8, ptr %3, align 1, !tbaa !5, !range !11, !noundef !12
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %12, label %15

12:                                               ; preds = %9
  %13 = load i32, ptr @flags, align 4, !tbaa !13
  %14 = and i32 %13, 16
  %.not3 = icmp eq i32 %14, 0
  br i1 %.not3, label %.sink.split, label %15

15:                                               ; preds = %12, %9
  %16 = call i32 @ovl_basic_check(ptr noundef nonnull @ofs)
  %.not4 = icmp eq i32 %16, 0
  br i1 %.not4, label %17, label %.sink.split

17:                                               ; preds = %15
  %18 = call i32 @ovl_scan_fix(ptr noundef nonnull @ofs) #5
  %.not5 = icmp eq i32 %18, 0
  br i1 %.not5, label %19, label %.sink.split

.sink.split:                                      ; preds = %12, %2, %7, %15, %17
  call void @set_abort(ptr noundef nonnull @status)
  br label %19

19:                                               ; preds = %.sink.split, %17
  call void @ovl_clean_dirs(ptr noundef nonnull @ofs)
  call void @fsck_exit()
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #5
  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
declare ptr @__xpg_basename(ptr noundef) local_unnamed_addr #2

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @set_abort(ptr noundef) local_unnamed_addr #4

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

declare i32 @ovl_scan_fix(ptr noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
declare hidden void @fsck_exit() 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 "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 = { inlinehint 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 #5 = { 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 = !{!"_Bool", !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 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}


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