; LLVM IR from kmxz/overlayfs-tools :: mount (ovl_get_dirs)

; 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_config = type { ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [33 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @ovl_get_dirs(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca [4096 x i8], align 16
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4096, ptr %12) #6
  call void @llvm.memset.p0.i64(ptr align 16 %12, i8 0, i64 4096, i1 false)
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ovl_config, ptr %14, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %38

18:                                               ; preds = %5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ovl_config, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds [4096 x i8], ptr %12, i64 0, i64 0
  %23 = call ptr @realpath(ptr noundef %21, ptr noundef %22) #6
  %24 = icmp ne ptr %23, null
  br i1 %24, label %32, label %25

25:                                               ; preds = %18
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ovl_config, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = call ptr @__errno_location() #7
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = call ptr @strerror(i32 noundef %30) #6
  call void (ptr, ...) @print_err(ptr noundef @.str, ptr noundef %28, ptr noundef %31)
  br label %97

32:                                               ; preds = %18
  %33 = getelementptr inbounds [4096 x i8], ptr %12, i64 0, i64 0
  %34 = call ptr @sstrdup(ptr noundef %33)
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %34, ptr %35, align 8, !tbaa !5
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  call void (ptr, ...) @print_debug(ptr noundef @.str.1, ptr noundef %37)
  br label %38

38:                                               ; preds = %32, %5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ovl_config, ptr %39, i32 0, i32 2
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %63

43:                                               ; preds = %38
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ovl_config, ptr %44, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !13
  %47 = getelementptr inbounds [4096 x i8], ptr %12, i64 0, i64 0
  %48 = call ptr @realpath(ptr noundef %46, ptr noundef %47) #6
  %49 = icmp ne ptr %48, null
  br i1 %49, label %57, label %50

50:                                               ; preds = %43
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ovl_config, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !13
  %54 = call ptr @__errno_location() #7
  %55 = load i32, ptr %54, align 4, !tbaa !11
  %56 = call ptr @strerror(i32 noundef %55) #6
  call void (ptr, ...) @print_err(ptr noundef @.str.2, ptr noundef %53, ptr noundef %56)
  br label %88

57:                                               ; preds = %43
  %58 = getelementptr inbounds [4096 x i8], ptr %12, i64 0, i64 0
  %59 = call ptr @sstrdup(ptr noundef %58)
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %59, ptr %60, align 8, !tbaa !5
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = load ptr, ptr %61, align 8, !tbaa !5
  call void (ptr, ...) @print_debug(ptr noundef @.str.3, ptr noundef %62)
  br label %63

63:                                               ; preds = %57, %38
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.ovl_config, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !14
  %67 = icmp ne ptr %66, null
  br i1 %67, label %68, label %78

68:                                               ; preds = %63
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.ovl_config, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !14
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = call i32 @ovl_resolve_lowerdirs(ptr noundef %71, ptr noundef %72, ptr noundef %73)
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %77

76:                                               ; preds = %68
  br label %79

77:                                               ; preds = %68
  br label %78

78:                                               ; preds = %77, %63
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %98

79:                                               ; preds = %76
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  %81 = load ptr, ptr %80, align 8, !tbaa !5
  %82 = icmp ne ptr %81, null
  br i1 %82, label %83, label %86

83:                                               ; preds = %79
  %84 = load ptr, ptr %11, align 8, !tbaa !5
  %85 = load ptr, ptr %84, align 8, !tbaa !5
  call void @free(ptr noundef %85) #6
  br label %86

86:                                               ; preds = %83, %79
  %87 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr null, ptr %87, align 8, !tbaa !5
  br label %88

88:                                               ; preds = %86, %50
  %89 = load ptr, ptr %10, align 8, !tbaa !5
  %90 = load ptr, ptr %89, align 8, !tbaa !5
  %91 = icmp ne ptr %90, null
  br i1 %91, label %92, label %95

92:                                               ; preds = %88
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  %94 = load ptr, ptr %93, align 8, !tbaa !5
  call void @free(ptr noundef %94) #6
  br label %95

95:                                               ; preds = %92, %88
  %96 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr null, ptr %96, align 8, !tbaa !5
  br label %97

97:                                               ; preds = %95, %25
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %98

98:                                               ; preds = %97, %78
  call void @llvm.lifetime.end.p0(i64 4096, ptr %12) #6
  %99 = load i32, ptr %6, align 4
  ret i32 %99
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

declare void @print_err(ptr noundef, ...) #4

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

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

declare ptr @sstrdup(ptr noundef) #4

declare void @print_debug(ptr noundef, ...) #4

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { "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 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 #6 = { nounwind }
attributes #7 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"ovl_config", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 16}
!14 = !{!10, !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"

@.str = external hidden unnamed_addr constant [33 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @ovl_get_dirs(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2, ptr nocapture noundef %3, ptr nocapture noundef %4) local_unnamed_addr #0 {
  %6 = alloca [4096 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %6) #8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4096) %6, i8 0, i64 4096, i1 false)
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %18, label %9

9:                                                ; preds = %5
  %10 = call ptr @realpath(ptr noundef nonnull %8, ptr noundef nonnull %6) #8
  %.not25 = icmp eq ptr %10, null
  br i1 %.not25, label %11, label %16

11:                                               ; preds = %9
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = tail call ptr @__errno_location() #9
  %14 = load i32, ptr %13, align 4, !tbaa !10
  %15 = call ptr @strerror(i32 noundef %14) #8
  call void (ptr, ...) @print_err(ptr noundef nonnull @.str, ptr noundef %12, ptr noundef %15) #8
  br label %42

16:                                               ; preds = %9
  %17 = call ptr @sstrdup(ptr noundef nonnull %6) #8
  store ptr %17, ptr %3, align 8, !tbaa !12
  call void (ptr, ...) @print_debug(ptr noundef nonnull @.str.1, ptr noundef %17) #8
  br label %18

18:                                               ; preds = %16, %5
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %.not26 = icmp eq ptr %20, null
  br i1 %.not26, label %30, label %21

21:                                               ; preds = %18
  %22 = call ptr @realpath(ptr noundef nonnull %20, ptr noundef nonnull %6) #8
  %.not27 = icmp eq ptr %22, null
  br i1 %.not27, label %23, label %28

23:                                               ; preds = %21
  %24 = load ptr, ptr %19, align 8, !tbaa !13
  %25 = tail call ptr @__errno_location() #9
  %26 = load i32, ptr %25, align 4, !tbaa !10
  %27 = call ptr @strerror(i32 noundef %26) #8
  call void (ptr, ...) @print_err(ptr noundef nonnull @.str.2, ptr noundef %24, ptr noundef %27) #8
  br label %38

28:                                               ; preds = %21
  %29 = call ptr @sstrdup(ptr noundef nonnull %6) #8
  store ptr %29, ptr %4, align 8, !tbaa !12
  call void (ptr, ...) @print_debug(ptr noundef nonnull @.str.3, ptr noundef %29) #8
  br label %30

30:                                               ; preds = %28, %18
  %31 = load ptr, ptr %0, align 8, !tbaa !14
  %.not28 = icmp eq ptr %31, null
  br i1 %.not28, label %42, label %32

32:                                               ; preds = %30
  %33 = call i32 @ovl_resolve_lowerdirs(ptr noundef nonnull %31, ptr noundef %1, ptr noundef %2)
  %.not29 = icmp eq i32 %33, 0
  br i1 %.not29, label %42, label %34

34:                                               ; preds = %32
  %35 = load ptr, ptr %4, align 8, !tbaa !12
  %.not30 = icmp eq ptr %35, null
  br i1 %.not30, label %37, label %36

36:                                               ; preds = %34
  call void @free(ptr noundef nonnull %35) #8
  br label %37

37:                                               ; preds = %36, %34
  store ptr null, ptr %4, align 8, !tbaa !12
  br label %38

38:                                               ; preds = %37, %23
  %39 = load ptr, ptr %3, align 8, !tbaa !12
  %.not31 = icmp eq ptr %39, null
  br i1 %.not31, label %41, label %40

40:                                               ; preds = %38
  call void @free(ptr noundef nonnull %39) #8
  br label %41

41:                                               ; preds = %40, %38
  store ptr null, ptr %3, align 8, !tbaa !12
  br label %42

42:                                               ; preds = %11, %41, %30, %32
  %.0 = phi i32 [ 0, %32 ], [ 0, %30 ], [ -1, %41 ], [ -1, %11 ]
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %6) #8
  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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

declare void @print_err(ptr noundef, ...) local_unnamed_addr #4

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #5

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

declare ptr @sstrdup(ptr noundef) local_unnamed_addr #4

declare void @print_debug(ptr noundef, ...) local_unnamed_addr #4

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #7

; 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { "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 "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 #6 = { 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 #7 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #8 = { nounwind }
attributes #9 = { 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 8}
!6 = !{!"ovl_config", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 16}
!14 = !{!6, !7, i64 0}


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