; LLVM IR from chdb-io/chdb :: base/glibc-compatibility/musl (glob)

; 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.match = type { ptr, [1 x i8] }
%struct.glob_t = type { i64, ptr, i64, i32, ptr, ptr, ptr, ptr, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local i32 @glob(ptr noalias noundef %0, i32 noundef %1, ptr noundef %2, ptr noalias noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca %struct.match, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %20, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #7
  call void @llvm.memset.p0.i64(ptr align 8 %12, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #7
  store ptr %12, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #7
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = and i32 %21, 8
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %28

24:                                               ; preds = %4
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.glob_t, ptr %25, i32 0, i32 2
  %27 = load i64, ptr %26, align 8, !tbaa !11
  br label %29

28:                                               ; preds = %4
  br label %29

29:                                               ; preds = %28, %24
  %30 = phi i64 [ %27, %24 ], [ 0, %28 ]
  store i64 %30, ptr %16, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #7
  store i32 0, ptr %17, align 4, !tbaa !9
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !15
  %33 = sext i8 %32 to i32
  %34 = icmp eq i32 %33, 47
  br i1 %34, label %35, label %46

35:                                               ; preds = %29
  br label %36

36:                                               ; preds = %42, %35
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = load i8, ptr %37, align 1, !tbaa !15
  %39 = sext i8 %38 to i32
  %40 = icmp eq i32 %39, 47
  br i1 %40, label %41, label %45

41:                                               ; preds = %36
  br label %42

42:                                               ; preds = %41
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i32 1
  store ptr %44, ptr %10, align 8, !tbaa !5
  br label %36, !llvm.loop !16

45:                                               ; preds = %36
  store ptr @.str, ptr %11, align 8, !tbaa !5
  br label %47

46:                                               ; preds = %29
  store ptr @.str.1, ptr %11, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %46, %45
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %51, label %50

50:                                               ; preds = %47
  store ptr @ignore_err, ptr %8, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %50, %47
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = and i32 %52, 32
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %63, label %55

55:                                               ; preds = %51
  %56 = load i64, ptr %16, align 8, !tbaa !14
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.glob_t, ptr %57, i32 0, i32 2
  store i64 %56, ptr %58, align 8, !tbaa !11
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.glob_t, ptr %59, i32 0, i32 0
  store i64 0, ptr %60, align 8, !tbaa !18
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.glob_t, ptr %61, i32 0, i32 1
  store ptr null, ptr %62, align 8, !tbaa !19
  br label %63

63:                                               ; preds = %55, %51
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = call i64 @strnlen(ptr noundef %64, i64 noundef 4097) #8
  %66 = icmp ugt i64 %65, 4096
  br i1 %66, label %67, label %68

67:                                               ; preds = %63
  store i32 1, ptr %5, align 4
  store i32 1, ptr %18, align 4
  br label %226

68:                                               ; preds = %63
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load i8, ptr %69, align 1, !tbaa !15
  %71 = icmp ne i8 %70, 0
  br i1 %71, label %72, label %78

72:                                               ; preds = %68
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = call i32 @match_in_dir(ptr noundef %73, ptr noundef %74, i32 noundef %75, ptr noundef %76, ptr noundef %13)
  store i32 %77, ptr %17, align 4, !tbaa !9
  br label %78

78:                                               ; preds = %72, %68
  %79 = load i32, ptr %17, align 4, !tbaa !9
  %80 = icmp eq i32 %79, 1
  br i1 %80, label %81, label %83

81:                                               ; preds = %78
  call void @freelist(ptr noundef %12)
  %82 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %82, ptr %5, align 4
  store i32 1, ptr %18, align 4
  br label %226

83:                                               ; preds = %78
  store i64 0, ptr %14, align 8, !tbaa !14
  %84 = getelementptr inbounds %struct.match, ptr %12, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !20
  store ptr %85, ptr %13, align 8, !tbaa !5
  br label %86

86:                                               ; preds = %90, %83
  %87 = load ptr, ptr %13, align 8, !tbaa !5
  %88 = icmp ne ptr %87, null
  br i1 %88, label %89, label %96

89:                                               ; preds = %86
  br label %90

90:                                               ; preds = %89
  %91 = load ptr, ptr %13, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.match, ptr %91, i32 0, i32 0
  %93 = load ptr, ptr %92, align 8, !tbaa !20
  store ptr %93, ptr %13, align 8, !tbaa !5
  %94 = load i64, ptr %14, align 8, !tbaa !14
  %95 = add i64 %94, 1
  store i64 %95, ptr %14, align 8, !tbaa !14
  br label %86, !llvm.loop !22

96:                                               ; preds = %86
  %97 = load i64, ptr %14, align 8, !tbaa !14
  %98 = icmp ne i64 %97, 0
  br i1 %98, label %115, label %99

99:                                               ; preds = %96
  %100 = load i32, ptr %7, align 4, !tbaa !9
  %101 = and i32 %100, 16
  %102 = icmp ne i32 %101, 0
  br i1 %102, label %103, label %113

103:                                              ; preds = %99
  store ptr %12, ptr %13, align 8, !tbaa !5
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  %105 = load ptr, ptr %6, align 8, !tbaa !5
  %106 = call i64 @strlen(ptr noundef %105) #8
  %107 = call i32 @append(ptr noundef %13, ptr noundef %104, i64 noundef %106, i32 noundef 0)
  %108 = icmp ne i32 %107, 0
  br i1 %108, label %109, label %110

109:                                              ; preds = %103
  store i32 1, ptr %5, align 4
  store i32 1, ptr %18, align 4
  br label %226

110:                                              ; preds = %103
  %111 = load i64, ptr %14, align 8, !tbaa !14
  %112 = add i64 %111, 1
  store i64 %112, ptr %14, align 8, !tbaa !14
  br label %114

113:                                              ; preds = %99
  store i32 3, ptr %5, align 4
  store i32 1, ptr %18, align 4
  br label %226

114:                                              ; preds = %110
  br label %115

115:                                              ; preds = %114, %96
  %116 = load i32, ptr %7, align 4, !tbaa !9
  %117 = and i32 %116, 32
  %118 = icmp ne i32 %117, 0
  br i1 %118, label %119, label %148

119:                                              ; preds = %115
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #7
  %120 = load ptr, ptr %9, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.glob_t, ptr %120, i32 0, i32 1
  %122 = load ptr, ptr %121, align 8, !tbaa !19
  %123 = load i64, ptr %16, align 8, !tbaa !14
  %124 = load ptr, ptr %9, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.glob_t, ptr %124, i32 0, i32 0
  %126 = load i64, ptr %125, align 8, !tbaa !18
  %127 = add i64 %123, %126
  %128 = load i64, ptr %14, align 8, !tbaa !14
  %129 = add i64 %127, %128
  %130 = add i64 %129, 1
  %131 = mul i64 %130, 8
  %132 = call ptr @realloc(ptr noundef %122, i64 noundef %131) #9
  store ptr %132, ptr %19, align 8, !tbaa !5
  %133 = load ptr, ptr %19, align 8, !tbaa !5
  %134 = icmp ne ptr %133, null
  br i1 %134, label %136, label %135

135:                                              ; preds = %119
  call void @freelist(ptr noundef %12)
  store i32 1, ptr %5, align 4
  store i32 1, ptr %18, align 4
  br label %145

136:                                              ; preds = %119
  %137 = load ptr, ptr %19, align 8, !tbaa !5
  %138 = load ptr, ptr %9, align 8, !tbaa !5
  %139 = getelementptr inbounds %struct.glob_t, ptr %138, i32 0, i32 1
  store ptr %137, ptr %139, align 8, !tbaa !19
  %140 = load ptr, ptr %9, align 8, !tbaa !5
  %141 = getelementptr inbounds %struct.glob_t, ptr %140, i32 0, i32 0
  %142 = load i64, ptr %141, align 8, !tbaa !18
  %143 = load i64, ptr %16, align 8, !tbaa !14
  %144 = add i64 %143, %142
  store i64 %144, ptr %16, align 8, !tbaa !14
  store i32 0, ptr %18, align 4
  br label %145

145:                                              ; preds = %136, %135
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #7
  %146 = load i32, ptr %18, align 4
  switch i32 %146, label %226 [
    i32 0, label %147
  ]

147:                                              ; preds = %145
  br label %177

148:                                              ; preds = %115
  %149 = load i64, ptr %16, align 8, !tbaa !14
  %150 = load i64, ptr %14, align 8, !tbaa !14
  %151 = add i64 %149, %150
  %152 = add i64 %151, 1
  %153 = mul i64 %152, 8
  %154 = call noalias ptr @malloc(i64 noundef %153) #10
  %155 = load ptr, ptr %9, align 8, !tbaa !5
  %156 = getelementptr inbounds %struct.glob_t, ptr %155, i32 0, i32 1
  store ptr %154, ptr %156, align 8, !tbaa !19
  %157 = load ptr, ptr %9, align 8, !tbaa !5
  %158 = getelementptr inbounds %struct.glob_t, ptr %157, i32 0, i32 1
  %159 = load ptr, ptr %158, align 8, !tbaa !19
  %160 = icmp ne ptr %159, null
  br i1 %160, label %162, label %161

161:                                              ; preds = %148
  call void @freelist(ptr noundef %12)
  store i32 1, ptr %5, align 4
  store i32 1, ptr %18, align 4
  br label %226

162:                                              ; preds = %148
  store i64 0, ptr %15, align 8, !tbaa !14
  br label %163

163:                                              ; preds = %173, %162
  %164 = load i64, ptr %15, align 8, !tbaa !14
  %165 = load i64, ptr %16, align 8, !tbaa !14
  %166 = icmp ult i64 %164, %165
  br i1 %166, label %167, label %176

167:                                              ; preds = %163
  %168 = load ptr, ptr %9, align 8, !tbaa !5
  %169 = getelementptr inbounds %struct.glob_t, ptr %168, i32 0, i32 1
  %170 = load ptr, ptr %169, align 8, !tbaa !19
  %171 = load i64, ptr %15, align 8, !tbaa !14
  %172 = getelementptr inbounds ptr, ptr %170, i64 %171
  store ptr null, ptr %172, align 8, !tbaa !5
  br label %173

173:                                              ; preds = %167
  %174 = load i64, ptr %15, align 8, !tbaa !14
  %175 = add i64 %174, 1
  store i64 %175, ptr %15, align 8, !tbaa !14
  br label %163, !llvm.loop !23

176:                                              ; preds = %163
  br label %177

177:                                              ; preds = %176, %147
  store i64 0, ptr %15, align 8, !tbaa !14
  %178 = getelementptr inbounds %struct.match, ptr %12, i32 0, i32 0
  %179 = load ptr, ptr %178, align 8, !tbaa !20
  store ptr %179, ptr %13, align 8, !tbaa !5
  br label %180

180:                                              ; preds = %195, %177
  %181 = load i64, ptr %15, align 8, !tbaa !14
  %182 = load i64, ptr %14, align 8, !tbaa !14
  %183 = icmp ult i64 %181, %182
  br i1 %183, label %184, label %201

184:                                              ; preds = %180
  %185 = load ptr, ptr %13, align 8, !tbaa !5
  %186 = getelementptr inbounds %struct.match, ptr %185, i32 0, i32 1
  %187 = getelementptr inbounds [1 x i8], ptr %186, i64 0, i64 0
  %188 = load ptr, ptr %9, align 8, !tbaa !5
  %189 = getelementptr inbounds %struct.glob_t, ptr %188, i32 0, i32 1
  %190 = load ptr, ptr %189, align 8, !tbaa !19
  %191 = load i64, ptr %16, align 8, !tbaa !14
  %192 = load i64, ptr %15, align 8, !tbaa !14
  %193 = add i64 %191, %192
  %194 = getelementptr inbounds ptr, ptr %190, i64 %193
  store ptr %187, ptr %194, align 8, !tbaa !5
  br label %195

195:                                              ; preds = %184
  %196 = load ptr, ptr %13, align 8, !tbaa !5
  %197 = getelementptr inbounds %struct.match, ptr %196, i32 0, i32 0
  %198 = load ptr, ptr %197, align 8, !tbaa !20
  store ptr %198, ptr %13, align 8, !tbaa !5
  %199 = load i64, ptr %15, align 8, !tbaa !14
  %200 = add i64 %199, 1
  store i64 %200, ptr %15, align 8, !tbaa !14
  br label %180, !llvm.loop !24

201:                                              ; preds = %180
  %202 = load ptr, ptr %9, align 8, !tbaa !5
  %203 = getelementptr inbounds %struct.glob_t, ptr %202, i32 0, i32 1
  %204 = load ptr, ptr %203, align 8, !tbaa !19
  %205 = load i64, ptr %16, align 8, !tbaa !14
  %206 = load i64, ptr %15, align 8, !tbaa !14
  %207 = add i64 %205, %206
  %208 = getelementptr inbounds ptr, ptr %204, i64 %207
  store ptr null, ptr %208, align 8, !tbaa !5
  %209 = load i64, ptr %14, align 8, !tbaa !14
  %210 = load ptr, ptr %9, align 8, !tbaa !5
  %211 = getelementptr inbounds %struct.glob_t, ptr %210, i32 0, i32 0
  %212 = load i64, ptr %211, align 8, !tbaa !18
  %213 = add i64 %212, %209
  store i64 %213, ptr %211, align 8, !tbaa !18
  %214 = load i32, ptr %7, align 4, !tbaa !9
  %215 = and i32 %214, 4
  %216 = icmp ne i32 %215, 0
  br i1 %216, label %224, label %217

217:                                              ; preds = %201
  %218 = load ptr, ptr %9, align 8, !tbaa !5
  %219 = getelementptr inbounds %struct.glob_t, ptr %218, i32 0, i32 1
  %220 = load ptr, ptr %219, align 8, !tbaa !19
  %221 = load i64, ptr %16, align 8, !tbaa !14
  %222 = getelementptr inbounds ptr, ptr %220, i64 %221
  %223 = load i64, ptr %14, align 8, !tbaa !14
  call void @qsort(ptr noundef %222, i64 noundef %223, i64 noundef 8, ptr noundef @sort)
  br label %224

224:                                              ; preds = %217, %201
  %225 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %225, ptr %5, align 4
  store i32 1, ptr %18, align 4
  br label %226

226:                                              ; preds = %224, %161, %145, %113, %109, %81, %67
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  %227 = load i32, ptr %5, align 4
  ret i32 %227
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strnlen(ptr noundef, i64 noundef) #3

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

; Function Attrs: nounwind uwtable
declare hidden void @freelist(ptr noundef) #0

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

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

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #4

; 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) #5

declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #6

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

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { nounwind allocsize(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 #5 = { 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 #6 = { "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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { nounwind allocsize(1) }
attributes #10 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 16}
!12 = !{!"", !13, i64 0, !6, i64 8, !13, i64 16, !10, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!12, !13, i64 0}
!19 = !{!12, !6, i64 8}
!20 = !{!21, !6, i64 0}
!21 = !{!"match", !6, i64 0, !7, i64 8}
!22 = distinct !{!22, !17}
!23 = distinct !{!23, !17}
!24 = distinct !{!24, !17}


; 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.match = type { ptr, [1 x i8] }

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

; Function Attrs: nounwind uwtable
define dso_local i32 @glob(ptr noalias noundef %0, i32 noundef %1, ptr noundef %2, ptr noalias nocapture noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.match, align 8
  %6 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %5, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #7
  store ptr %5, ptr %6, align 8, !tbaa !5
  %7 = and i32 %1, 8
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %11, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %3, i64 16
  %10 = load i64, ptr %9, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %4, %8
  %12 = phi i64 [ %10, %8 ], [ 0, %4 ]
  %13 = load i8, ptr %0, align 1, !tbaa !13
  %14 = icmp eq i8 %13, 47
  br i1 %14, label %.preheader89, label %.loopexit90

.preheader89:                                     ; preds = %11, %.preheader89
  %.07191 = phi ptr [ %15, %.preheader89 ], [ %0, %11 ]
  %15 = getelementptr inbounds i8, ptr %.07191, i64 1
  %.pr = load i8, ptr %15, align 1, !tbaa !13
  %16 = icmp eq i8 %.pr, 47
  br i1 %16, label %.preheader89, label %.loopexit90, !llvm.loop !14

.loopexit90:                                      ; preds = %.preheader89, %11
  %.172 = phi ptr [ %0, %11 ], [ %15, %.preheader89 ]
  %.070 = phi ptr [ @.str.1, %11 ], [ @.str, %.preheader89 ]
  %.not75 = icmp eq ptr %2, null
  %spec.store.select = select i1 %.not75, ptr @ignore_err, ptr %2
  %17 = and i32 %1, 32
  %.not76 = icmp eq i32 %17, 0
  br i1 %.not76, label %18, label %20

18:                                               ; preds = %.loopexit90
  %19 = getelementptr inbounds i8, ptr %3, i64 16
  store i64 %12, ptr %19, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %3, i8 0, i64 16, i1 false)
  br label %20

20:                                               ; preds = %18, %.loopexit90
  %21 = call i64 @strnlen(ptr noundef nonnull dereferenceable(1) %.172, i64 noundef 4097) #8
  %22 = icmp ugt i64 %21, 4096
  br i1 %22, label %86, label %23

23:                                               ; preds = %20
  %.not77 = icmp eq i8 %13, 0
  br i1 %.not77, label %._crit_edge.thread, label %24

24:                                               ; preds = %23
  %25 = call i32 @match_in_dir(ptr noundef nonnull %.070, ptr noundef nonnull %.172, i32 noundef %1, ptr noundef nonnull %spec.store.select, ptr noundef nonnull %6)
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %27, label %.thread

27:                                               ; preds = %24
  call void @freelist(ptr noundef nonnull %5)
  br label %86

.thread:                                          ; preds = %24
  %.pre = load ptr, ptr %5, align 8, !tbaa !16
  store ptr %.pre, ptr %6, align 8, !tbaa !5
  %.not7892 = icmp eq ptr %.pre, null
  br i1 %.not7892, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.thread, %.lr.ph
  %.06893 = phi i64 [ %30, %.lr.ph ], [ 0, %.thread ]
  %28 = phi ptr [ %29, %.lr.ph ], [ %.pre, %.thread ]
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  store ptr %29, ptr %6, align 8, !tbaa !5
  %30 = add i64 %.06893, 1
  %.not78 = icmp eq ptr %29, null
  br i1 %.not78, label %._crit_edge, label %.lr.ph, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph
  %.not79 = icmp eq i64 %30, 0
  br i1 %.not79, label %._crit_edge.thread, label %35

._crit_edge.thread:                               ; preds = %23, %.thread, %._crit_edge
  %.06386102107 = phi i32 [ %25, %._crit_edge ], [ %25, %.thread ], [ 0, %23 ]
  %31 = and i32 %1, 16
  %.not80 = icmp eq i32 %31, 0
  br i1 %.not80, label %86, label %32

32:                                               ; preds = %._crit_edge.thread
  store ptr %5, ptr %6, align 8, !tbaa !5
  %33 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #8
  %34 = call i32 @append(ptr noundef nonnull %6, ptr noundef nonnull %0, i64 noundef %33, i32 noundef 0)
  %.not81 = icmp eq i32 %34, 0
  br i1 %.not81, label %35, label %86

35:                                               ; preds = %32, %._crit_edge
  %.06386102106 = phi i32 [ %25, %._crit_edge ], [ %.06386102107, %32 ]
  %.169 = phi i64 [ %30, %._crit_edge ], [ 1, %32 ]
  br i1 %.not76, label %46, label %36

36:                                               ; preds = %35
  %37 = getelementptr inbounds i8, ptr %3, i64 8
  %38 = load ptr, ptr %37, align 8, !tbaa !19
  %39 = load i64, ptr %3, align 8, !tbaa !20
  %40 = add i64 %39, %12
  %41 = add i64 %40, %.169
  %42 = shl i64 %41, 3
  %43 = add i64 %42, 8
  %44 = call ptr @realloc(ptr noundef %38, i64 noundef %43) #9
  %.not83.not = icmp eq ptr %44, null
  br i1 %.not83.not, label %.thread87, label %45

.thread87:                                        ; preds = %36
  call void @freelist(ptr noundef nonnull %5)
  br label %86

45:                                               ; preds = %36
  store ptr %44, ptr %37, align 8, !tbaa !19
  br label %.loopexit

46:                                               ; preds = %35
  %47 = add i64 %.169, %12
  %48 = shl i64 %47, 3
  %49 = add i64 %48, 8
  %50 = call noalias ptr @malloc(i64 noundef %49) #10
  %51 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %50, ptr %51, align 8, !tbaa !19
  %.not82 = icmp eq ptr %50, null
  br i1 %.not82, label %53, label %.preheader

.preheader:                                       ; preds = %46
  %.not97 = icmp eq i64 %12, 0
  br i1 %.not97, label %.loopexit, label %.lr.ph95.preheader

.lr.ph95.preheader:                               ; preds = %.preheader
  %52 = shl nuw i64 %12, 3
  call void @llvm.memset.p0.i64(ptr nonnull align 8 %50, i8 0, i64 %52, i1 false), !tbaa !5
  br label %.loopexit

53:                                               ; preds = %46
  call void @freelist(ptr noundef nonnull %5)
  br label %86

.loopexit:                                        ; preds = %.lr.ph95.preheader, %.preheader, %45
  %54 = phi ptr [ %44, %45 ], [ %50, %.preheader ], [ %50, %.lr.ph95.preheader ]
  %.165 = phi i64 [ %40, %45 ], [ 0, %.preheader ], [ %12, %.lr.ph95.preheader ]
  %55 = load ptr, ptr %5, align 8, !tbaa !16
  store ptr %55, ptr %6, align 8, !tbaa !5
  %56 = getelementptr ptr, ptr %54, i64 %.165
  %xtraiter = and i64 %.169, 3
  %57 = icmp ult i64 %.169, 4
  br i1 %57, label %.unr-lcssa, label %.loopexit.new

.loopexit.new:                                    ; preds = %.loopexit
  %unroll_iter = and i64 %.169, -4
  br label %58

58:                                               ; preds = %58, %.loopexit.new
  %59 = phi ptr [ %55, %.loopexit.new ], [ %74, %58 ]
  %.16796 = phi i64 [ 0, %.loopexit.new ], [ %75, %58 ]
  %niter = phi i64 [ 0, %.loopexit.new ], [ %niter.next.3, %58 ]
  %60 = getelementptr inbounds i8, ptr %59, i64 8
  %61 = getelementptr ptr, ptr %56, i64 %.16796
  store ptr %60, ptr %61, align 8, !tbaa !5
  %62 = load ptr, ptr %59, align 8, !tbaa !16
  store ptr %62, ptr %6, align 8, !tbaa !5
  %63 = or disjoint i64 %.16796, 1
  %64 = getelementptr inbounds i8, ptr %62, i64 8
  %65 = getelementptr ptr, ptr %56, i64 %63
  store ptr %64, ptr %65, align 8, !tbaa !5
  %66 = load ptr, ptr %62, align 8, !tbaa !16
  store ptr %66, ptr %6, align 8, !tbaa !5
  %67 = or disjoint i64 %.16796, 2
  %68 = getelementptr inbounds i8, ptr %66, i64 8
  %69 = getelementptr ptr, ptr %56, i64 %67
  store ptr %68, ptr %69, align 8, !tbaa !5
  %70 = load ptr, ptr %66, align 8, !tbaa !16
  store ptr %70, ptr %6, align 8, !tbaa !5
  %71 = or disjoint i64 %.16796, 3
  %72 = getelementptr inbounds i8, ptr %70, i64 8
  %73 = getelementptr ptr, ptr %56, i64 %71
  store ptr %72, ptr %73, align 8, !tbaa !5
  %74 = load ptr, ptr %70, align 8, !tbaa !16
  store ptr %74, ptr %6, align 8, !tbaa !5
  %75 = add nuw i64 %.16796, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.unr-lcssa, label %58, !llvm.loop !21

.unr-lcssa:                                       ; preds = %58, %.loopexit
  %.unr = phi ptr [ %55, %.loopexit ], [ %74, %58 ]
  %.16796.unr = phi i64 [ 0, %.loopexit ], [ %75, %58 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.epilog-lcssa, label %.epil.preheader

.epil.preheader:                                  ; preds = %.unr-lcssa, %.epil.preheader
  %76 = phi ptr [ %79, %.epil.preheader ], [ %.unr, %.unr-lcssa ]
  %.16796.epil = phi i64 [ %80, %.epil.preheader ], [ %.16796.unr, %.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.unr-lcssa ]
  %77 = getelementptr inbounds i8, ptr %76, i64 8
  %78 = getelementptr ptr, ptr %56, i64 %.16796.epil
  store ptr %77, ptr %78, align 8, !tbaa !5
  %79 = load ptr, ptr %76, align 8, !tbaa !16
  store ptr %79, ptr %6, align 8, !tbaa !5
  %80 = add nuw i64 %.16796.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.epilog-lcssa, label %.epil.preheader, !llvm.loop !22

.epilog-lcssa:                                    ; preds = %.epil.preheader, %.unr-lcssa
  %81 = getelementptr ptr, ptr %56, i64 %.169
  store ptr null, ptr %81, align 8, !tbaa !5
  %82 = load i64, ptr %3, align 8, !tbaa !20
  %83 = add i64 %82, %.169
  store i64 %83, ptr %3, align 8, !tbaa !20
  %84 = and i32 %1, 4
  %.not84 = icmp eq i32 %84, 0
  br i1 %.not84, label %85, label %86

85:                                               ; preds = %.epilog-lcssa
  call void @qsort(ptr noundef %56, i64 noundef %.169, i64 noundef 8, ptr noundef nonnull @sort) #7
  br label %86

86:                                               ; preds = %.thread87, %.epilog-lcssa, %85, %._crit_edge.thread, %32, %20, %53, %27
  %.1 = phi i32 [ 1, %27 ], [ 1, %53 ], [ 1, %20 ], [ 1, %32 ], [ 3, %._crit_edge.thread ], [ %.06386102106, %85 ], [ %.06386102106, %.epilog-lcssa ], [ 1, %.thread87 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #7
  ret i32 %.1
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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

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

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

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

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

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #4

; 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 #5

; Function Attrs: nofree
declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #6

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

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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) 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 #5 = { 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 #6 = { nofree "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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { nounwind allocsize(1) }
attributes #10 = { 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, !11, i64 16}
!10 = !{!"", !11, i64 0, !6, i64 8, !11, i64 16, !12, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 0}
!17 = !{!"match", !6, i64 0, !7, i64 8}
!18 = distinct !{!18, !15}
!19 = !{!10, !6, i64 8}
!20 = !{!10, !11, i64 0}
!21 = distinct !{!21, !15}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.unroll.disable"}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass