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

; 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.XSearchEntry = type { [2048 x i8], [2048 x i8], [256 x i8], [16 x i8], [2048 x i8], i32, i32, i64, i32, i32, i64, i64, i64, ptr }
%struct.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }

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

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

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

14:                                               ; preds = %4
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.XSearchEntry, ptr %15, i32 0, i32 2
  %17 = getelementptr inbounds [256 x i8], ptr %16, i64 0, i64 0
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = call i64 @xstrncpy(ptr noundef %17, i64 noundef 256, ptr noundef %18)
  br label %20

20:                                               ; preds = %14, %4
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %29

23:                                               ; preds = %20
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.XSearchEntry, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds [2048 x i8], ptr %25, i64 0, i64 0
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = call i64 @xstrncpy(ptr noundef %26, i64 noundef 2048, ptr noundef %27)
  br label %29

29:                                               ; preds = %23, %20
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %77

32:                                               ; preds = %29
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.XSearchEntry, ptr %33, i32 0, i32 3
  %35 = getelementptr inbounds [16 x i8], ptr %34, i64 0, i64 0
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.stat, ptr %36, i32 0, i32 3
  %38 = load i32, ptr %37, align 8, !tbaa !9
  %39 = call i32 @XPath_ModeToPerm(ptr noundef %35, i64 noundef 16, i32 noundef %38)
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.stat, ptr %40, i32 0, i32 3
  %42 = load i32, ptr %41, align 8, !tbaa !9
  %43 = call i32 @XFile_GetType(i32 noundef %42)
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.XSearchEntry, ptr %44, i32 0, i32 5
  store i32 %43, ptr %45, align 8, !tbaa !14
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.stat, ptr %46, i32 0, i32 2
  %48 = load i64, ptr %47, align 8, !tbaa !16
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.XSearchEntry, ptr %49, i32 0, i32 7
  store i64 %48, ptr %50, align 8, !tbaa !17
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.stat, ptr %51, i32 0, i32 12
  %53 = getelementptr inbounds %struct.timespec, ptr %52, i32 0, i32 0
  %54 = load i64, ptr %53, align 8, !tbaa !18
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.XSearchEntry, ptr %55, i32 0, i32 10
  store i64 %54, ptr %56, align 8, !tbaa !19
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.stat, ptr %57, i32 0, i32 8
  %59 = load i64, ptr %58, align 8, !tbaa !20
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.XSearchEntry, ptr %60, i32 0, i32 11
  store i64 %59, ptr %61, align 8, !tbaa !21
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.stat, ptr %62, i32 0, i32 5
  %64 = load i32, ptr %63, align 8, !tbaa !22
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.XSearchEntry, ptr %65, i32 0, i32 8
  store i32 %64, ptr %66, align 8, !tbaa !23
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.stat, ptr %67, i32 0, i32 4
  %69 = load i32, ptr %68, align 4, !tbaa !24
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.XSearchEntry, ptr %70, i32 0, i32 9
  store i32 %69, ptr %71, align 4, !tbaa !25
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.stat, ptr %72, i32 0, i32 3
  %74 = load i32, ptr %73, align 8, !tbaa !9
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.XSearchEntry, ptr %75, i32 0, i32 6
  store i32 %74, ptr %76, align 4, !tbaa !26
  br label %77

77:                                               ; preds = %32, %29
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.XSearchEntry, ptr %78, i32 0, i32 5
  %80 = load i32, ptr %79, align 8, !tbaa !14
  %81 = icmp eq i32 %80, 16
  br i1 %81, label %82, label %112

82:                                               ; preds = %77
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = icmp ne ptr %83, null
  br i1 %84, label %85, label %112

85:                                               ; preds = %82
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = icmp ne ptr %86, null
  br i1 %87, label %88, label %112

88:                                               ; preds = %85
  call void @llvm.lifetime.start.p0(i64 2048, ptr %9) #4
  %89 = getelementptr inbounds [2048 x i8], ptr %9, i64 0, i64 0
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = load ptr, ptr %6, align 8, !tbaa !5
  %92 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %89, i64 noundef 2048, ptr noundef @.str, ptr noundef %90, ptr noundef %91)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %93 = getelementptr inbounds [2048 x i8], ptr %9, i64 0, i64 0
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.XSearchEntry, ptr %94, i32 0, i32 1
  %96 = getelementptr inbounds [2048 x i8], ptr %95, i64 0, i64 0
  %97 = call i64 @readlink(ptr noundef %93, ptr noundef %96, i64 noundef 2047) #4
  %98 = trunc i64 %97 to i32
  store i32 %98, ptr %10, align 4, !tbaa !27
  %99 = load i32, ptr %10, align 4, !tbaa !27
  %100 = icmp slt i32 %99, 0
  br i1 %100, label %101, label %102

