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

@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1

; 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
declare dso_local zeroext i8 @XPath_Exists(ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @XDir_Create(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca [2048 x i8], align 16
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call zeroext i8 @XPath_Exists(ptr noundef %11)
  %13 = icmp ne i8 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  store i32 1, ptr %3, align 4
  br label %67

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 2048, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %16 = getelementptr inbounds [2048 x i8], ptr %6, i64 0, i64 0
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %16, i64 noundef 2048, ptr noundef @.str.7, ptr noundef %17)
  store i64 %18, ptr %8, align 8, !tbaa !11
  %19 = load i64, ptr %8, align 8, !tbaa !11
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %23, label %21

21:                                               ; preds = %15
  %22 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %22, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %66

23:                                               ; preds = %15
  %24 = load i64, ptr %8, align 8, !tbaa !11
  %25 = sub i64 %24, 1
  %26 = getelementptr inbounds [2048 x i8], ptr %6, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !13
  %28 = sext i8 %27 to i32
  %29 = icmp eq i32 %28, 47
  br i1 %29, label %30, label %34

30:                                               ; preds = %23
  %31 = load i64, ptr %8, align 8, !tbaa !11
  %32 = sub i64 %31, 1
  %33 = getelementptr inbounds [2048 x i8], ptr %6, i64 0, i64 %32
  store i8 0, ptr %33, align 1, !tbaa !13
  br label %34

34:                                               ; preds = %30, %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store ptr null, ptr %10, align 8, !tbaa !5
  %35 = getelementptr inbounds [2048 x i8], ptr %6, i64 0, i64 0
  %36 = getelementptr inbounds i8, ptr %35, i64 1
  store ptr %36, ptr %10, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %58, %34
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = load i8, ptr %38, align 1, !tbaa !13
  %40 = icmp ne i8 %39, 0
  br i1 %40, label %41, label %61

41:                                               ; preds = %37
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = load i8, ptr %42, align 1, !tbaa !13
  %44 = sext i8 %43 to i32
  %45 = icmp eq i32 %44, 47
  br i1 %45, label %46, label %57

46:                                               ; preds = %41
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  store i8 0, ptr %47, align 1, !tbaa !13
  %48 = getelementptr inbounds [2048 x i8], ptr %6, i64 0, i64 0
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = call i32 @XDir_Make(ptr noundef %48, i32 noundef %49)
  store i32 %50, ptr %7, align 4, !tbaa !9
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = icmp sle i32 %51, 0
  br i1 %52, label %53, label %55

53:                                               ; preds = %46
  %54 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %54, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %65

55:                                               ; preds = %46
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  store i8 47, ptr %56, align 1, !tbaa !13
  br label %57

57:                                               ; preds = %55, %41
  br label %58

58:                                               ; preds = %57
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i32 1
  store ptr %60, ptr %10, align 8, !tbaa !5
  br label %37, !llvm.loop !14

61:                                               ; preds = %37
  %62 = getelementptr inbounds [2048 x i8], ptr %6, i64 0, i64 0
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = call i32 @XDir_Make(ptr noundef %62, i32 noundef %63)
  store i32 %64, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %65

65:                                               ; preds = %61, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %66

66:                                               ; preds = %65, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 2048, ptr %6) #3
  br label %67

67:                                               ; preds = %66, %14
  %68 = load i32, ptr %3, align 4
  ret i32 %68
}

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 = { "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 }

!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 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @XPath_Exists(ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @XDir_Create(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = alloca [2048 x i8], align 16
  %4 = tail call zeroext i8 @XPath_Exists(ptr noundef %0)
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %5, label %21

5:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %3) #3
  %6 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %3, i64 noundef 2048, ptr noundef nonnull @.str.7, ptr noundef %0) #3
  %.not19 = icmp eq i64 %6, 0
  br i1 %.not19, label %.loopexit, label %7

7:                                                ; preds = %5
  %8 = add i64 %6, -1
  %9 = getelementptr inbounds [2048 x i8], ptr %3, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = icmp eq i8 %10, 47
  br i1 %11, label %12, label %.preheader

12:                                               ; preds = %7
  store i8 0, ptr %9, align 1, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %12, %7
  br label %13

13:                                               ; preds = %.backedge, %.preheader
  %.pn = phi ptr [ %3, %.preheader ], [ %.0, %.backedge ]
  %.0 = getelementptr inbounds i8, ptr %.pn, i64 1
  %14 = load i8, ptr %.0, align 1, !tbaa !5
  switch i8 %14, label %.backedge [
    i8 0, label %19
    i8 47, label %15
  ]

.backedge:                                        ; preds = %13, %18
  br label %13, !llvm.loop !8

15:                                               ; preds = %13
  store i8 0, ptr %.0, align 1, !tbaa !5
  %16 = call i32 @XDir_Make(ptr noundef nonnull %3, i32 noundef %1)
  %17 = icmp slt i32 %16, 1
  br i1 %17, label %.loopexit, label %18

18:                                               ; preds = %15
  store i8 47, ptr %.0, align 1, !tbaa !5
  br label %.backedge

19:                                               ; preds = %13
  %20 = call i32 @XDir_Make(ptr noundef nonnull %3, i32 noundef %1)
  br label %.loopexit

.loopexit:                                        ; preds = %15, %19, %5
  %.1 = phi i32 [ 0, %5 ], [ %20, %19 ], [ %16, %15 ]
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %3) #3
  br label %21

21:                                               ; preds = %2, %.loopexit
  %.2 = phi i32 [ %.1, %.loopexit ], [ 1, %2 ]
  ret i32 %.2
}

attributes #0 = { mustprogress 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 = { "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 }

!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"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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