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

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

11:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %50

12:                                               ; preds = %1
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %13, ptr %5, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %44, %12
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = icmp ne i8 %16, 0
  br i1 %17, label %18, label %47

18:                                               ; preds = %14
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = sext i8 %20 to i32
  %22 = icmp eq i32 %21, 92
  br i1 %22, label %23, label %31

23:                                               ; preds = %18
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i32 1
  store ptr %25, ptr %5, align 8, !tbaa !5
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = icmp ne i8 %27, 0
  br i1 %28, label %30, label %29

29:                                               ; preds = %23
  br label %47

30:                                               ; preds = %23
  br label %43

31:                                               ; preds = %18
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load i8, ptr %32, align 1, !tbaa !9
  %34 = sext i8 %33 to i32
  %35 = icmp eq i32 %34, 44
  br i1 %35, label %36, label %42

36:                                               ; preds = %31
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 0, ptr %37, align 1, !tbaa !9
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i64 1
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %39, ptr %40, align 8, !tbaa !5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %41, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %50

42:                                               ; preds = %31
  br label %43

43:                                               ; preds = %42, %30
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i32 1
  store ptr %46, ptr %5, align 8, !tbaa !5
  br label %14, !llvm.loop !10

47:                                               ; preds = %29, %14
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr null, ptr %48, align 8, !tbaa !5
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %49, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %50

50:                                               ; preds = %47, %36, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %51 = load ptr, ptr %2, align 8
  ret ptr %51
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; 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 ptr @ovl_next_opt(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %12, label %.preheader

.preheader:                                       ; preds = %1, %10
  %.0 = phi ptr [ %11, %10 ], [ %2, %1 ]
  %4 = load i8, ptr %.0, align 1, !tbaa !9
  switch i8 %4, label %10 [
    i8 0, label %.sink.split
    i8 92, label %5
    i8 44, label %8
  ]

5:                                                ; preds = %.preheader
  %6 = getelementptr inbounds i8, ptr %.0, i64 1
  %7 = load i8, ptr %6, align 1, !tbaa !9
  %.not20 = icmp eq i8 %7, 0
  br i1 %.not20, label %.sink.split, label %10

8:                                                ; preds = %.preheader
  store i8 0, ptr %.0, align 1, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %.0, i64 1
  br label %.sink.split

10:                                               ; preds = %.preheader, %5
  %.1 = phi ptr [ %6, %5 ], [ %.0, %.preheader ]
  %11 = getelementptr inbounds i8, ptr %.1, i64 1
  br label %.preheader, !llvm.loop !10

.sink.split:                                      ; preds = %5, %.preheader, %8
  %.sink = phi ptr [ %9, %8 ], [ null, %.preheader ], [ null, %5 ]
  store ptr %.sink, ptr %0, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %.sink.split, %1
  ret ptr %2
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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