101:                                              ; preds = %88
  store i32 0, ptr %10, align 4, !tbaa !27
  br label %102

102:                                              ; preds = %101, %88
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.XSearchEntry, ptr %103, i32 0, i32 1
  %105 = load i32, ptr %10, align 4, !tbaa !27
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [2048 x i8], ptr %104, i64 0, i64 %106
  store i8 0, ptr %107, align 1, !tbaa !28
  %108 = getelementptr inbounds [2048 x i8], ptr %9, i64 0, i64 0
  %109 = call ptr @realpath(ptr noundef %108, ptr noundef null) #4
  %110 = load ptr, ptr %5, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.XSearchEntry, ptr %110, i32 0, i32 13
  store ptr %109, ptr %111, align 8, !tbaa !29
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 2048, ptr %9) #4
  br label %112

112:                                              ; preds = %102, %85, %82, %77
  ret void
}

declare i64 @xstrncpy(ptr noundef, i64 noundef, ptr noundef) #1

declare i32 @XPath_ModeToPerm(ptr noundef, i64 noundef, i32 noundef) #1

declare i32 @XFile_GetType(i32 noundef) #1

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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, !12, i64 24}
!10 = !{!"stat", !11, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !13, i64 72, !13, i64 88, !13, i64 104, !7, i64 120}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"timespec", !11, i64 0, !11, i64 8}
!14 = !{!15, !12, i64 6416}
!15 = !{!"XSearchEntry", !7, i64 0, !7, i64 2048, !7, i64 4096, !7, i64 4352, !7, i64 4368, !12, i64 6416, !12, i64 6420, !11, i64 6424, !12, i64 6432, !12, i64 6436, !11, i64 6440, !11, i64 6448, !11, i64 6456, !6, i64 6464}
!16 = !{!10, !11, i64 16}
!17 = !{!15, !11, i64 6424}
!18 = !{!10, !11, i64 88}
!19 = !{!15, !11, i64 6440}
!20 = !{!10, !11, i64 48}
!21 = !{!15, !11, i64 6448}
!22 = !{!10, !12, i64 32}
!23 = !{!15, !12, i64 6432}
!24 = !{!10, !12, i64 28}
!25 = !{!15, !12, i64 6436}
!26 = !{!15, !12, i64 6420}
!27 = !{!12, !12, i64 0}
!28 = !{!7, !7, i64 0}
!29 = !{!15, !6, i64 6464}


