; LLVM IR from kala13x/libxutils :: src/sys (xfs)

; 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.XDir = type { ptr, ptr, ptr, ptr, i8, i8 }

@.str.8 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @xrmdir(ptr noundef) #0

; 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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

declare i64 @xstrncpyf(ptr noundef, i64 noundef, ptr noundef, ...) #5

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

; Function Attrs: nounwind uwtable
declare dso_local void @XDir_Close(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @XDir_Read(ptr noundef, ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @XPath_Remove(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @XDir_Remove(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca %struct.XDir, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call i64 @strlen(ptr noundef %11) #7
  store i64 %12, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 -1, ptr %5, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 40, ptr %6) #6
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = call i32 @XDir_Open(ptr noundef %6, ptr noundef %13)
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %16, label %52

16:                                               ; preds = %1
  br label %17

17:                                               ; preds = %48, %16
  %18 = call i32 @XDir_Read(ptr noundef %6, ptr noundef null, i64 noundef 0)
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %20, label %49

20:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %21 = load i64, ptr %4, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.XDir, ptr %6, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = call i64 @strlen(ptr noundef %23) #7
  %25 = add i64 %21, %24
  %26 = add i64 %25, 2
  store i64 %26, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = call noalias ptr @malloc(i64 noundef %27) #8
  store ptr %28, ptr %8, align 8, !tbaa !5
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %20
  call void @XDir_Close(ptr noundef %6)
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %9, align 4
  br label %46

32:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = load i64, ptr %7, align 8, !tbaa !9
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.XDir, ptr %6, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !13
  %38 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %33, i64 noundef %34, ptr noundef @.str.8, ptr noundef %35, ptr noundef %37)
  store i64 %38, ptr %10, align 8, !tbaa !9
  %39 = load i64, ptr %10, align 8, !tbaa !9
  %40 = icmp ugt i64 %39, 0
  br i1 %40, label %41, label %44

41:                                               ; preds = %32
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = call i32 @XPath_Remove(ptr noundef %42)
  store i32 %43, ptr %5, align 4, !tbaa !11
  br label %44

44:                                               ; preds = %41, %32
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %45) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  store i32 0, ptr %9, align 4
  br label %46

46:                                               ; preds = %44, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  %47 = load i32, ptr %9, align 4
  switch i32 %47, label %54 [
    i32 0, label %48
  ]

48:                                               ; preds = %46
  br label %17, !llvm.loop !15

49:                                               ; preds = %17
  call void @XDir_Close(ptr noundef %6)
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = call i32 @xrmdir(ptr noundef %50)
  br label %52

52:                                               ; preds = %49, %1
  %53 = load i32, ptr %5, align 4, !tbaa !11
  store i32 %53, ptr %2, align 4
  store i32 1, ptr %9, align 4
  br label %54

54:                                               ; preds = %52, %46
  call void @llvm.lifetime.end.p0(i64 40, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  %55 = load i32, ptr %2, align 4
  ret i32 %55
}

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 allocsize(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 willreturn memory(read) "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 = { "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(read) }
attributes #8 = { nounwind allocsize(0) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"XDir", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !7, i64 32, !7, i64 33}
!15 = distinct !{!15, !16}
!16 = !{!"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"

%struct.XDir = type { ptr, ptr, ptr, ptr, i8, i8 }

@.str.8 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @xrmdir(ptr noundef) local_unnamed_addr #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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #4

declare i64 @xstrncpyf(ptr noundef, i64 noundef, ptr noundef, ...) local_unnamed_addr #5

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @XDir_Read(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @XDir_Remove(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca %struct.XDir, align 8
  %3 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #6
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %2) #7
  %4 = call i32 @XDir_Open(ptr noundef nonnull %2, ptr noundef %0)
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.preheader, label %23

.preheader:                                       ; preds = %1
  %6 = call i32 @XDir_Read(ptr noundef nonnull %2, ptr noundef null, i64 noundef 0)
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %8 = getelementptr inbounds i8, ptr %2, i64 8
  %9 = add i64 %3, 2
  br label %10

10:                                               ; preds = %.lr.ph, %19
  %.01522 = phi i32 [ -1, %.lr.ph ], [ %.116, %19 ]
  %11 = load ptr, ptr %8, align 8, !tbaa !5
  %12 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %11) #6
  %13 = add i64 %9, %12
  %14 = call noalias ptr @malloc(i64 noundef %13) #8
  %.not19 = icmp eq ptr %14, null
  br i1 %.not19, label %.thread, label %15

.thread:                                          ; preds = %10
  call void @XDir_Close(ptr noundef nonnull %2)
  br label %23

15:                                               ; preds = %10
  %16 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %14, i64 noundef %13, ptr noundef nonnull @.str.8, ptr noundef %0, ptr noundef %11) #7
  %.not = icmp eq i64 %16, 0
  br i1 %.not, label %19, label %17

17:                                               ; preds = %15
  %18 = call i32 @XPath_Remove(ptr noundef nonnull %14)
  br label %19

19:                                               ; preds = %15, %17
  %.116 = phi i32 [ %18, %17 ], [ %.01522, %15 ]
  call void @free(ptr noundef nonnull %14) #7
  %20 = call i32 @XDir_Read(ptr noundef nonnull %2, ptr noundef null, i64 noundef 0)
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %10, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %19, %.preheader
  %.015.lcssa = phi i32 [ -1, %.preheader ], [ %.116, %19 ]
  call void @XDir_Close(ptr noundef nonnull %2)
  %22 = call i32 @xrmdir(ptr noundef %0)
  br label %23

23:                                               ; preds = %.thread, %1, %._crit_edge
  %.2 = phi i32 [ %.015.lcssa, %._crit_edge ], [ -1, %1 ], [ -1, %.thread ]
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %2) #7
  ret i32 %.2
}

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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #3 = { 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 #4 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { "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 willreturn memory(read) }
attributes #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass