; 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.dirent = type { i64, i64, i16, i8, [256 x i8] }

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

; Function Attrs: nounwind uwtable
define dso_local void @print_longlisting(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca [1000 x %struct.file_info], align 16
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca [4096 x i8], align 16
  %11 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %12 = call ptr @setlocale(i32 noundef 6, ptr noundef @.str) #5
  call void @llvm.lifetime.start.p0(i64 4688000, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 0, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 0, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = call ptr @opendir(ptr noundef %13)
  store ptr %14, ptr %7, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %1
  call void @perror(ptr noundef @.str.1)
  store i32 1, ptr %8, align 4
  br label %69

18:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  br label %19

19:                                               ; preds = %58, %40, %18
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = call ptr @readdir(ptr noundef %20)
  store ptr %21, ptr %9, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %26

23:                                               ; preds = %19
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = icmp slt i32 %24, 1000
  br label %26

26:                                               ; preds = %23, %19
  %27 = phi i1 [ false, %19 ], [ %25, %23 ]
  br i1 %27, label %28, label %59

28:                                               ; preds = %26
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.dirent, ptr %29, i32 0, i32 4
  %31 = getelementptr inbounds [256 x i8], ptr %30, i64 0, i64 0
  %32 = call i32 @strcmp(ptr noundef %31, ptr noundef @.str.2) #6
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %40, label %34

34:                                               ; preds = %28
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.dirent, ptr %35, i32 0, i32 4
  %37 = getelementptr inbounds [256 x i8], ptr %36, i64 0, i64 0
  %38 = call i32 @strcmp(ptr noundef %37, ptr noundef @.str.3) #6
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %34, %28
  br label %19, !llvm.loop !13

41:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4096, ptr %10) #5
  %42 = getelementptr inbounds [4096 x i8], ptr %10, i64 0, i64 0
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.dirent, ptr %44, i32 0, i32 4
  %46 = getelementptr inbounds [256 x i8], ptr %45, i64 0, i64 0
  %47 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %42, i64 noundef 4096, ptr noundef @.str.4, ptr noundef %43, ptr noundef %46) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %48 = load i32, ptr %4, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1000 x %struct.file_info], ptr %3, i64 0, i64 %49
  store ptr %50, ptr %11, align 8, !tbaa !5
  %51 = getelementptr inbounds [4096 x i8], ptr %10, i64 0, i64 0
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = call i32 @get_file_info(ptr noundef %51, ptr noundef %52, ptr noundef %5, ptr noundef %6)
  %54 = icmp eq i32 %53, 0
  br i1 %54, label %55, label %58

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

58:                                               ; preds = %55, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4096, ptr %10) #5
  br label %19, !llvm.loop !13

59:                                               ; preds = %26
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = call i32 @closedir(ptr noundef %60)
  %62 = getelementptr inbounds [1000 x %struct.file_info], ptr %3, i64 0, i64 0
  %63 = load i32, ptr %4, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  call void @qsort(ptr noundef %62, i64 noundef %64, i64 noundef 4688, ptr noundef @compare_entries)
  %65 = getelementptr inbounds [1000 x %struct.file_info], ptr %3, i64 0, i64 0
  %66 = load i32, ptr %4, align 4, !tbaa !9
  %67 = load i64, ptr %5, align 8, !tbaa !11
  %68 = load i64, ptr %6, align 8, !tbaa !11
  call void @print_sorted_entries(ptr noundef %65, i32 noundef %66, i64 noundef %67, i64 noundef %68)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  store i32 0, ptr %8, align 4
  br label %69

69:                                               ; preds = %59, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4688000, ptr %3) #5
  %70 = load i32, ptr %8, align 4
  switch i32 %70, label %72 [
    i32 0, label %71
    i32 1, label %71
  ]

71:                                               ; preds = %69, %69
  ret void

72:                                               ; preds = %69
  unreachable
}

; Function Attrs: nounwind
declare ptr @setlocale(i32 noundef, ptr noundef) #1

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

declare ptr @opendir(ptr noundef) #3

declare void @perror(ptr noundef) #3

declare ptr @readdir(ptr noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #1

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

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

declare i32 @closedir(ptr noundef) #3

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

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

; Function Attrs: nounwind uwtable
declare hidden void @print_sorted_entries(ptr noundef, i32 noundef, i64 noundef, i64 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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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(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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = distinct !{!13, !14}
!14 = !{!"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"

%struct.file_info = type { [256 x i8], [4096 x i8], i64, i32, i64, i32, i32, [256 x i8], [16 x i8], [30 x i8] }

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

; Function Attrs: nounwind uwtable
define dso_local void @print_longlisting(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca [1000 x %struct.file_info], align 16
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca [4096 x i8], align 16
  %6 = tail call ptr @setlocale(i32 noundef 6, ptr noundef nonnull @.str) #7
  call void @llvm.lifetime.start.p0(i64 4688000, ptr nonnull %2) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #7
  store i64 0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #7
  store i64 0, ptr %4, align 8, !tbaa !5
  %7 = tail call ptr @opendir(ptr noundef %0)
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %9, label %.preheader

.preheader:                                       ; preds = %1
  %8 = tail call ptr @readdir(ptr noundef nonnull %7) #7
  %.not22 = icmp eq ptr %8, null
  br i1 %.not22, label %.outer._crit_edge, label %.lr.ph.split.preheader

9:                                                ; preds = %1
  tail call void @perror(ptr noundef nonnull @.str.1) #8
  br label %34

.lr.ph.split:                                     ; preds = %.lr.ph.split.preheader, %17
  %10 = phi ptr [ %18, %17 ], [ %29, %.lr.ph.split.preheader ]
  %11 = getelementptr inbounds i8, ptr %10, i64 19
  %12 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %11, ptr noundef nonnull dereferenceable(1) @.str.2) #9
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %17, label %14

14:                                               ; preds = %.lr.ph.split
  %15 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %11, ptr noundef nonnull dereferenceable(1) @.str.3) #9
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %.outer

17:                                               ; preds = %14, %.lr.ph.split
  %18 = call ptr @readdir(ptr noundef nonnull %7) #7
  %.not23 = icmp eq ptr %18, null
  br i1 %.not23, label %.outer._crit_edge, label %.lr.ph.split, !llvm.loop !9

.outer:                                           ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %5) #7
  %19 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %5, i64 noundef 4096, ptr noundef nonnull @.str.4, ptr noundef %0, ptr noundef nonnull %11) #7
  %20 = zext nneg i32 %.0.ph20 to i64
  %21 = getelementptr inbounds [1000 x %struct.file_info], ptr %2, i64 0, i64 %20
  %22 = call i32 @get_file_info(ptr noundef nonnull %5, ptr noundef nonnull %21, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %23 = icmp eq i32 %22, 0
  %24 = zext i1 %23 to i32
  %spec.select = add nuw nsw i32 %.0.ph20, %24
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %5) #7
  %25 = call ptr @readdir(ptr noundef nonnull %7) #7
  %26 = icmp ne ptr %25, null
  %27 = icmp ult i32 %spec.select, 1000
  %28 = select i1 %26, i1 %27, i1 false
  br i1 %28, label %.lr.ph.split.preheader, label %.outer._crit_edge, !llvm.loop !9

.lr.ph.split.preheader:                           ; preds = %.preheader, %.outer
  %29 = phi ptr [ %25, %.outer ], [ %8, %.preheader ]
  %.0.ph20 = phi i32 [ %spec.select, %.outer ], [ 0, %.preheader ]
  br label %.lr.ph.split

.outer._crit_edge:                                ; preds = %.outer, %17, %.preheader
  %.0.ph.lcssa = phi i32 [ 0, %.preheader ], [ %.0.ph20, %17 ], [ %spec.select, %.outer ]
  %30 = call i32 @closedir(ptr noundef nonnull %7)
  %31 = sext i32 %.0.ph.lcssa to i64
  call void @qsort(ptr noundef nonnull %2, i64 noundef %31, i64 noundef 4688, ptr noundef nonnull @compare_entries) #7
  %32 = load i64, ptr %3, align 8, !tbaa !5
  %33 = load i64, ptr %4, align 8, !tbaa !5
  call void @print_sorted_entries(ptr noundef nonnull %2, i32 noundef %.0.ph.lcssa, i64 noundef %32, i64 noundef %33)
  br label %34

34:                                               ; preds = %.outer._crit_edge, %9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #7
  call void @llvm.lifetime.end.p0(i64 4688000, ptr nonnull %2) #7
  ret void
}

; Function Attrs: nounwind
declare ptr @setlocale(i32 noundef, ptr 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

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

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

declare ptr @readdir(ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #5

; Function Attrs: nofree nounwind
declare noundef i32 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @closedir(ptr nocapture noundef) local_unnamed_addr #3

; 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 @compare_entries(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @print_sorted_entries(ptr noundef, i32 noundef, i64 noundef, i64 noundef) local_unnamed_addr #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 = { 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 #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 = { "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 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 #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 = { cold }
attributes #9 = { nounwind willreturn memory(read) }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass