; LLVM IR from ihucos/plash :: clean (delete_unused_tmpdirs_here)

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

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 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

declare ptr @opendir(ptr noundef) #1

declare i32 @pl_fatal(ptr noundef, ...) #1

declare ptr @readdir(ptr noundef) #1

declare i32 @closedir(ptr noundef) #1

; 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
declare dso_local i32 @is_process_still_running(i32 noundef, i32 noundef) #2

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

11:                                               ; preds = %0
  %12 = call i32 (ptr, ...) @pl_fatal(ptr noundef @.str.1)
  br label %13

13:                                               ; preds = %11, %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  br label %14

14:                                               ; preds = %63, %41, %37, %13
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = call ptr @readdir(ptr noundef %15)
  store ptr %16, ptr %6, align 8, !tbaa !9
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %64

18:                                               ; preds = %14
  %19 = load ptr, ptr %6, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.dirent, ptr %19, i32 0, i32 3
  %21 = load i8, ptr %20, align 2, !tbaa !11
  %22 = zext i8 %21 to i32
  %23 = icmp eq i32 %22, 4
  br i1 %23, label %24, label %63

24:                                               ; preds = %18
  %25 = load ptr, ptr %6, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.dirent, ptr %25, i32 0, i32 4
  %27 = getelementptr inbounds [256 x i8], ptr %26, i64 0, i64 0
  %28 = call noalias ptr @strdup(ptr noundef %27) #5
  store ptr %28, ptr %2, align 8, !tbaa !9
  %29 = icmp eq ptr %28, null
  br i1 %29, label %30, label %32

30:                                               ; preds = %24
  %31 = call i32 (ptr, ...) @pl_fatal(ptr noundef @.str.2)
  br label %32

32:                                               ; preds = %30, %24
  %33 = load ptr, ptr %2, align 8, !tbaa !9
  %34 = call ptr @strtok(ptr noundef %33, ptr noundef @.str.3) #5
  %35 = call ptr @strtok(ptr noundef null, ptr noundef @.str.3) #5
  store ptr %35, ptr %3, align 8, !tbaa !9
  %36 = icmp eq ptr %35, null
  br i1 %36, label %37, label %38

37:                                               ; preds = %32
  br label %14, !llvm.loop !14

38:                                               ; preds = %32
  %39 = call ptr @strtok(ptr noundef null, ptr noundef @.str.3) #5
  store ptr %39, ptr %4, align 8, !tbaa !9
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %42

41:                                               ; preds = %38
  br label %14, !llvm.loop !14

42:                                               ; preds = %38
  %43 = load ptr, ptr %3, align 8, !tbaa !9
  %44 = call i64 @atoll(ptr noundef %43) #6
  %45 = trunc i64 %44 to i32
  %46 = load ptr, ptr %4, align 8, !tbaa !9
  %47 = call i64 @atoll(ptr noundef %46) #6
  %48 = trunc i64 %47 to i32
  %49 = call i32 @is_process_still_running(i32 noundef %45, i32 noundef %48)
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %61, label %51

51:                                               ; preds = %42
  store ptr @.str.4, ptr %7, align 8, !tbaa !9
  %52 = getelementptr inbounds ptr, ptr %7, i64 1
  store ptr @.str.5, ptr %52, align 8, !tbaa !9
  %53 = getelementptr inbounds ptr, ptr %7, i64 2
  %54 = load ptr, ptr %6, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.dirent, ptr %54, i32 0, i32 4
  %56 = getelementptr inbounds [256 x i8], ptr %55, i64 0, i64 0
  store ptr %56, ptr %53, align 8, !tbaa !9
  %57 = getelementptr inbounds ptr, ptr %7, i64 3
  store ptr null, ptr %57, align 8, !tbaa !9
  %58 = getelementptr inbounds [4 x ptr], ptr %7, i64 0, i64 0
  call void @_pl_run(ptr noundef %58)
  %59 = load i64, ptr %1, align 8, !tbaa !5
  %60 = add i64 %59, 1
  store i64 %60, ptr %1, align 8, !tbaa !5
  br label %61

61:                                               ; preds = %51, %42
  %62 = load ptr, ptr %2, align 8, !tbaa !9
  call void @free(ptr noundef %62) #5
  br label %63

63:                                               ; preds = %61, %18
  br label %14, !llvm.loop !14

64:                                               ; preds = %14
  %65 = load ptr, ptr %5, align 8, !tbaa !9
  %66 = call i32 @closedir(ptr noundef %65)
  %67 = load i64, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, 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
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  ret i64 %67
}

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #3

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

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i64 @atoll(ptr noundef nonnull) #4

declare void @_pl_run(ptr noundef) #1

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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 = { inlinehint nounwind willreturn memory(read) 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 }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !7, i64 18}
!12 = !{!"dirent", !6, i64 0, !6, i64 8, !13, i64 16, !7, i64 18, !7, i64 19}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

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

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

declare i32 @pl_fatal(ptr noundef, ...) local_unnamed_addr #1