; 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 [5 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @XSearch_CreateEntry(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef readonly %3) local_unnamed_addr #0 {
  %5 = alloca [2048 x i8], align 16
  tail call void @XSearch_InitEntry(ptr noundef %0)
  %6 = icmp ne ptr %1, null
  br i1 %6, label %7, label %10

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 4096
  %9 = tail call i64 @xstrncpy(ptr noundef nonnull %8, i64 noundef 256, ptr noundef nonnull %1) #5
  br label %10

10:                                               ; preds = %7, %4
  %11 = icmp ne ptr %2, null
  br i1 %11, label %12, label %14

12:                                               ; preds = %10
  %13 = tail call i64 @xstrncpy(ptr noundef %0, i64 noundef 2048, ptr noundef nonnull %2) #5
  br label %14

14:                                               ; preds = %12, %10
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %._crit_edge, label %15

._crit_edge:                                      ; preds = %14
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 6416
  %.pre = load i32, ptr %.phi.trans.insert, align 8, !tbaa !5
  br label %38

15:                                               ; preds = %14
  %16 = getelementptr inbounds i8, ptr %0, i64 4352
  %17 = getelementptr inbounds i8, ptr %3, i64 24
  %18 = load i32, ptr %17, align 8, !tbaa !12
  %19 = tail call i32 @XPath_ModeToPerm(ptr noundef nonnull %16, i64 noundef 16, i32 noundef %18) #5
  %20 = load i32, ptr %17, align 8, !tbaa !12
  %21 = tail call i32 @XFile_GetType(i32 noundef %20) #5
  %22 = getelementptr inbounds i8, ptr %0, i64 6416
  store i32 %21, ptr %22, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %3, i64 16
  %24 = load i64, ptr %23, align 8, !tbaa !15
  %25 = getelementptr inbounds i8, ptr %0, i64 6424
  store i64 %24, ptr %25, align 8, !tbaa !16
  %26 = getelementptr inbounds i8, ptr %3, i64 88
  %27 = load i64, ptr %26, align 8, !tbaa !17
  %28 = getelementptr inbounds i8, ptr %0, i64 6440
  store i64 %27, ptr %28, align 8, !tbaa !18
  %29 = getelementptr inbounds i8, ptr %3, i64 48
  %30 = load i64, ptr %29, align 8, !tbaa !19
  %31 = getelementptr inbounds i8, ptr %0, i64 6448
  store i64 %30, ptr %31, align 8, !tbaa !20
  %32 = getelementptr inbounds i8, ptr %0, i64 6432
  %33 = getelementptr inbounds i8, ptr %3, i64 28
  %34 = load <2 x i32>, ptr %33, align 4, !tbaa !21
  %35 = shufflevector <2 x i32> %34, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
  store <2 x i32> %35, ptr %32, align 8, !tbaa !21
  %36 = load i32, ptr %17, align 8, !tbaa !12
  %37 = getelementptr inbounds i8, ptr %0, i64 6420
  store i32 %36, ptr %37, align 4, !tbaa !22
  br label %38

38:                                               ; preds = %._crit_edge, %15
  %39 = phi i32 [ %.pre, %._crit_edge ], [ %21, %15 ]
  %40 = icmp eq i32 %39, 16
  %or.cond = and i1 %6, %40
  %or.cond3 = and i1 %11, %or.cond
  br i1 %or.cond3, label %41, label %50

41:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %5) #5
  %42 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %5, i64 noundef 2048, ptr noundef nonnull @.str, ptr noundef nonnull %2, ptr noundef nonnull %1) #5
  %43 = getelementptr inbounds i8, ptr %0, i64 2048
  %44 = call i64 @readlink(ptr noundef nonnull %5, ptr noundef nonnull %43, i64 noundef 2047) #5
  %45 = trunc i64 %44 to i32
  %spec.store.select = call i32 @llvm.smax.i32(i32 %45, i32 0)
  %46 = zext nneg i32 %spec.store.select to i64
  %47 = getelementptr inbounds [2048 x i8], ptr %43, i64 0, i64 %46
  store i8 0, ptr %47, align 1, !tbaa !23
  %48 = call ptr @realpath(ptr noundef nonnull %5, ptr noundef null) #5
  %49 = getelementptr inbounds i8, ptr %0, i64 6464
  store ptr %48, ptr %49, align 8, !tbaa !24
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %5) #5
  br label %50

50:                                               ; preds = %41, %38
  ret void
}

declare i64 @xstrncpy(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

declare i32 @XPath_ModeToPerm(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @XFile_GetType(i32 noundef) local_unnamed_addr #1

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

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

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 = { "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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, !9, i64 6416}
!6 = !{!"XSearchEntry", !7, i64 0, !7, i64 2048, !7, i64 4096, !7, i64 4352, !7, i64 4368, !9, i64 6416, !9, i64 6420, !10, i64 6424, !9, i64 6432, !9, i64 6436, !10, i64 6440, !10, i64 6448, !10, i64 6456, !11, i64 6464}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !9, i64 24}
!13 = !{!"stat", !10, i64 0, !10, i64 8, !10, i64 16, !9, i64 24, !9, i64 28, !9, i64 32, !9, i64 36, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !14, i64 72, !14, i64 88, !14, i64 104, !7, i64 120}
!14 = !{!"timespec", !10, i64 0, !10, i64 8}
!15 = !{!13, !10, i64 16}
!16 = !{!6, !10, i64 6424}
!17 = !{!13, !10, i64 88}
!18 = !{!6, !10, i64 6440}
!19 = !{!13, !10, i64 48}
!20 = !{!6, !10, i64 6448}
!21 = !{!9, !9, i64 0}
!22 = !{!6, !9, i64 6420}
!23 = !{!7, !7, i64 0}
!24 = !{!6, !11, i64 6464}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass