; 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.XSearchCtx = type { %struct.XArray_, %struct.XArray_, i8, i8, i8, i8, i8, ptr, ptr, [2048 x i8], [4096 x i8], i32, i32, i32, i32, i64, i64, i64, i8, ptr, i32 }
%struct.XArray_ = type { ptr, ptr, i32, ptr, i8, i8, i8, i64, i64 }

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @XSearch_ClearCb(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @XSearch_Init(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.XSearchCtx, ptr %5, i32 0, i32 20
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.XSearchCtx, ptr %7, i32 0, i32 19
  store ptr %6, ptr %8, align 8, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.XSearchCtx, ptr %9, i32 0, i32 3
  store i8 0, ptr %10, align 1, !tbaa !14
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.XSearchCtx, ptr %11, i32 0, i32 2
  store i8 0, ptr %12, align 8, !tbaa !15
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.XSearchCtx, ptr %13, i32 0, i32 5
  store i8 0, ptr %14, align 1, !tbaa !16
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.XSearchCtx, ptr %15, i32 0, i32 4
  store i8 0, ptr %16, align 2, !tbaa !17
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.XSearchCtx, ptr %17, i32 0, i32 6
  store i8 0, ptr %18, align 4, !tbaa !18
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.XSearchCtx, ptr %19, i32 0, i32 7
  store ptr null, ptr %20, align 8, !tbaa !19
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.XSearchCtx, ptr %21, i32 0, i32 8
  store ptr null, ptr %22, align 8, !tbaa !20
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.XSearchCtx, ptr %23, i32 0, i32 1
  %25 = call ptr @XArray_InitPool(ptr noundef %24, i64 noundef 0, i64 noundef 0, i8 noundef zeroext 0)
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.XSearchCtx, ptr %26, i32 0, i32 0
  %28 = call ptr @XArray_InitPool(ptr noundef %27, i64 noundef 0, i64 noundef 0, i8 noundef zeroext 0)
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.XSearchCtx, ptr %29, i32 0, i32 0
  %31 = getelementptr inbounds %struct.XArray_, ptr %30, i32 0, i32 1
  store ptr @XSearch_ArrayClearCb, ptr %31, align 8, !tbaa !21
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.XSearchCtx, ptr %32, i32 0, i32 1
  %34 = getelementptr inbounds %struct.XArray_, ptr %33, i32 0, i32 1
  store ptr @XSearch_ClearCb, ptr %34, align 8, !tbaa !22
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.XSearchCtx, ptr %35, i32 0, i32 9
  %37 = getelementptr inbounds [2048 x i8], ptr %36, i64 0, i64 0
  store i8 0, ptr %37, align 8, !tbaa !23
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.XSearchCtx, ptr %38, i32 0, i32 10
  %40 = getelementptr inbounds [4096 x i8], ptr %39, i64 0, i64 0
  store i8 0, ptr %40, align 8, !tbaa !23
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = call i32 @xstrsrc(ptr noundef %41, ptr noundef @.str.1)
  %43 = icmp sge i32 %42, 0
  br i1 %43, label %44, label %49

44:                                               ; preds = %2
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.XSearchCtx, ptr %46, i32 0, i32 1
  %48 = call i64 @xstrsplita(ptr noundef %45, ptr noundef @.str.1, ptr noundef %47, i8 noundef zeroext 0, i8 noundef zeroext 0)
  br label %49

49:                                               ; preds = %44, %2
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.XSearchCtx, ptr %50, i32 0, i32 9
  %52 = getelementptr inbounds [2048 x i8], ptr %51, i64 0, i64 0
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = call i64 @xstrncpy(ptr noundef %52, i64 noundef 2048, ptr noundef %53)
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.XSearchCtx, ptr %55, i32 0, i32 15
  store i64 0, ptr %56, align 8, !tbaa !24
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.XSearchCtx, ptr %57, i32 0, i32 11
  store i32 0, ptr %58, align 8, !tbaa !25
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.XSearchCtx, ptr %59, i32 0, i32 13
  store i32 0, ptr %60, align 8, !tbaa !26
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.XSearchCtx, ptr %61, i32 0, i32 12
  store i32 -1, ptr %62, align 4, !tbaa !27
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.XSearchCtx, ptr %63, i32 0, i32 14
  store i32 -1, ptr %64, align 4, !tbaa !28
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.XSearchCtx, ptr %65, i32 0, i32 16
  store i64 0, ptr %66, align 8, !tbaa !29
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.XSearchCtx, ptr %67, i32 0, i32 17
  store i64 0, ptr %68, align 8, !tbaa !30
  ret void
}

declare ptr @XArray_InitPool(ptr noundef, i64 noundef, i64 noundef, i8 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare hidden void @XSearch_ArrayClearCb(ptr noundef) #1

declare i32 @xstrsrc(ptr noundef, ptr noundef) #0

declare i64 @xstrsplita(ptr noundef, ptr noundef, ptr noundef, i8 noundef zeroext, i8 noundef zeroext) #0

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

!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, !6, i64 6328}
!10 = !{!"XSearchCtx", !11, i64 0, !11, i64 56, !7, i64 112, !7, i64 113, !7, i64 114, !7, i64 115, !7, i64 116, !6, i64 120, !6, i64 128, !7, i64 136, !7, i64 2184, !12, i64 6280, !12, i64 6284, !12, i64 6288, !12, i64 6292, !13, i64 6296, !13, i64 6304, !13, i64 6312, !7, i64 6320, !6, i64 6328, !12, i64 6336}
!11 = !{!"XArray_", !6, i64 0, !6, i64 8, !12, i64 16, !6, i64 24, !7, i64 32, !7, i64 33, !7, i64 34, !13, i64 40, !13, i64 48}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !7, i64 113}
!15 = !{!10, !7, i64 112}
!16 = !{!10, !7, i64 115}
!17 = !{!10, !7, i64 114}
!18 = !{!10, !7, i64 116}
!19 = !{!10, !6, i64 120}
!20 = !{!10, !6, i64 128}
!21 = !{!10, !6, i64 8}
!22 = !{!10, !6, i64 64}
!23 = !{!7, !7, i64 0}
!24 = !{!10, !13, i64 6296}
!25 = !{!10, !12, i64 6280}
!26 = !{!10, !12, i64 6288}
!27 = !{!10, !12, i64 6284}
!28 = !{!10, !12, i64 6292}
!29 = !{!10, !13, i64 6304}
!30 = !{!10, !13, i64 6312}


; 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.1 = external hidden unnamed_addr constant [2 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local void @XSearch_ClearCb(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @XSearch_Init(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 6336
  %4 = getelementptr inbounds i8, ptr %0, i64 6328
  store ptr %3, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 112
  %6 = getelementptr inbounds i8, ptr %0, i64 120
  %7 = getelementptr inbounds i8, ptr %0, i64 56
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(5) %5, i8 0, i64 5, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %6, i8 0, i64 16, i1 false)
  %8 = tail call ptr @XArray_InitPool(ptr noundef nonnull %7, i64 noundef 0, i64 noundef 0, i8 noundef zeroext 0) #3
  %9 = tail call ptr @XArray_InitPool(ptr noundef %0, i64 noundef 0, i64 noundef 0, i8 noundef zeroext 0) #3
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr @XSearch_ArrayClearCb, ptr %10, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr @XSearch_ClearCb, ptr %11, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %0, i64 136
  store i8 0, ptr %12, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %0, i64 2184
  store i8 0, ptr %13, align 8, !tbaa !15
  %14 = tail call i32 @xstrsrc(ptr noundef %1, ptr noundef nonnull @.str.1) #3
  %15 = icmp sgt i32 %14, -1
  br i1 %15, label %16, label %18

16:                                               ; preds = %2
  %17 = tail call i64 @xstrsplita(ptr noundef %1, ptr noundef nonnull @.str.1, ptr noundef nonnull %7, i8 noundef zeroext 0, i8 noundef zeroext 0) #3
  br label %18

18:                                               ; preds = %16, %2
  %19 = tail call i64 @xstrncpy(ptr noundef nonnull %12, i64 noundef 2048, ptr noundef %1) #3
  %20 = getelementptr inbounds i8, ptr %0, i64 6296
  store i64 0, ptr %20, align 8, !tbaa !16
  %21 = getelementptr inbounds i8, ptr %0, i64 6280
  store <4 x i32> <i32 0, i32 -1, i32 0, i32 -1>, ptr %21, align 8, !tbaa !17
  %22 = getelementptr inbounds i8, ptr %0, i64 6304
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %22, i8 0, i64 16, i1 false)
  ret void
}

declare ptr @XArray_InitPool(ptr noundef, i64 noundef, i64 noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @XSearch_ArrayClearCb(ptr noundef) #1

declare i32 @xstrsrc(ptr noundef, ptr noundef) local_unnamed_addr #0

declare i64 @xstrsplita(ptr noundef, ptr noundef, ptr noundef, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !8, i64 6328}
!6 = !{!"XSearchCtx", !7, i64 0, !7, i64 56, !9, i64 112, !9, i64 113, !9, i64 114, !9, i64 115, !9, i64 116, !8, i64 120, !8, i64 128, !9, i64 136, !9, i64 2184, !11, i64 6280, !11, i64 6284, !11, i64 6288, !11, i64 6292, !12, i64 6296, !12, i64 6304, !12, i64 6312, !9, i64 6320, !8, i64 6328, !11, i64 6336}
!7 = !{!"XArray_", !8, i64 0, !8, i64 8, !11, i64 16, !8, i64 24, !9, i64 32, !9, i64 33, !9, i64 34, !12, i64 40, !12, i64 48}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"long", !9, i64 0}
!13 = !{!6, !8, i64 8}
!14 = !{!6, !8, i64 64}
!15 = !{!9, !9, i64 0}
!16 = !{!6, !12, i64 6296}
!17 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,MemCpyOptPass,SLPVectorizerPass,SROAPass,TailCallElimPass