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

; 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"

; Function Attrs: nounwind uwtable
define dso_local i32 @ovl_split_lowerdirs(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 1, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %6, ptr %5, align 8, !tbaa !5
  store ptr %6, ptr %4, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %34, %1
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = load i8, ptr %8, align 1, !tbaa !11
  %10 = sext i8 %9 to i32
  %11 = icmp eq i32 %10, 92
  br i1 %11, label %12, label %15

12:                                               ; preds = %7
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i32 1
  store ptr %14, ptr %4, align 8, !tbaa !5
  br label %25

15:                                               ; preds = %7
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = sext i8 %17 to i32
  %19 = icmp eq i32 %18, 58
  br i1 %19, label %20, label %24

20:                                               ; preds = %15
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 0, ptr %21, align 1, !tbaa !11
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = add i32 %22, 1
  store i32 %23, ptr %3, align 4, !tbaa !9
  br label %34

24:                                               ; preds = %15
  br label %25

25:                                               ; preds = %24, %12
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load i8, ptr %26, align 1, !tbaa !11
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %27, ptr %28, align 1, !tbaa !11
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load i8, ptr %29, align 1, !tbaa !11
  %31 = icmp ne i8 %30, 0
  br i1 %31, label %33, label %32

32:                                               ; preds = %25
  br label %39

33:                                               ; preds = %25
  br label %34

34:                                               ; preds = %33, %20
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i32 1
  store ptr %36, ptr %4, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i32 1
  store ptr %38, ptr %5, align 8, !tbaa !5
  br label %7

39:                                               ; preds = %32
  %40 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %40
}

; 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 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 }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !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"

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local i32 @ovl_split_lowerdirs(ptr nocapture noundef %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %11, %1
  %.012 = phi i32 [ 1, %1 ], [ %.113, %11 ]
  %.011 = phi ptr [ %0, %1 ], [ %12, %11 ]
  %.0 = phi ptr [ %0, %1 ], [ %13, %11 ]
  %3 = load i8, ptr %.011, align 1, !tbaa !5
  switch i8 %3, label %8 [
    i8 92, label %4
    i8 58, label %6
  ]

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %.011, i64 1
  %.pre = load i8, ptr %5, align 1, !tbaa !5
  br label %8

6:                                                ; preds = %2
  store i8 0, ptr %.0, align 1, !tbaa !5
  %7 = add i32 %.012, 1
  br label %11

8:                                                ; preds = %2, %4
  %9 = phi i8 [ %.pre, %4 ], [ %3, %2 ]
  %.1 = phi ptr [ %5, %4 ], [ %.011, %2 ]
  store i8 %9, ptr %.0, align 1, !tbaa !5
  %10 = load i8, ptr %.1, align 1, !tbaa !5
  %.not = icmp eq i8 %10, 0
  br i1 %.not, label %14, label %11

11:                                               ; preds = %8, %6
  %.113 = phi i32 [ %.012, %8 ], [ %7, %6 ]
  %.2 = phi ptr [ %.1, %8 ], [ %.011, %6 ]
  %12 = getelementptr inbounds i8, ptr %.2, i64 1
  %13 = getelementptr inbounds i8, ptr %.0, i64 1
  br label %2

14:                                               ; preds = %8
  ret i32 %.012
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass