; LLVM IR from clibs/clib :: deps/rimraf (rimraf)

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rimraf(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.stat, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call ptr @opendir(ptr noundef %9)
  store ptr %10, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp eq ptr null, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %1
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %76

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store ptr null, ptr %6, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %68, %31, %14
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call ptr @readdir(ptr noundef %16)
  store ptr %17, ptr %6, align 8, !tbaa !5
  %18 = icmp ne ptr null, %17
  br i1 %18, label %19, label %69

19:                                               ; preds = %15
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.dirent, ptr %20, i32 0, i32 4
  %22 = getelementptr inbounds [256 x i8], ptr %21, i64 0, i64 0
  %23 = call i32 @strcmp(ptr noundef @.str, ptr noundef %22) #6
  %24 = icmp eq i32 0, %23
  br i1 %24, label %31, label %25

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

31:                                               ; preds = %25, %19
  br label %15, !llvm.loop !9

32:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.dirent, ptr %34, i32 0, i32 4
  %36 = getelementptr inbounds [256 x i8], ptr %35, i64 0, i64 0
  %37 = call ptr @path_join(ptr noundef %33, ptr noundef %36)
  store ptr %37, ptr %7, align 8, !tbaa !5
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = icmp eq ptr null, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %32
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %66

41:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 144, ptr %8) #5
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = call i32 @stat(ptr noundef %42, ptr noundef %8) #5
  %44 = icmp ne i32 0, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %41
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %65

46:                                               ; preds = %41
  %47 = getelementptr inbounds %struct.stat, ptr %8, i32 0, i32 3
  %48 = load i32, ptr %47, align 8, !tbaa !11
  %49 = and i32 %48, 16384
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %57

51:                                               ; preds = %46
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = call i32 @rimraf(ptr noundef %52)
  %54 = icmp eq i32 -1, %53
  br i1 %54, label %55, label %56

55:                                               ; preds = %51
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %65

56:                                               ; preds = %51
  br label %63

57:                                               ; preds = %46
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = call i32 @unlink(ptr noundef %58) #5
  %60 = icmp eq i32 -1, %59
  br i1 %60, label %61, label %62

61:                                               ; preds = %57
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %65

62:                                               ; preds = %57
  br label %63

63:                                               ; preds = %62, %56
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %64) #5
  store i32 0, ptr %5, align 4
  br label %65

65:                                               ; preds = %63, %61, %55, %45
  call void @llvm.lifetime.end.p0(i64 144, ptr %8) #5
  br label %66

66:                                               ; preds = %65, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  %67 = load i32, ptr %5, align 4
  switch i32 %67, label %75 [
    i32 0, label %68
  ]

68:                                               ; preds = %66
  br label %15, !llvm.loop !9

69:                                               ; preds = %15
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %70) #5
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = call i32 @closedir(ptr noundef %71)
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = call i32 @rmdir(ptr noundef %73) #5
  store i32 %74, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %75

75:                                               ; preds = %69, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %76

76:                                               ; preds = %75, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %77 = load i32, ptr %2, align 4
  ret i32 %77
}

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

declare ptr @opendir(ptr noundef) #2

declare ptr @readdir(ptr noundef) #2

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

declare ptr @path_join(ptr noundef, ptr noundef) #2

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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

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

declare i32 @closedir(ptr noundef) #2

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

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 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 #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 }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !14, i64 24}
!12 = !{!"stat", !13, i64 0, !13, i64 8, !13, i64 16, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !15, i64 72, !15, i64 88, !15, i64 104, !7, i64 120}
!13 = !{!"long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"timespec", !13, i64 0, !13, i64 8}


; 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.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 }

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @rimraf(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca %struct.stat, align 8
  %3 = tail call ptr @opendir(ptr noundef %0)
  %4 = icmp eq ptr %3, null
  br i1 %4, label %.thread, label %.preheader

.preheader:                                       ; preds = %1
  %5 = tail call ptr @readdir(ptr noundef nonnull %3) #6
  %.not29 = icmp eq ptr %5, null
  br i1 %.not29, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %6 = getelementptr inbounds i8, ptr %2, i64 24
  br label %7

7:                                                ; preds = %.lr.ph, %.backedge
  %8 = phi ptr [ %5, %.lr.ph ], [ %15, %.backedge ]
  %9 = getelementptr inbounds i8, ptr %8, i64 19
  %10 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull dereferenceable(1) %9) #7
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %.backedge, label %12

12:                                               ; preds = %7
  %13 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef nonnull dereferenceable(1) %9) #7
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %.backedge, label %16

.backedge:                                        ; preds = %7, %12, %30
  %15 = tail call ptr @readdir(ptr noundef nonnull %3) #6
  %.not = icmp eq ptr %15, null
  br i1 %.not, label %._crit_edge, label %7, !llvm.loop !5

16:                                               ; preds = %12
  %17 = tail call ptr @path_join(ptr noundef %0, ptr noundef nonnull %9) #6
  %18 = icmp eq ptr %17, null
  br i1 %18, label %.thread, label %19

19:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %2) #6
  %20 = call i32 @stat(ptr noundef nonnull %17, ptr noundef nonnull %2) #6
  %.not22 = icmp eq i32 %20, 0
  br i1 %.not22, label %21, label %.thread26

21:                                               ; preds = %19
  %22 = load i32, ptr %6, align 8, !tbaa !7
  %23 = and i32 %22, 16384
  %.not23 = icmp eq i32 %23, 0
  br i1 %.not23, label %27, label %24

24:                                               ; preds = %21
  %25 = tail call i32 @rimraf(ptr noundef nonnull %17)
  %26 = icmp eq i32 %25, -1
  br i1 %26, label %.thread26, label %30

27:                                               ; preds = %21
  %28 = tail call i32 @unlink(ptr noundef nonnull %17) #6
  %29 = icmp eq i32 %28, -1
  br i1 %29, label %.thread26, label %30

.thread26:                                        ; preds = %19, %24, %27
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %2) #6
  br label %.thread

30:                                               ; preds = %24, %27
  tail call void @free(ptr noundef nonnull %17) #6
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %2) #6
  br label %.backedge

._crit_edge:                                      ; preds = %.backedge, %.preheader
  %31 = tail call i32 @closedir(ptr noundef nonnull %3)
  %32 = tail call i32 @rmdir(ptr noundef %0) #6
  br label %.thread

.thread:                                          ; preds = %16, %.thread26, %._crit_edge, %1
  %.4 = phi i32 [ -1, %1 ], [ %32, %._crit_edge ], [ -1, %.thread26 ], [ -1, %16 ]
  ret i32 %.4
}

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

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

declare ptr @readdir(ptr noundef) local_unnamed_addr #3

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

declare ptr @path_join(ptr noundef, ptr noundef) local_unnamed_addr #3

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

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #5

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @rmdir(ptr nocapture noundef readonly) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 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 #5 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }
attributes #7 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !12, i64 24}
!8 = !{!"stat", !9, i64 0, !9, i64 8, !9, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !9, i64 40, !9, i64 48, !9, i64 56, !9, i64 64, !13, i64 72, !13, i64 88, !13, i64 104, !10, i64 120}
!9 = !{!"long", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"int", !10, i64 0}
!13 = !{!"timespec", !9, i64 0, !9, i64 8}


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