; LLVM IR from wichue/nethello :: src/base/File.ll (ZN3chw11delete_fileEPKc)

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

; 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: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3chw6is_dirEPKc(ptr noundef) #1

declare ptr @opendir(ptr noundef) #2

declare i32 @closedir(ptr noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3chw14is_special_dirEPKc(ptr noundef) #3

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN3chw11delete_fileEPKc(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca [4096 x i8], align 16
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4096, ptr %6) #5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call noundef zeroext i1 @_ZN3chw6is_dirEPKc(ptr noundef %9)
  br i1 %10, label %11, label %43

11:                                               ; preds = %1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = call ptr @opendir(ptr noundef %12)
  store ptr %13, ptr %4, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %18

15:                                               ; preds = %11
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call i32 @rmdir(ptr noundef %16) #5
  store i32 %17, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %53

18:                                               ; preds = %11
  br label %19

19:                                               ; preds = %29, %28, %18
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call ptr @readdir(ptr noundef %20)
  store ptr %21, ptr %5, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %37

23:                                               ; preds = %19
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.dirent, ptr %24, i32 0, i32 4
  %26 = getelementptr inbounds [256 x i8], ptr %25, i64 0, i64 0
  %27 = call noundef zeroext i1 @_ZN3chw14is_special_dirEPKc(ptr noundef %26)
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  br label %19, !llvm.loop !9

29:                                               ; preds = %23
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.dirent, ptr %31, i32 0, i32 4
  %33 = getelementptr inbounds [256 x i8], ptr %32, i64 0, i64 0
  %34 = getelementptr inbounds [4096 x i8], ptr %6, i64 0, i64 0
  call void @_ZN3chw13get_file_pathEPKcS1_Pc(ptr noundef %30, ptr noundef %33, ptr noundef %34)
  %35 = getelementptr inbounds [4096 x i8], ptr %6, i64 0, i64 0
  %36 = call noundef i32 @_ZN3chw11delete_fileEPKc(ptr noundef %35)
  br label %19, !llvm.loop !9

37:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = call i32 @rmdir(ptr noundef %38) #5
  store i32 %39, ptr %8, align 4, !tbaa !11
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = call i32 @closedir(ptr noundef %40)
  %42 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %42, ptr %2, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %53

43:                                               ; preds = %1
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = call i32 @remove(ptr noundef %44) #5
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %50

47:                                               ; preds = %43
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = call i32 @unlink(ptr noundef %48) #5
  br label %51

50:                                               ; preds = %43
  br label %51

51:                                               ; preds = %50, %47
  %52 = phi i32 [ %49, %47 ], [ 0, %50 ]
  store i32 %52, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %53

53:                                               ; preds = %51, %37, %15
  call void @llvm.lifetime.end.p0(i64 4096, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %54 = load i32, ptr %2, align 4
  ret i32 %54
}

; Function Attrs: nounwind
declare i32 @rmdir(ptr noundef) #4

declare ptr @readdir(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @remove(ptr noundef) #4

; Function Attrs: nounwind
declare i32 @unlink(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { mustprogress 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 = { 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 = { 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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


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

; 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: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3chw6is_dirEPKc(ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3chw14is_special_dirEPKc(ptr noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN3chw11delete_fileEPKc(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca [4096 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %2) #5
  %3 = tail call noundef zeroext i1 @_ZN3chw6is_dirEPKc(ptr noundef %0)
  br i1 %3, label %4, label %18

4:                                                ; preds = %1
  %5 = tail call ptr @opendir(ptr noundef %0)
  %6 = icmp eq ptr %5, null
  br i1 %6, label %8, label %.preheader

.preheader:                                       ; preds = %4
  %7 = tail call ptr @readdir(ptr noundef nonnull %5)
  %.not1314 = icmp eq ptr %7, null
  br i1 %.not1314, label %._crit_edge, label %.lr.ph

8:                                                ; preds = %4
  %9 = tail call i32 @rmdir(ptr noundef %0) #5
  br label %22

.lr.ph:                                           ; preds = %.preheader, %.backedge
  %10 = phi ptr [ %15, %.backedge ], [ %7, %.preheader ]
  %11 = getelementptr inbounds i8, ptr %10, i64 19
  %12 = call noundef zeroext i1 @_ZN3chw14is_special_dirEPKc(ptr noundef nonnull %11)
  br i1 %12, label %.backedge, label %13

13:                                               ; preds = %.lr.ph
  call void @_ZN3chw13get_file_pathEPKcS1_Pc(ptr noundef %0, ptr noundef nonnull %11, ptr noundef nonnull %2)
  %14 = call noundef i32 @_ZN3chw11delete_fileEPKc(ptr noundef nonnull %2)
  br label %.backedge

.backedge:                                        ; preds = %13, %.lr.ph
  %15 = call ptr @readdir(ptr noundef nonnull %5)
  %.not13 = icmp eq ptr %15, null
  br i1 %.not13, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.backedge, %.preheader
  %16 = call i32 @rmdir(ptr noundef %0) #5
  %17 = call i32 @closedir(ptr noundef nonnull %5)
  br label %22

18:                                               ; preds = %1
  %19 = tail call i32 @remove(ptr noundef %0) #5
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %22, label %20

20:                                               ; preds = %18
  %21 = tail call i32 @unlink(ptr noundef %0) #5
  br label %22

22:                                               ; preds = %20, %18, %._crit_edge, %8
  %.0 = phi i32 [ %9, %8 ], [ %16, %._crit_edge ], [ %21, %20 ], [ 0, %18 ]
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %2) #5
  ret i32 %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @rmdir(ptr nocapture noundef readonly) local_unnamed_addr #2

declare ptr @readdir(ptr noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @remove(ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @unlink(ptr nocapture noundef readonly) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 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 #3 = { mustprogress 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 = { "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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