; LLVM IR from artagnon/phoenixfs :: loose (packup_loose_objects)

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

@looseroot = external dso_local global %struct.loose_buf, align 8
@.str = external hidden unnamed_addr constant [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [50 x i8], align 1
@xpath = external hidden global [4096 x i8], align 16
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [54 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @add_loose_entry(ptr noundef, i64 noundef) #0

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

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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

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

declare i32 @fclose(ptr noundef) #2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: nounwind uwtable
define dso_local void @packup_loose_objects(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca %struct.stat, align 8
  %12 = alloca i8, align 1
  %13 = alloca [40 x i8], align 16
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca [20 x i8], align 16
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  %21 = alloca ptr, align 8
  %22 = alloca ptr, align 8
  %23 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 144, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #5
  store i8 0, ptr %12, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 40, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 20, ptr %16) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %39

26:                                               ; preds = %4
  %27 = load i32, ptr @looseroot, align 8, !tbaa !13
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %39, label %29

29:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #5
  %30 = call noalias ptr @fopen(ptr noundef @.str, ptr noundef @.str.1)
  store ptr %30, ptr %19, align 8, !tbaa !5
  %31 = load ptr, ptr %19, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %38

33:                                               ; preds = %29
  %34 = load ptr, ptr %19, align 8, !tbaa !5
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef @.str.3, i32 noundef 51) #5
  %36 = load ptr, ptr %19, align 8, !tbaa !5
  %37 = call i32 @fclose(ptr noundef %36)
  br label %38

38:                                               ; preds = %33, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  store i32 1, ptr %20, align 4
  br label %167

39:                                               ; preds = %26, %4
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = call i32 @fseek(ptr noundef %40, i64 noundef 0, i32 noundef 2)
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %112, %39
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = load i32, ptr @looseroot, align 8, !tbaa !13
  %45 = icmp ult i32 %43, %44
  br i1 %45, label %46, label %115

46:                                               ; preds = %42
  %47 = load ptr, ptr getelementptr inbounds (%struct.loose_buf, ptr @looseroot, i32 0, i32 1), align 8, !tbaa !15
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds ptr, ptr %47, i64 %49
  %51 = load ptr, ptr %50, align 8, !tbaa !5
  store ptr %51, ptr %14, align 8, !tbaa !5
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = call i64 @ftell(ptr noundef %52)
  %54 = load ptr, ptr %14, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.pack_idx_entry, ptr %54, i32 0, i32 1
  store i64 %53, ptr %55, align 8, !tbaa !16
  %56 = load ptr, ptr %14, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.pack_idx_entry, ptr %56, i32 0, i32 0
  %58 = getelementptr inbounds [20 x i8], ptr %57, i64 0, i64 0
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = call i64 @fwrite(ptr noundef %58, i64 noundef 20, i64 noundef 1, ptr noundef %59)
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = call i64 @fwrite(ptr noundef %12, i64 noundef 1, i64 noundef 1, ptr noundef %61)
  %63 = getelementptr inbounds [40 x i8], ptr %13, i64 0, i64 0
  %64 = load ptr, ptr %14, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.pack_idx_entry, ptr %64, i32 0, i32 0
  %66 = getelementptr inbounds [20 x i8], ptr %65, i64 0, i64 0
  call void @print_sha1(ptr noundef %63, ptr noundef %66)
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds [40 x i8], ptr %13, i64 0, i64 0
  %69 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef @xpath, ptr noundef @.str.4, ptr noundef %67, ptr noundef %68) #5
  %70 = call i32 @lstat(ptr noundef @xpath, ptr noundef %11) #5
  %71 = icmp slt i32 %70, 0
  br i1 %71, label %75, label %72

72:                                               ; preds = %46
  %73 = call noalias ptr @fopen(ptr noundef @xpath, ptr noundef @.str.5)
  store ptr %73, ptr %10, align 8, !tbaa !5
  %74 = icmp ne ptr %73, null
  br i1 %74, label %87, label %75

75:                                               ; preds = %72, %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #5
  %76 = call noalias ptr @fopen(ptr noundef @.str, ptr noundef @.str.1)
  store ptr %76, ptr %21, align 8, !tbaa !5
  %77 = load ptr, ptr %21, align 8, !tbaa !5
  %78 = icmp ne ptr %77, null
  br i1 %78, label %79, label %85

79:                                               ; preds = %75
  %80 = load ptr, ptr %21, align 8, !tbaa !5
  %81 = getelementptr inbounds [40 x i8], ptr %13, i64 0, i64 0
  %82 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %80, ptr noundef @.str.6, i32 noundef 72, ptr noundef %81) #5
  %83 = load ptr, ptr %21, align 8, !tbaa !5
  %84 = call i32 @fclose(ptr noundef %83)
  br label %85

85:                                               ; preds = %79, %75
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #5
  %86 = call noalias ptr @fopen(ptr noundef @xpath, ptr noundef @.str.7)
  store ptr %86, ptr %10, align 8, !tbaa !5
  br label %87

87:                                               ; preds = %85, %72
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #5
  %88 = call noalias ptr @fopen(ptr noundef @.str, ptr noundef @.str.1)
  store ptr %88, ptr %22, align 8, !tbaa !5
  %89 = load ptr, ptr %22, align 8, !tbaa !5
  %90 = icmp ne ptr %89, null
  br i1 %90, label %91, label %101

91:                                               ; preds = %87
  %92 = load ptr, ptr %22, align 8, !tbaa !5
  %93 = getelementptr inbounds [40 x i8], ptr %13, i64 0, i64 0
  %94 = load i32, ptr %9, align 4, !tbaa !9
  %95 = load ptr, ptr %14, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.pack_idx_entry, ptr %95, i32 0, i32 1
  %97 = load i64, ptr %96, align 8, !tbaa !16
  %98 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %92, ptr noundef @.str.8, i32 noundef 76, ptr noundef %93, i32 noundef %94, i64 noundef %97) #5
  %99 = load ptr, ptr %22, align 8, !tbaa !5
  %100 = call i32 @fclose(ptr noundef %99)
  br label %101

101:                                              ; preds = %91, %87
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #5
  %102 = getelementptr inbounds %struct.stat, ptr %11, i32 0, i32 8
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = call i64 @fwrite(ptr noundef %102, i64 noundef 8, i64 noundef 1, ptr noundef %103)
  %105 = load ptr, ptr %10, align 8, !tbaa !5
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.stat, ptr %11, i32 0, i32 8
  %108 = load i64, ptr %107, align 8, !tbaa !19
  %109 = call i64 @buffer_copy_bytes(ptr noundef %105, ptr noundef %106, i64 noundef %108)
  %110 = load ptr, ptr %10, align 8, !tbaa !5
  %111 = call i32 @fclose(ptr noundef %110)
  br label %112

112:                                              ; preds = %101
  %113 = load i32, ptr %9, align 4, !tbaa !9
  %114 = add nsw i32 %113, 1
  store i32 %114, ptr %9, align 4, !tbaa !9
  br label %42, !llvm.loop !22

115:                                              ; preds = %42
  %116 = load ptr, ptr %6, align 8, !tbaa !5
  %117 = icmp ne ptr %116, null
  br i1 %117, label %121, label %118

118:                                              ; preds = %115
  %119 = load ptr, ptr getelementptr inbounds (%struct.loose_buf, ptr @looseroot, i32 0, i32 1), align 8, !tbaa !15
  %120 = load i32, ptr @looseroot, align 8, !tbaa !13
  call void @unmap_write_idx(ptr noundef %119, i32 noundef %120)
  store i32 1, ptr %20, align 4
  br label %167

121:                                              ; preds = %115
  %122 = load ptr, ptr %6, align 8, !tbaa !5
  %123 = getelementptr inbounds i8, ptr %122, i64 8
  %124 = getelementptr inbounds i8, ptr %123, i64 1024
  store ptr %124, ptr %15, align 8, !tbaa !5
  %125 = load i32, ptr @looseroot, align 8, !tbaa !13
  store i32 %125, ptr %18, align 4, !tbaa !9
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %126

126:                                              ; preds = %161, %121
  %127 = load i32, ptr %9, align 4, !tbaa !9
  %128 = load i32, ptr %7, align 4, !tbaa !9
  %129 = icmp ult i32 %127, %128
  br i1 %129, label %130, label %164

130:                                              ; preds = %126
  %131 = load ptr, ptr %15, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %16, ptr align 1 %131, i64 20, i1 false)
  %132 = getelementptr inbounds [40 x i8], ptr %13, i64 0, i64 0
  %133 = getelementptr inbounds [20 x i8], ptr %16, i64 0, i64 0
  call void @print_sha1(ptr noundef %132, ptr noundef %133)
  %134 = getelementptr inbounds [20 x i8], ptr %16, i64 0, i64 0
  call void @add_loose_entry(ptr noundef %134, i64 noundef 0)
  %135 = getelementptr inbounds [20 x i8], ptr %16, i64 0, i64 0
  %136 = call i64 @find_pack_entry(ptr noundef %135)
  store i64 %136, ptr %17, align 8, !tbaa !24
  %137 = icmp ne i64 %136, 0
  br i1 %137, label %149, label %138

138:                                              ; preds = %130
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #5
  %139 = call noalias ptr @fopen(ptr noundef @.str, ptr noundef @.str.1)
  store ptr %139, ptr %23, align 8, !tbaa !5
  %140 = load ptr, ptr %23, align 8, !tbaa !5
  %141 = icmp ne ptr %140, null
  br i1 %141, label %142, label %148

142:                                              ; preds = %138
  %143 = load ptr, ptr %23, align 8, !tbaa !5
  %144 = getelementptr inbounds [40 x i8], ptr %13, i64 0, i64 0
  %145 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %143, ptr noundef @.str.9, i32 noundef 99, ptr noundef %144) #5
  %146 = load ptr, ptr %23, align 8, !tbaa !5
  %147 = call i32 @fclose(ptr noundef %146)
  br label %148

148:                                              ; preds = %142, %138
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #5
  br label %149

149:                                              ; preds = %148, %130
  %150 = load i64, ptr %17, align 8, !tbaa !24
  %151 = load ptr, ptr getelementptr inbounds (%struct.loose_buf, ptr @looseroot, i32 0, i32 1), align 8, !tbaa !15
  %152 = load i32, ptr %9, align 4, !tbaa !9
  %153 = load i32, ptr %18, align 4, !tbaa !9
  %154 = add nsw i32 %152, %153
  %155 = sext i32 %154 to i64
  %156 = getelementptr inbounds ptr, ptr %151, i64 %155
  %157 = load ptr, ptr %156, align 8, !tbaa !5
  %158 = getelementptr inbounds %struct.pack_idx_entry, ptr %157, i32 0, i32 1
  store i64 %150, ptr %158, align 8, !tbaa !16
  %159 = load ptr, ptr %15, align 8, !tbaa !5
  %160 = getelementptr inbounds i8, ptr %159, i64 20
  store ptr %160, ptr %15, align 8, !tbaa !5
  br label %161

161:                                              ; preds = %149
  %162 = load i32, ptr %9, align 4, !tbaa !9
  %163 = add nsw i32 %162, 1
  store i32 %163, ptr %9, align 4, !tbaa !9
  br label %126, !llvm.loop !25

164:                                              ; preds = %126
  %165 = load ptr, ptr getelementptr inbounds (%struct.loose_buf, ptr @looseroot, i32 0, i32 1), align 8, !tbaa !15
  %166 = load i32, ptr @looseroot, align 8, !tbaa !13
  call void @unmap_write_idx(ptr noundef %165, i32 noundef %166)
  store i32 0, ptr %20, align 4
  br label %167

167:                                              ; preds = %164, %118, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 20, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 144, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  %168 = load i32, ptr %20, align 4
  switch i32 %168, label %170 [
    i32 0, label %169
    i32 1, label %169
  ]

169:                                              ; preds = %167, %167
  ret void

170:                                              ; preds = %167
  unreachable
}

declare i32 @fseek(ptr noundef, i64 noundef, i32 noundef) #2

declare i64 @ftell(ptr noundef) #2

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

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

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

declare i64 @buffer_copy_bytes(ptr noundef, ptr noundef, i64 noundef) #2

declare void @unmap_write_idx(ptr noundef, i32 noundef) #2

declare i64 @find_pack_entry(ptr noundef) #2

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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"loose_buf", !10, i64 0, !6, i64 8}
!15 = !{!14, !6, i64 8}
!16 = !{!17, !18, i64 24}
!17 = !{!"pack_idx_entry", !7, i64 0, !18, i64 24, !18, i64 32}
!18 = !{!"long", !7, i64 0}
!19 = !{!20, !18, i64 48}
!20 = !{!"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, !21, i64 72, !21, i64 88, !21, i64 104, !7, i64 120}
!21 = !{!"timespec", !18, i64 0, !18, i64 8}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!18, !18, i64 0}
!25 = distinct !{!25, !23}


; 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.loose_buf = type { i32, ptr }
%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 }

@looseroot = external dso_local local_unnamed_addr global %struct.loose_buf, align 8
@.str = external hidden unnamed_addr constant [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [50 x i8], align 1
@xpath = external hidden global [4096 x i8], align 16
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [54 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @add_loose_entry(ptr noundef, i64 noundef) local_unnamed_addr #0

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

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

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

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

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

; 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 nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: nounwind uwtable
define dso_local void @packup_loose_objects(ptr noundef %0, ptr noundef readonly %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.stat, align 8
  %6 = alloca [40 x i8], align 16
  %7 = alloca [20 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %5) #6
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %6) #6
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %7) #6
  %8 = icmp eq ptr %1, null
  %9 = load i32, ptr @looseroot, align 8
  %10 = icmp ne i32 %9, 0
  %or.cond = select i1 %8, i1 true, i1 %10
  br i1 %or.cond, label %16, label %11

11:                                               ; preds = %4
  %12 = tail call noalias ptr @fopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1)
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %75, label %13

13:                                               ; preds = %11
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %12, ptr noundef nonnull @.str.3, i32 noundef 51) #6
  %15 = tail call i32 @fclose(ptr noundef nonnull %12)
  br label %75

16:                                               ; preds = %4
  %17 = tail call i32 @fseek(ptr noundef %0, i64 noundef 0, i32 noundef 2)
  %18 = load i32, ptr @looseroot, align 8, !tbaa !5
  %.not61 = icmp eq i32 %18, 0
  br i1 %.not61, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %16
  %19 = getelementptr inbounds i8, ptr %5, i64 48
  br label %20

20:                                               ; preds = %.lr.ph, %46
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %46 ]
  %21 = load ptr, ptr getelementptr inbounds (i8, ptr @looseroot, i64 8), align 8, !tbaa !11
  %22 = getelementptr inbounds ptr, ptr %21, i64 %indvars.iv
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  %24 = call i64 @ftell(ptr noundef %0)
  %25 = getelementptr inbounds i8, ptr %23, i64 24
  store i64 %24, ptr %25, align 8, !tbaa !13
  %26 = call i64 @fwrite(ptr noundef %23, i64 noundef 20, i64 noundef 1, ptr noundef %0)
  %fputc = call i32 @fputc(i32 0, ptr %0)
  call void @print_sha1(ptr noundef nonnull %6, ptr noundef %23) #6
  %27 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) @xpath, ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef %3, ptr noundef nonnull %6) #6
  %28 = call i32 @lstat(ptr noundef nonnull @xpath, ptr noundef nonnull %5) #6
  %29 = icmp slt i32 %28, 0
  br i1 %29, label %32, label %30

30:                                               ; preds = %20
  %31 = call noalias ptr @fopen(ptr noundef nonnull @xpath, ptr noundef nonnull @.str.5)
  %.not52 = icmp eq ptr %31, null
  br i1 %.not52, label %32, label %39

32:                                               ; preds = %30, %20
  %33 = call noalias ptr @fopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1)
  %.not53 = icmp eq ptr %33, null
  br i1 %.not53, label %37, label %34

34:                                               ; preds = %32
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %33, ptr noundef nonnull @.str.6, i32 noundef 72, ptr noundef nonnull %6) #6
  %36 = call i32 @fclose(ptr noundef nonnull %33)
  br label %37

37:                                               ; preds = %34, %32
  %38 = call noalias ptr @fopen(ptr noundef nonnull @xpath, ptr noundef nonnull @.str.7)
  br label %39

39:                                               ; preds = %37, %30
  %.040 = phi ptr [ %38, %37 ], [ %31, %30 ]
  %40 = call noalias ptr @fopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1)
  %.not54 = icmp eq ptr %40, null
  br i1 %.not54, label %46, label %41

41:                                               ; preds = %39
  %42 = load i64, ptr %25, align 8, !tbaa !13
  %43 = trunc nuw nsw i64 %indvars.iv to i32
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %40, ptr noundef nonnull @.str.8, i32 noundef 76, ptr noundef nonnull %6, i32 noundef %43, i64 noundef %42) #6
  %45 = call i32 @fclose(ptr noundef nonnull %40)
  br label %46

46:                                               ; preds = %41, %39
  %47 = call i64 @fwrite(ptr noundef nonnull %19, i64 noundef 8, i64 noundef 1, ptr noundef %0)
  %48 = load i64, ptr %19, align 8, !tbaa !16
  %49 = call i64 @buffer_copy_bytes(ptr noundef %.040, ptr noundef %0, i64 noundef %48) #6
  %50 = call i32 @fclose(ptr noundef %.040)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %51 = load i32, ptr @looseroot, align 8, !tbaa !5
  %52 = zext i32 %51 to i64
  %53 = icmp ult i64 %indvars.iv.next, %52
  br i1 %53, label %20, label %._crit_edge, !llvm.loop !19

._crit_edge:                                      ; preds = %46, %16
  %54 = phi i32 [ 0, %16 ], [ %51, %46 ]
  br i1 %8, label %55, label %57

55:                                               ; preds = %._crit_edge
  %56 = load ptr, ptr getelementptr inbounds (i8, ptr @looseroot, i64 8), align 8, !tbaa !11
  call void @unmap_write_idx(ptr noundef %56, i32 noundef %54) #6
  br label %75

57:                                               ; preds = %._crit_edge
  %.not62 = icmp eq i32 %2, 0
  br i1 %.not62, label %.._crit_edge60_crit_edge, label %.lr.ph59.preheader

.._crit_edge60_crit_edge:                         ; preds = %57
  %.pre = load ptr, ptr getelementptr inbounds (i8, ptr @looseroot, i64 8), align 8, !tbaa !11
  br label %._crit_edge60

.lr.ph59.preheader:                               ; preds = %57
  %58 = getelementptr inbounds i8, ptr %1, i64 1032
  %59 = sext i32 %54 to i64
  %wide.trip.count = zext i32 %2 to i64
  br label %.lr.ph59

.lr.ph59:                                         ; preds = %.lr.ph59.preheader, %66
  %indvars.iv65 = phi i64 [ 0, %.lr.ph59.preheader ], [ %indvars.iv.next66, %66 ]
  %.04156 = phi ptr [ %58, %.lr.ph59.preheader ], [ %72, %66 ]
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(20) %7, ptr noundef nonnull align 1 dereferenceable(20) %.04156, i64 20, i1 false)
  call void @print_sha1(ptr noundef nonnull %6, ptr noundef nonnull %7) #6
  call void @add_loose_entry(ptr noundef nonnull %7, i64 noundef 0)
  %60 = call i64 @find_pack_entry(ptr noundef nonnull %7) #6
  %.not50 = icmp eq i64 %60, 0
  br i1 %.not50, label %61, label %66

61:                                               ; preds = %.lr.ph59
  %62 = call noalias ptr @fopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1)
  %.not51 = icmp eq ptr %62, null
  br i1 %.not51, label %66, label %63

63:                                               ; preds = %61
  %64 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %62, ptr noundef nonnull @.str.9, i32 noundef 99, ptr noundef nonnull %6) #6
  %65 = call i32 @fclose(ptr noundef nonnull %62)
  br label %66

66:                                               ; preds = %61, %63, %.lr.ph59
  %67 = load ptr, ptr getelementptr inbounds (i8, ptr @looseroot, i64 8), align 8, !tbaa !11
  %68 = getelementptr ptr, ptr %67, i64 %indvars.iv65
  %69 = getelementptr ptr, ptr %68, i64 %59
  %70 = load ptr, ptr %69, align 8, !tbaa !12
  %71 = getelementptr inbounds i8, ptr %70, i64 24
  store i64 %60, ptr %71, align 8, !tbaa !13
  %72 = getelementptr inbounds i8, ptr %.04156, i64 20
  %indvars.iv.next66 = add nuw nsw i64 %indvars.iv65, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next66, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge60.loopexit, label %.lr.ph59, !llvm.loop !21

._crit_edge60.loopexit:                           ; preds = %66
  %.pre68 = load i32, ptr @looseroot, align 8, !tbaa !5
  br label %._crit_edge60

._crit_edge60:                                    ; preds = %.._crit_edge60_crit_edge, %._crit_edge60.loopexit
  %73 = phi i32 [ %54, %.._crit_edge60_crit_edge ], [ %.pre68, %._crit_edge60.loopexit ]
  %74 = phi ptr [ %.pre, %.._crit_edge60_crit_edge ], [ %67, %._crit_edge60.loopexit ]
  call void @unmap_write_idx(ptr noundef %74, i32 noundef %73) #6
  br label %75

75:                                               ; preds = %11, %13, %._crit_edge60, %55
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %7) #6
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %6) #6
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %5) #6
  ret void
}

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

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

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #3

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

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

declare i64 @buffer_copy_bytes(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare void @unmap_write_idx(ptr noundef, i32 noundef) local_unnamed_addr #2

declare i64 @find_pack_entry(ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fputc(i32 noundef, ptr nocapture noundef) local_unnamed_addr #5

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 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nofree nounwind }
attributes #6 = { 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, !7, i64 0}
!6 = !{!"loose_buf", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !15, i64 24}
!14 = !{!"pack_idx_entry", !8, i64 0, !15, i64 24, !15, i64 32}
!15 = !{!"long", !8, i64 0}
!16 = !{!17, !15, i64 48}
!17 = !{!"stat", !15, i64 0, !15, i64 8, !15, i64 16, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !15, i64 40, !15, i64 48, !15, i64 56, !15, i64 64, !18, i64 72, !18, i64 88, !18, i64 104, !8, i64 120}
!18 = !{!"timespec", !15, i64 0, !15, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


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