; LLVM IR from mncoppola/rpef :: utilities_src/squashfs4.1/squashfs-tools (sort)

; 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.priority_entry = type { ptr, ptr }
%struct.dir_ent = type { ptr, ptr, ptr, ptr, ptr }
%struct.inode_info = type { %struct.stat, ptr, i64, i32, i32, i32, i8, i8, i8, i8 }
%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 }

@priority_list = external dso_local global [65536 x ptr], align 16
@silent = external global i32, align 4
@.str.21 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [56 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @sort_files_and_write(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 65535, ptr %3, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %97, %1
  %8 = load i32, ptr %3, align 4, !tbaa !9
  %9 = icmp sge i32 %8, 0
  br i1 %9, label %10, label %100

10:                                               ; preds = %7
  %11 = load i32, ptr %3, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [65536 x ptr], ptr @priority_list, i64 0, i64 %12
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %14, ptr %4, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %92, %10
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %96

18:                                               ; preds = %15
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.priority_entry, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = getelementptr inbounds %struct.dir_ent, ptr %21, i32 0, i32 2
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = getelementptr inbounds %struct.inode_info, ptr %23, i32 0, i32 2
  %25 = load i64, ptr %24, align 8, !tbaa !15
  %26 = icmp eq i64 %25, -1
  br i1 %26, label %27, label %69

27:                                               ; preds = %18
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.priority_entry, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  call void @write_file(ptr noundef %5, ptr noundef %30, ptr noundef %6)
  br label %31

31:                                               ; preds = %27
  %32 = load i32, ptr @silent, align 4, !tbaa !9
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %53, label %34

34:                                               ; preds = %31
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.priority_entry, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  %38 = getelementptr inbounds %struct.dir_ent, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !21
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.priority_entry, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = getelementptr inbounds %struct.dir_ent, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !13
  %45 = getelementptr inbounds %struct.inode_info, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds %struct.stat, ptr %45, i32 0, i32 8
  %47 = load i64, ptr %46, align 8, !tbaa !22
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = icmp ne i32 %48, 0
  %50 = zext i1 %49 to i64
  %51 = select i1 %49, ptr @.str.22, ptr @.str.23
  %52 = call i32 (ptr, ...) @printf(ptr noundef @.str.21, ptr noundef %39, i64 noundef %47, ptr noundef %51)
  br label %53

53:                                               ; preds = %34, %31
  br label %54

54:                                               ; preds = %53
  br label %55

55:                                               ; preds = %54
  %56 = load i64, ptr %5, align 8, !tbaa !23
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.priority_entry, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !11
  %60 = getelementptr inbounds %struct.dir_ent, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !13
  %62 = getelementptr inbounds %struct.inode_info, ptr %61, i32 0, i32 2
  store i64 %56, ptr %62, align 8, !tbaa !15
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.priority_entry, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !11
  %66 = getelementptr inbounds %struct.dir_ent, ptr %65, i32 0, i32 2
  %67 = load ptr, ptr %66, align 8, !tbaa !13
  %68 = getelementptr inbounds %struct.inode_info, ptr %67, i32 0, i32 6
  store i8 2, ptr %68, align 4, !tbaa !24
  br label %91

69:                                               ; preds = %18
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr @silent, align 4, !tbaa !9
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %88, label %73

73:                                               ; preds = %70
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.priority_entry, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !11
  %77 = getelementptr inbounds %struct.dir_ent, ptr %76, i32 0, i32 1
  %78 = load ptr, ptr %77, align 8, !tbaa !21
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.priority_entry, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !11
  %82 = getelementptr inbounds %struct.dir_ent, ptr %81, i32 0, i32 2
  %83 = load ptr, ptr %82, align 8, !tbaa !13
  %84 = getelementptr inbounds %struct.inode_info, ptr %83, i32 0, i32 0
  %85 = getelementptr inbounds %struct.stat, ptr %84, i32 0, i32 8
  %86 = load i64, ptr %85, align 8, !tbaa !22
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.24, ptr noundef %78, i64 noundef %86)
  br label %88

88:                                               ; preds = %73, %70
  br label %89

89:                                               ; preds = %88
  br label %90

90:                                               ; preds = %89
  br label %91

91:                                               ; preds = %90, %55
  br label %92

92:                                               ; preds = %91
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.priority_entry, ptr %93, i32 0, i32 1
  %95 = load ptr, ptr %94, align 8, !tbaa !25
  store ptr %95, ptr %4, align 8, !tbaa !5
  br label %15, !llvm.loop !26

96:                                               ; preds = %15
  br label %97

97:                                               ; preds = %96
  %98 = load i32, ptr %3, align 4, !tbaa !9
  %99 = add nsw i32 %98, -1
  store i32 %99, ptr %3, align 4, !tbaa !9
  br label %7, !llvm.loop !28

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

declare void @write_file(ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @printf(ptr noundef, ...) #2

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 }

!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, !6, i64 0}
!12 = !{!"priority_entry", !6, i64 0, !6, i64 8}
!13 = !{!14, !6, i64 16}
!14 = !{!"dir_ent", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!15 = !{!16, !20, i64 152}
!16 = !{!"inode_info", !17, i64 0, !6, i64 144, !20, i64 152, !10, i64 160, !10, i64 164, !10, i64 168, !7, i64 172, !7, i64 173, !7, i64 174, !7, i64 175}
!17 = !{!"stat", !18, i64 0, !18, i64 8, !18, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !18, i64 40, !18, i64 48, !18, i64 56, !18, i64 64, !19, i64 72, !19, i64 88, !19, i64 104, !7, i64 120}
!18 = !{!"long", !7, i64 0}
!19 = !{!"timespec", !18, i64 0, !18, i64 8}
!20 = !{!"long long", !7, i64 0}
!21 = !{!14, !6, i64 8}
!22 = !{!16, !18, i64 48}
!23 = !{!20, !20, i64 0}
!24 = !{!16, !7, i64 172}
!25 = !{!12, !6, i64 8}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = distinct !{!28, !27}


; 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"

@priority_list = external dso_local local_unnamed_addr global [65536 x ptr], align 16
@silent = external local_unnamed_addr global i32, align 4
@.str.21 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [56 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @sort_files_and_write(ptr nocapture noundef readnone %0) local_unnamed_addr #1 {
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  br label %4

4:                                                ; preds = %1, %._crit_edge
  %indvars.iv = phi i64 [ 65535, %1 ], [ %indvars.iv.next, %._crit_edge ]
  %5 = getelementptr inbounds [65536 x ptr], ptr @priority_list, i64 0, i64 %indvars.iv
  %.016 = load ptr, ptr %5, align 8, !tbaa !5
  %.not17 = icmp eq ptr %.016, null
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %40
  %.018 = phi ptr [ %.0, %40 ], [ %.016, %4 ]
  %6 = load ptr, ptr %.018, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %8, i64 152
  %10 = load i64, ptr %9, align 8, !tbaa !13
  %11 = icmp eq i64 %10, -1
  br i1 %11, label %12, label %32

12:                                               ; preds = %.lr.ph
  call void @write_file(ptr noundef nonnull %2, ptr noundef nonnull %6, ptr noundef nonnull %3) #4
  %13 = load i32, ptr @silent, align 4, !tbaa !20
  %.not14 = icmp eq i32 %13, 0
  br i1 %.not14, label %14, label %25

14:                                               ; preds = %12
  %15 = load ptr, ptr %.018, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !21
  %18 = getelementptr inbounds i8, ptr %15, i64 16
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds i8, ptr %19, i64 48
  %21 = load i64, ptr %20, align 8, !tbaa !22
  %22 = load i32, ptr %3, align 4, !tbaa !20
  %.not15 = icmp eq i32 %22, 0
  %23 = select i1 %.not15, ptr @.str.23, ptr @.str.22
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.21, ptr noundef %17, i64 noundef %21, ptr noundef nonnull %23)
  br label %25

25:                                               ; preds = %14, %12
  %26 = load i64, ptr %2, align 8, !tbaa !23
  %27 = load ptr, ptr %.018, align 8, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  %30 = getelementptr inbounds i8, ptr %29, i64 152
  store i64 %26, ptr %30, align 8, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %29, i64 172
  store i8 2, ptr %31, align 4, !tbaa !24
  br label %40

32:                                               ; preds = %.lr.ph
  %33 = load i32, ptr @silent, align 4, !tbaa !20
  %.not13 = icmp eq i32 %33, 0
  br i1 %.not13, label %34, label %40

34:                                               ; preds = %32
  %35 = getelementptr inbounds i8, ptr %6, i64 8
  %36 = load ptr, ptr %35, align 8, !tbaa !21
  %37 = getelementptr inbounds i8, ptr %8, i64 48
  %38 = load i64, ptr %37, align 8, !tbaa !22
  %39 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.24, ptr noundef %36, i64 noundef %38)
  br label %40

40:                                               ; preds = %25, %34, %32
  %41 = getelementptr inbounds i8, ptr %.018, i64 8
  %.0 = load ptr, ptr %41, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !25

._crit_edge:                                      ; preds = %40, %4
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %.not21 = icmp eq i64 %indvars.iv, 0
  br i1 %.not21, label %42, label %4, !llvm.loop !27

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

declare void @write_file(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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 = { "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 = { 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 = { 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, !6, i64 0}
!10 = !{!"priority_entry", !6, i64 0, !6, i64 8}
!11 = !{!12, !6, i64 16}
!12 = !{!"dir_ent", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!13 = !{!14, !19, i64 152}
!14 = !{!"inode_info", !15, i64 0, !6, i64 144, !19, i64 152, !17, i64 160, !17, i64 164, !17, i64 168, !7, i64 172, !7, i64 173, !7, i64 174, !7, i64 175}
!15 = !{!"stat", !16, i64 0, !16, i64 8, !16, i64 16, !17, i64 24, !17, i64 28, !17, i64 32, !17, i64 36, !16, i64 40, !16, i64 48, !16, i64 56, !16, i64 64, !18, i64 72, !18, i64 88, !18, i64 104, !7, i64 120}
!16 = !{!"long", !7, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!"timespec", !16, i64 0, !16, i64 8}
!19 = !{!"long long", !7, i64 0}
!20 = !{!17, !17, i64 0}
!21 = !{!12, !6, i64 8}
!22 = !{!14, !16, i64 48}
!23 = !{!19, !19, i64 0}
!24 = !{!14, !7, i64 172}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = distinct !{!27, !26}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass