; LLVM IR from jspd-group/pegit :: src (checkout)

; 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.revert_opts = type { i32, i32, %struct.strbuf_list, i32, i32, i8, i32, i32, i32 }
%struct.strbuf_list = type { ptr, ptr, i64 }
%struct.pack_file_cache = type { ptr, %struct.strbuf }
%struct.strbuf = type { i64, i64, ptr }
%struct.index_list = type { ptr, ptr }
%struct.index = type { [256 x i8], %struct.stat, i8, i64, i64, i64 }
%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 }

@count_modified = external global i32, align 4
@count_new = external global i32, align 4
@rev_opts = external dso_local global %struct.revert_opts, align 8
@.str.27 = external hidden unnamed_addr constant [34 x i8], align 1
@__const.revert_all_files.cache = external hidden unnamed_addr constant %struct.pack_file_cache, align 8

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

declare void @strbuf_release(ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @revert_file(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @check_and_mkdir(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @revert_all_files(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca %struct.pack_file_cache, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load i32, ptr @count_new, align 4, !tbaa !9
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %7, label %15

7:                                                ; preds = %1
  %8 = load i32, ptr @count_modified, align 4, !tbaa !9
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %15

10:                                               ; preds = %7
  %11 = load i32, ptr getelementptr inbounds (%struct.revert_opts, ptr @rev_opts, i32 0, i32 3), align 8, !tbaa !11
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %15, label %13

13:                                               ; preds = %10
  %14 = call i32 (ptr, ...) @printf(ptr noundef @.str.27)
  br label %35

15:                                               ; preds = %10, %7, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %16, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %4) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 @__const.revert_all_files.cache, i64 32, i1 false)
  %17 = call i32 @cache_pack_file(ptr noundef %4)
  br label %18

18:                                               ; preds = %21, %15
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %33

21:                                               ; preds = %18
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.index_list, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  %25 = getelementptr inbounds %struct.index, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds [256 x i8], ptr %25, i64 0, i64 0
  call void @check_and_mkdir(ptr noundef %26)
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.index_list, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  call void @revert_file(ptr noundef %4, ptr noundef %29)
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.index_list, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  store ptr %32, ptr %3, align 8, !tbaa !5
  br label %18, !llvm.loop !18

33:                                               ; preds = %18
  %34 = getelementptr inbounds %struct.pack_file_cache, ptr %4, i32 0, i32 1
  call void @strbuf_release(ptr noundef %34)
  call void @llvm.lifetime.end.p0(i64 32, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  br label %35

35:                                               ; preds = %33, %13
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cache_pack_file(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 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 #4 = { inlinehint 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 #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, !10, i64 32}
!12 = !{!"revert_opts", !10, i64 0, !10, i64 4, !13, i64 8, !10, i64 32, !10, i64 36, !7, i64 40, !10, i64 44, !10, i64 48, !10, i64 52}
!13 = !{!"strbuf_list", !6, i64 0, !6, i64 8, !14, i64 16}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"index_list", !6, i64 0, !6, i64 8}
!17 = !{!16, !6, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"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.revert_opts = type { i32, i32, %struct.strbuf_list, i32, i32, i8, i32, i32, i32 }
%struct.strbuf_list = type { ptr, ptr, i64 }
%struct.pack_file_cache = type { ptr, %struct.strbuf }
%struct.strbuf = type { i64, i64, ptr }

@count_modified = external local_unnamed_addr global i32, align 4
@count_new = external local_unnamed_addr global i32, align 4
@rev_opts = external dso_local local_unnamed_addr global %struct.revert_opts, align 8
@.str.27 = external hidden unnamed_addr constant [34 x i8], align 1
@__const.revert_all_files.cache = external hidden unnamed_addr constant %struct.pack_file_cache, align 8

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

declare void @strbuf_release(ptr noundef) local_unnamed_addr #2

; 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 nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @revert_file(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare dso_local void @check_and_mkdir(ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local void @revert_all_files(ptr noundef readonly %0) local_unnamed_addr #4 {
  %2 = alloca %struct.pack_file_cache, align 8
  %3 = load i32, ptr @count_new, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 0
  %5 = load i32, ptr @count_modified, align 4
  %6 = icmp eq i32 %5, 0
  %or.cond.not9 = select i1 %4, i1 true, i1 %6
  %7 = load i32, ptr getelementptr inbounds (i8, ptr @rev_opts, i64 32), align 8
  %8 = icmp ne i32 %7, 0
  %or.cond3 = select i1 %or.cond.not9, i1 true, i1 %8
  br i1 %or.cond3, label %11, label %9

9:                                                ; preds = %1
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.27)
  br label %18

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %2, ptr noundef nonnull align 8 dereferenceable(32) @__const.revert_all_files.cache, i64 32, i1 false)
  %12 = call i32 @cache_pack_file(ptr noundef nonnull %2)
  %.not10 = icmp eq ptr %0, null
  br i1 %.not10, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11, %.lr.ph
  %.011 = phi ptr [ %16, %.lr.ph ], [ %0, %11 ]
  %13 = load ptr, ptr %.011, align 8, !tbaa !9
  call void @check_and_mkdir(ptr noundef %13)
  %14 = load ptr, ptr %.011, align 8, !tbaa !9
  call void @revert_file(ptr noundef nonnull %2, ptr noundef %14)
  %15 = getelementptr inbounds i8, ptr %.011, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %11
  %17 = getelementptr inbounds i8, ptr %2, i64 8
  call void @strbuf_release(ptr noundef nonnull %17) #6
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #6
  br label %18

18:                                               ; preds = %._crit_edge, %9
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cache_pack_file(ptr noundef) local_unnamed_addr #5

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree 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 = { 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 #5 = { inlinehint 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 #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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"index_list", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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