declare ptr @readdir(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @is_process_still_running(i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i64 @delete_unused_tmpdirs_here() local_unnamed_addr #2 {
  %1 = alloca [4 x ptr], align 8
  %2 = tail call ptr @opendir(ptr noundef nonnull @.str)
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %6

4:                                                ; preds = %0
  %5 = tail call i32 (ptr, ...) @pl_fatal(ptr noundef nonnull @.str.1) #7
  br label %6

6:                                                ; preds = %4, %0
  %7 = tail call ptr @readdir(ptr noundef %2) #7
  %.not1820 = icmp eq ptr %7, null
  br i1 %.not1820, label %.outer._crit_edge, label %.lr.ph.lr.ph

.lr.ph.lr.ph:                                     ; preds = %6
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = getelementptr inbounds i8, ptr %1, i64 16
  %10 = getelementptr inbounds i8, ptr %1, i64 24
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.lr.ph, %.outer
  %11 = phi ptr [ %7, %.lr.ph.lr.ph ], [ %40, %.outer ]
  %.0.ph21 = phi i64 [ 0, %.lr.ph.lr.ph ], [ %.2, %.outer ]
  br label %12

12:                                               ; preds = %.lr.ph, %.backedge
  %13 = phi ptr [ %11, %.lr.ph ], [ %27, %.backedge ]
  %14 = getelementptr inbounds i8, ptr %13, i64 18
  %15 = load i8, ptr %14, align 2, !tbaa !5
  %16 = icmp eq i8 %15, 4
  br i1 %16, label %17, label %.outer

17:                                               ; preds = %12
  %18 = getelementptr inbounds i8, ptr %13, i64 19
  %19 = call noalias ptr @strdup(ptr noundef nonnull %18) #7
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %23

21:                                               ; preds = %17
  %22 = call i32 (ptr, ...) @pl_fatal(ptr noundef nonnull @.str.2) #7
  br label %23

23:                                               ; preds = %21, %17
  %24 = call ptr @strtok(ptr noundef %19, ptr noundef nonnull @.str.3) #7
  %25 = call ptr @strtok(ptr noundef null, ptr noundef nonnull @.str.3) #7
  %26 = icmp eq ptr %25, null
  br i1 %26, label %.backedge, label %28

.backedge:                                        ; preds = %23, %28
  %27 = call ptr @readdir(ptr noundef %2) #7
  %.not = icmp eq ptr %27, null
  br i1 %.not, label %.outer._crit_edge, label %12, !llvm.loop !11

28:                                               ; preds = %23
  %29 = call ptr @strtok(ptr noundef null, ptr noundef nonnull @.str.3) #7
  %30 = icmp eq ptr %29, null
  br i1 %30, label %.backedge, label %31

31:                                               ; preds = %28
  %32 = call i64 @atoll(ptr nocapture noundef %25) #8
  %33 = trunc i64 %32 to i32
  %34 = call i64 @atoll(ptr nocapture noundef %29) #8
  %35 = trunc i64 %34 to i32
  %36 = call i32 @is_process_still_running(i32 noundef %33, i32 noundef %35)
  %.not14 = icmp eq i32 %36, 0
  br i1 %.not14, label %37, label %39

37:                                               ; preds = %31
  store ptr @.str.4, ptr %1, align 8, !tbaa !13
  store ptr @.str.5, ptr %8, align 8, !tbaa !13
  store ptr %18, ptr %9, align 8, !tbaa !13
  store ptr null, ptr %10, align 8, !tbaa !13
  call void @_pl_run(ptr noundef nonnull %1) #7
  %38 = add i64 %.0.ph21, 1
  br label %39

39:                                               ; preds = %37, %31
  %.1 = phi i64 [ %.0.ph21, %31 ], [ %38, %37 ]
  call void @free(ptr noundef %19) #7
  br label %.outer

.outer:                                           ; preds = %12, %39
  %.2 = phi i64 [ %.1, %39 ], [ %.0.ph21, %12 ]
  %40 = call ptr @readdir(ptr noundef %2) #7
  %.not18 = icmp eq ptr %40, null
  br i1 %.not18, label %.outer._crit_edge, label %.lr.ph, !llvm.loop !11

.outer._crit_edge:                                ; preds = %.outer, %.backedge, %6
  %.0.ph.lcssa = phi i64 [ 0, %6 ], [ %.0.ph21, %.backedge ], [ %.2, %.outer ]
  %41 = call i32 @closedir(ptr noundef %2)
  ret i64 %.0.ph.lcssa
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn
declare ptr @strtok(ptr noundef, ptr nocapture noundef readonly) local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i64 @atoll(ptr nocapture noundef nonnull) local_unnamed_addr #5

declare void @_pl_run(ptr noundef) local_unnamed_addr #1

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

attributes #0 = { 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 #1 = { "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 = { 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 #3 = { mustprogress nofree nounwind willreturn 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 #4 = { mustprogress nofree nounwind willreturn "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 mustprogress nofree nounwind willreturn memory(read) 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 = { 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 #7 = { nounwind }
attributes #8 = { 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, !8, i64 18}
!6 = !{!"dirent", !7, i64 0, !7, i64 8, !10, i64 16, !8, i64 18, !8, i64 19}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !8, i64 0}


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