; LLVM IR from yellow-footed-honeyguide/facad :: src (longlisting)

; 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.file_info = type { [256 x i8], [4096 x i8], i64, i32, i64, i32, i32, [256 x i8], [16 x i8], [30 x i8] }
%struct.glob_t = type { i64, ptr, i64, i32, ptr, ptr, ptr, ptr, ptr }

@stderr = external global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [26 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: nounwind uwtable
declare hidden i32 @get_file_info(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @print_sorted_entries(ptr noundef, i32 noundef, i64 noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @print_longlisting_files(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca [1000 x %struct.file_info], align 16
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca %struct.glob_t, align 8
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4688000, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 0, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store i64 0, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %73, %2
  %16 = load i32, ptr %9, align 4, !tbaa !9
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %76

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 72, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds ptr, ptr %21, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = call i32 @glob(ptr noundef %25, i32 noundef 4096, ptr noundef null, ptr noundef %11) #5
  store i32 %26, ptr %12, align 4, !tbaa !9
  %27 = load i32, ptr %12, align 4, !tbaa !9
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %61

29:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  store i64 0, ptr %13, align 8, !tbaa !11
  br label %30

30:                                               ; preds = %57, %29
  %31 = load i64, ptr %13, align 8, !tbaa !11
  %32 = getelementptr inbounds %struct.glob_t, ptr %11, i32 0, i32 0
  %33 = load i64, ptr %32, align 8, !tbaa !13
  %34 = icmp ult i64 %31, %33
  br i1 %34, label %35, label %38

35:                                               ; preds = %30
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = icmp slt i32 %36, 1000
  br label %38

38:                                               ; preds = %35, %30
  %39 = phi i1 [ false, %30 ], [ %37, %35 ]
  br i1 %39, label %41, label %40

40:                                               ; preds = %38
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %60

41:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [1000 x %struct.file_info], ptr %5, i64 0, i64 %43
  store ptr %44, ptr %14, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.glob_t, ptr %11, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = load i64, ptr %13, align 8, !tbaa !11
  %48 = getelementptr inbounds ptr, ptr %46, i64 %47
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  %50 = load ptr, ptr %14, align 8, !tbaa !5
  %51 = call i32 @get_file_info(ptr noundef %49, ptr noundef %50, ptr noundef %7, ptr noundef %8)
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %53, label %56

53:                                               ; preds = %41
  %54 = load i32, ptr %6, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %6, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %53, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  br label %57

57:                                               ; preds = %56
  %58 = load i64, ptr %13, align 8, !tbaa !11
  %59 = add i64 %58, 1
  store i64 %59, ptr %13, align 8, !tbaa !11
  br label %30, !llvm.loop !16

60:                                               ; preds = %40
  br label %72

61:                                               ; preds = %20
  %62 = load ptr, ptr @stderr, align 8, !tbaa !5
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = load i32, ptr %9, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds ptr, ptr %63, i64 %65
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  %68 = call ptr @__errno_location() #6
  %69 = load i32, ptr %68, align 4, !tbaa !9
  %70 = call ptr @strerror(i32 noundef %69) #5
  %71 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %62, ptr noundef @.str.5, ptr noundef %67, ptr noundef %70) #5
  br label %72

72:                                               ; preds = %61, %60
  call void @globfree(ptr noundef %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 72, ptr %11) #5
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %9, align 4, !tbaa !9
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %9, align 4, !tbaa !9
  br label %15, !llvm.loop !18

76:                                               ; preds = %19
  %77 = load i32, ptr %6, align 4, !tbaa !9
  %78 = icmp sgt i32 %77, 0
  br i1 %78, label %79, label %87

79:                                               ; preds = %76
  %80 = getelementptr inbounds [1000 x %struct.file_info], ptr %5, i64 0, i64 0
  %81 = load i32, ptr %6, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  call void @qsort(ptr noundef %80, i64 noundef %82, i64 noundef 4688, ptr noundef @compare_entries)
  %83 = getelementptr inbounds [1000 x %struct.file_info], ptr %5, i64 0, i64 0
  %84 = load i32, ptr %6, align 4, !tbaa !9
  %85 = load i64, ptr %7, align 8, !tbaa !11
  %86 = load i64, ptr %8, align 8, !tbaa !11
  call void @print_sorted_entries(ptr noundef %83, i32 noundef %84, i64 noundef %85, i64 noundef %86)
  br label %90

87:                                               ; preds = %76
  %88 = load ptr, ptr @stderr, align 8, !tbaa !5
  %89 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %88, ptr noundef @.str.6) #5
  br label %90

90:                                               ; preds = %87, %79
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4688000, ptr %5) #5
  ret void
}

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #3

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #4

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

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 "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(none) "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 }
attributes #6 = { nounwind willreturn memory(none) }

!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 = !{!14, !12, i64 0}
!14 = !{!"", !12, i64 0, !6, i64 8, !12, i64 16, !10, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!15 = !{!14, !6, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !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.file_info = type { [256 x i8], [4096 x i8], i64, i32, i64, i32, i32, [256 x i8], [16 x i8], [30 x i8] }
%struct.glob_t = type { i64, ptr, i64, i32, ptr, ptr, ptr, ptr, ptr }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [26 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: nounwind uwtable
declare hidden i32 @get_file_info(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @print_sorted_entries(ptr noundef, i32 noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @print_longlisting_files(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = alloca [1000 x %struct.file_info], align 16
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca %struct.glob_t, align 8
  call void @llvm.lifetime.start.p0(i64 4688000, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #6
  store i64 0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #6
  store i64 0, ptr %5, align 8, !tbaa !5
  %7 = icmp sgt i32 %1, 0
  br i1 %7, label %.lr.ph23, label %._crit_edge.thread

.lr.ph23:                                         ; preds = %2
  %8 = getelementptr inbounds i8, ptr %6, i64 8
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %10

._crit_edge:                                      ; preds = %.loopexit
  %9 = icmp sgt i32 %.3, 0
  br i1 %9, label %39, label %._crit_edge.thread

10:                                               ; preds = %.lr.ph23, %.loopexit
  %indvars.iv = phi i64 [ 0, %.lr.ph23 ], [ %indvars.iv.next, %.loopexit ]
  %.022 = phi i32 [ 0, %.lr.ph23 ], [ %.3, %.loopexit ]
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %6) #6
  %11 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = call i32 @glob(ptr noundef %12, i32 noundef 4096, ptr noundef null, ptr noundef nonnull %6) #6
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %.preheader, label %32

.preheader:                                       ; preds = %10
  %15 = load i64, ptr %6, align 8, !tbaa !11
  %16 = icmp ne i64 %15, 0
  %17 = icmp slt i32 %.022, 1000
  %18 = select i1 %16, i1 %17, i1 false
  br i1 %18, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.120 = phi i32 [ %spec.select, %.lr.ph ], [ %.022, %.preheader ]
  %.01719 = phi i64 [ %27, %.lr.ph ], [ 0, %.preheader ]
  %19 = sext i32 %.120 to i64
  %20 = getelementptr inbounds [1000 x %struct.file_info], ptr %3, i64 0, i64 %19
  %21 = load ptr, ptr %8, align 8, !tbaa !14
  %22 = getelementptr inbounds ptr, ptr %21, i64 %.01719
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = call i32 @get_file_info(ptr noundef %23, ptr noundef nonnull %20, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %25 = icmp eq i32 %24, 0
  %26 = zext i1 %25 to i32
  %spec.select = add nsw i32 %.120, %26
  %27 = add nuw i64 %.01719, 1
  %28 = load i64, ptr %6, align 8, !tbaa !11
  %29 = icmp ult i64 %27, %28
  %30 = icmp slt i32 %spec.select, 1000
  %31 = select i1 %29, i1 %30, i1 false
  br i1 %31, label %.lr.ph, label %.loopexit, !llvm.loop !15

32:                                               ; preds = %10
  %33 = load ptr, ptr @stderr, align 8, !tbaa !9
  %34 = load ptr, ptr %11, align 8, !tbaa !9
  %35 = tail call ptr @__errno_location() #7
  %36 = load i32, ptr %35, align 4, !tbaa !17
  %37 = call ptr @strerror(i32 noundef %36) #6
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef nonnull @.str.5, ptr noundef %34, ptr noundef %37) #8
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.preheader, %32
  %.3 = phi i32 [ %.022, %32 ], [ %.022, %.preheader ], [ %spec.select, %.lr.ph ]
  call void @globfree(ptr noundef nonnull %6) #6
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %6) #6
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %10, !llvm.loop !18

39:                                               ; preds = %._crit_edge
  %40 = zext nneg i32 %.3 to i64
  call void @qsort(ptr noundef nonnull %3, i64 noundef %40, i64 noundef 4688, ptr noundef nonnull @compare_entries) #6
  %41 = load i64, ptr %4, align 8, !tbaa !5
  %42 = load i64, ptr %5, align 8, !tbaa !5
  call void @print_sorted_entries(ptr noundef nonnull %3, i32 noundef %.3, i64 noundef %41, i64 noundef %42)
  br label %45

._crit_edge.thread:                               ; preds = %2, %._crit_edge
  %43 = load ptr, ptr @stderr, align 8, !tbaa !9
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef nonnull @.str.6) #8
  br label %45

45:                                               ; preds = %._crit_edge.thread, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 4688000, ptr nonnull %3) #6
  ret void
}

; Function Attrs: nounwind
declare i32 @glob(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #4

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #5

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

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 = { 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 #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 = { 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 #5 = { mustprogress nofree nosync nounwind willreturn memory(none) "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(none) }
attributes #8 = { cold 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !10, i64 8, !6, i64 16, !13, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!13, !13, i64 0}
!18 = distinct !{!18, !16}


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