; LLVM IR from nelhage/reptyr :: platform/linux (linux)

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

@.str = external hidden unnamed_addr constant [22 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [117 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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #1

; Function Attrs: noreturn
declare void @die(ptr noundef, ...) #2

; 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 @read_proc_stat(i32 noundef, ptr noundef) #3

declare void @error(ptr noundef, ...) #4

declare void @debug(ptr noundef, ...) #4

; Function Attrs: nounwind uwtable
define dso_local i32 @check_pgroup(i32 noundef %0) #3 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %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 %struct.proc_stat, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 48, ptr %10) #7
  call void (ptr, ...) @debug(ptr noundef @.str.16)
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = call i32 @getpgid(i32 noundef %14) #7
  store i32 %15, ptr %4, align 4, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %22

18:                                               ; preds = %1
  %19 = load i32, ptr %3, align 4, !tbaa !5
  call void (ptr, ...) @error(ptr noundef @.str.17, i32 noundef %19)
  %20 = call ptr @__errno_location() #8
  %21 = load i32, ptr %20, align 4, !tbaa !5
  store i32 %21, ptr %2, align 4
  store i32 1, ptr %11, align 4
  br label %86

22:                                               ; preds = %1
  %23 = call ptr @opendir(ptr noundef @.str.18)
  store ptr %23, ptr %5, align 8, !tbaa !9
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %34

25:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  %26 = call ptr @__errno_location() #8
  %27 = load i32, ptr %26, align 4, !tbaa !5
  store i32 %27, ptr %12, align 4, !tbaa !5
  %28 = load i32, ptr %12, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %25
  call void (ptr, ...) @die(ptr noundef @.str, ptr noundef @.str.1) #9
  unreachable

31:                                               ; preds = %25
  %32 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %32, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  %33 = load i32, ptr %13, align 4, !tbaa !5
  store i32 %33, ptr %2, align 4
  store i32 1, ptr %11, align 4
  br label %86

34:                                               ; preds = %22
  br label %35

35:                                               ; preds = %80, %61, %56, %46, %34
  %36 = load ptr, ptr %5, align 8, !tbaa !9
  %37 = call ptr @readdir(ptr noundef %36)
  store ptr %37, ptr %6, align 8, !tbaa !9
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %81

39:                                               ; preds = %35
  %40 = load ptr, ptr %6, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.dirent, ptr %40, i32 0, i32 4
  %42 = getelementptr inbounds [256 x i8], ptr %41, i64 0, i64 0
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = sext i8 %43 to i32
  %45 = icmp eq i32 %44, 46
  br i1 %45, label %46, label %47

46:                                               ; preds = %39
  br label %35, !llvm.loop !12

47:                                               ; preds = %39
  %48 = load ptr, ptr %6, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.dirent, ptr %48, i32 0, i32 4
  %50 = getelementptr inbounds [256 x i8], ptr %49, i64 0, i64 0
  %51 = call i64 @strtol(ptr noundef %50, ptr noundef %8, i32 noundef 10) #7
  %52 = trunc i64 %51 to i32
  store i32 %52, ptr %7, align 4, !tbaa !5
  %53 = load ptr, ptr %8, align 8, !tbaa !9
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = icmp ne i8 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %47
  br label %35, !llvm.loop !12

57:                                               ; preds = %47
  %58 = load i32, ptr %7, align 4, !tbaa !5
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = icmp eq i32 %58, %59
  br i1 %60, label %61, label %62

61:                                               ; preds = %57
  br label %35, !llvm.loop !12

62:                                               ; preds = %57
  %63 = load i32, ptr %7, align 4, !tbaa !5
  %64 = call i32 @getpgid(i32 noundef %63) #7
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = icmp eq i32 %64, %65
  br i1 %66, label %67, label %80

67:                                               ; preds = %62
  %68 = load i32, ptr %7, align 4, !tbaa !5
  %69 = call i32 @read_proc_stat(i32 noundef %68, ptr noundef %10)
  store i32 %69, ptr %9, align 4, !tbaa !5
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %74

71:                                               ; preds = %67
  %72 = getelementptr inbounds %struct.proc_stat, ptr %10, i32 0, i32 1
  %73 = getelementptr inbounds [17 x i8], ptr %72, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %73, ptr align 1 @.str.19, i64 4, i1 false)
  br label %74

74:                                               ; preds = %71, %67
  %75 = load i32, ptr %7, align 4, !tbaa !5
  %76 = getelementptr inbounds %struct.proc_stat, ptr %10, i32 0, i32 1
  %77 = getelementptr inbounds [17 x i8], ptr %76, i64 0, i64 0
  %78 = load i32, ptr %3, align 4, !tbaa !5
  %79 = load i32, ptr %3, align 4, !tbaa !5
  call void (ptr, ...) @error(ptr noundef @.str.20, i32 noundef %75, i32 noundef 16, ptr noundef %77, i32 noundef %78, i32 noundef %79)
  store i32 22, ptr %9, align 4, !tbaa !5
  br label %82

80:                                               ; preds = %62
  br label %35, !llvm.loop !12

81:                                               ; preds = %35
  br label %82

82:                                               ; preds = %81, %74
  %83 = load ptr, ptr %5, align 8, !tbaa !9
  %84 = call i32 @closedir(ptr noundef %83)
  %85 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %85, ptr %2, align 4
  store i32 1, ptr %11, align 4
  br label %86

86:                                               ; preds = %82, %31, %18
  call void @llvm.lifetime.end.p0(i64 48, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #7
  %87 = load i32, ptr %2, align 4
  ret i32 %87
}

; Function Attrs: nounwind
declare i32 @getpgid(i32 noundef) #5

declare ptr @opendir(ptr noundef) #4

declare ptr @readdir(ptr noundef) #4

; Function Attrs: nounwind
declare i64 @strtol(ptr noundef, ptr noundef, i32 noundef) #5

; 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) #6

declare i32 @closedir(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(none) "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 = { noreturn "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 = { "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 "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(none) }
attributes #9 = { noreturn }

!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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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.proc_stat = type { i32, [17 x i8], i8, i32, i32, i32, i64 }

@.str = external hidden unnamed_addr constant [22 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [117 x i8], align 1

; 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 nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #1

; Function Attrs: noreturn
declare void @die(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: nounwind uwtable
declare dso_local i32 @read_proc_stat(i32 noundef, ptr noundef) local_unnamed_addr #3

declare void @error(ptr noundef, ...) local_unnamed_addr #4

declare void @debug(ptr noundef, ...) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local i32 @check_pgroup(i32 noundef %0) local_unnamed_addr #3 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.proc_stat, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #8
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %3) #8
  tail call void (ptr, ...) @debug(ptr noundef nonnull @.str.16) #8
  %4 = tail call i32 @getpgid(i32 noundef %0) #8
  %5 = icmp slt i32 %4, 0
  br i1 %5, label %6, label %9

6:                                                ; preds = %1
  tail call void (ptr, ...) @error(ptr noundef nonnull @.str.17, i32 noundef %0) #8
  %7 = tail call ptr @__errno_location() #9
  %8 = load i32, ptr %7, align 4, !tbaa !5
  br label %40

9:                                                ; preds = %1
  %10 = tail call ptr @opendir(ptr noundef nonnull @.str.18)
  %11 = icmp eq ptr %10, null
  br i1 %11, label %13, label %.preheader

.preheader:                                       ; preds = %9
  %12 = tail call ptr @readdir(ptr noundef nonnull %10) #8
  %.not27 = icmp eq ptr %12, null
  br i1 %.not27, label %.loopexit, label %.lr.ph

13:                                               ; preds = %9
  %14 = tail call ptr @__errno_location() #9
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %40

17:                                               ; preds = %13
  tail call void (ptr, ...) @die(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1) #10
  unreachable

.lr.ph:                                           ; preds = %.preheader, %.backedge
  %18 = phi ptr [ %22, %.backedge ], [ %12, %.preheader ]
  %19 = getelementptr inbounds i8, ptr %18, i64 19
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = icmp eq i8 %20, 46
  br i1 %21, label %.backedge, label %23

.backedge:                                        ; preds = %.lr.ph, %23, %29
  %22 = tail call ptr @readdir(ptr noundef nonnull %10) #8
  %.not = icmp eq ptr %22, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !10

23:                                               ; preds = %.lr.ph
  %24 = call i64 @strtol(ptr noundef nonnull %19, ptr noundef nonnull %2, i32 noundef 10) #8
  %25 = trunc i64 %24 to i32
  %26 = load ptr, ptr %2, align 8, !tbaa !12
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %.not25 = icmp ne i8 %27, 0
  %28 = icmp eq i32 %25, %0
  %or.cond = select i1 %.not25, i1 true, i1 %28
  br i1 %or.cond, label %.backedge, label %29

29:                                               ; preds = %23
  %30 = tail call i32 @getpgid(i32 noundef %25) #8
  %31 = icmp eq i32 %30, %4
  br i1 %31, label %32, label %.backedge

32:                                               ; preds = %29
  %33 = call i32 @read_proc_stat(i32 noundef %25, ptr noundef nonnull %3)
  %.not26 = icmp eq i32 %33, 0
  br i1 %.not26, label %37, label %34

34:                                               ; preds = %32
  %35 = getelementptr inbounds i8, ptr %3, i64 4
  %36 = load i32, ptr @.str.19, align 1
  store i32 %36, ptr %35, align 4
  br label %37

37:                                               ; preds = %34, %32
  %38 = getelementptr inbounds i8, ptr %3, i64 4
  call void (ptr, ...) @error(ptr noundef nonnull @.str.20, i32 noundef %25, i32 noundef 16, ptr noundef nonnull %38, i32 noundef %0, i32 noundef %0) #8
  br label %.loopexit

.loopexit:                                        ; preds = %.backedge, %.preheader, %37
  %.019 = phi i32 [ 22, %37 ], [ 0, %.preheader ], [ 0, %.backedge ]
  %39 = call i32 @closedir(ptr noundef nonnull %10)
  br label %40

40:                                               ; preds = %13, %.loopexit, %6
  %.0 = phi i32 [ %8, %6 ], [ %.019, %.loopexit ], [ %15, %13 ]
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %3) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #8
  ret i32 %.0
}

; Function Attrs: nounwind
declare i32 @getpgid(i32 noundef) local_unnamed_addr #5

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

declare ptr @readdir(ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nofree nounwind willreturn
declare i64 @strtol(ptr noundef readonly, ptr nocapture noundef, i32 noundef) local_unnamed_addr #7

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

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


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