; 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.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.steal_pty_state = type { %struct.proc_stat, i32, i32, %struct.fd_array, [4096 x i8], %union.anon, i32, %struct.ptrace_child, i64, i32, i32 }
%struct.proc_stat = type { i32, [17 x i8], i8, i32, i32, i32, i64 }
%struct.fd_array = type { ptr, i32, i32 }
%union.anon = type { %struct.sockaddr_un }
%struct.sockaddr_un = type { i16, [108 x i8] }
%struct.ptrace_child = type { i32, i32, i32, i32, i32, i64, i64, %struct.user_regs_struct }
%struct.user_regs_struct = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }
%struct.dirent = type { i64, i64, i16, i8, [256 x i8] }
%struct.syscall_numbers = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }

@.str.27 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [40 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #2

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

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #2

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

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

declare ptr @opendir(ptr noundef) #3

declare ptr @readdir(ptr noundef) #3

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

declare i32 @fd_array_push(ptr noundef, i32 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @find_master_fd(ptr noundef %0) #5 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.stat, align 8
  %7 = alloca i32, align 4
  %8 = alloca [4096 x i8], align 16
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  call void @llvm.lifetime.start.p0(i64 144, ptr %6) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.start.p0(i64 4096, ptr %8) #7
  %11 = getelementptr inbounds [4096 x i8], ptr %8, i64 0, i64 0
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.steal_pty_state, ptr %12, i32 0, i32 7
  %14 = getelementptr inbounds %struct.ptrace_child, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !9
  %16 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %11, i64 noundef 4096, ptr noundef @.str.27, i32 noundef %15) #7
  %17 = getelementptr inbounds [4096 x i8], ptr %8, i64 0, i64 0
  %18 = call ptr @opendir(ptr noundef %17)
  store ptr %18, ptr %4, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %23

20:                                               ; preds = %1
  %21 = call ptr @__errno_location() #8
  %22 = load i32, ptr %21, align 4, !tbaa !18
  store i32 %22, ptr %2, align 4
  store i32 1, ptr %9, align 4
  br label %139

23:                                               ; preds = %1
  br label %24

24:                                               ; preds = %130, %128, %85, %61, %49, %35, %23
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = call ptr @readdir(ptr noundef %25)
  store ptr %26, ptr %5, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %131

28:                                               ; preds = %24
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.dirent, ptr %29, i32 0, i32 4
  %31 = getelementptr inbounds [256 x i8], ptr %30, i64 0, i64 0
  %32 = load i8, ptr %31, align 1, !tbaa !19
  %33 = sext i8 %32 to i32
  %34 = icmp eq i32 %33, 46
  br i1 %34, label %35, label %36

35:                                               ; preds = %28
  br label %24, !llvm.loop !20

36:                                               ; preds = %28
  %37 = getelementptr inbounds [4096 x i8], ptr %8, i64 0, i64 0
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.steal_pty_state, ptr %38, i32 0, i32 7
  %40 = getelementptr inbounds %struct.ptrace_child, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !9
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.dirent, ptr %42, i32 0, i32 4
  %44 = getelementptr inbounds [256 x i8], ptr %43, i64 0, i64 0
  %45 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %37, i64 noundef 4096, ptr noundef @.str.28, i32 noundef %41, ptr noundef %44) #7
  %46 = getelementptr inbounds [4096 x i8], ptr %8, i64 0, i64 0
  %47 = call i32 @stat(ptr noundef %46, ptr noundef %6) #7
  %48 = icmp slt i32 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %36
  br label %24, !llvm.loop !20

50:                                               ; preds = %36
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.dirent, ptr %51, i32 0, i32 4
  %53 = getelementptr inbounds [256 x i8], ptr %52, i64 0, i64 0
  %54 = getelementptr inbounds %struct.stat, ptr %6, i32 0, i32 7
  %55 = load i64, ptr %54, align 8, !tbaa !22
  %56 = trunc i64 %55 to i32
  call void (ptr, ...) @debug(ptr noundef @.str.32, ptr noundef %53, i32 noundef %56)
  %57 = getelementptr inbounds %struct.stat, ptr %6, i32 0, i32 7
  %58 = load i64, ptr %57, align 8, !tbaa !22
  %59 = call i64 @gnu_dev_makedev(i32 noundef 5, i32 noundef 2) #8
  %60 = icmp ne i64 %58, %59
  br i1 %60, label %61, label %62

61:                                               ; preds = %50
  br label %24, !llvm.loop !20

62:                                               ; preds = %50
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.dirent, ptr %63, i32 0, i32 4
  %65 = getelementptr inbounds [256 x i8], ptr %64, i64 0, i64 0
  call void (ptr, ...) @debug(ptr noundef @.str.33, ptr noundef %65)
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.steal_pty_state, ptr %66, i32 0, i32 7
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.steal_pty_state, ptr %68, i32 0, i32 7
  %70 = call ptr @ptrace_syscall_numbers(ptr noundef %69)
  %71 = getelementptr inbounds %struct.syscall_numbers, ptr %70, i32 0, i32 13
  %72 = load i64, ptr %71, align 8, !tbaa !25
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.dirent, ptr %73, i32 0, i32 4
  %75 = getelementptr inbounds [256 x i8], ptr %74, i64 0, i64 0
  %76 = call i32 @atoi(ptr noundef %75) #9
  %77 = sext i32 %76 to i64
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.steal_pty_state, ptr %78, i32 0, i32 8
  %80 = load i64, ptr %79, align 8, !tbaa !27
  %81 = call i64 @ptrace_remote_syscall(ptr noundef %67, i64 noundef %72, i64 noundef %77, i64 noundef 2147767344, i64 noundef %80, i64 noundef 0, i64 noundef 0, i64 noundef 0)
  %82 = trunc i64 %81 to i32
  store i32 %82, ptr %7, align 4, !tbaa !18
  %83 = load i32, ptr %7, align 4, !tbaa !18
  %84 = icmp slt i32 %83, 0
  br i1 %84, label %85, label %89

85:                                               ; preds = %62
  %86 = load i32, ptr %7, align 4, !tbaa !18
  %87 = sub nsw i32 0, %86
  %88 = call ptr @strerror(i32 noundef %87) #7
  call void (ptr, ...) @debug(ptr noundef @.str.34, ptr noundef %88)
  br label %24, !llvm.loop !20

89:                                               ; preds = %62
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  %90 = load ptr, ptr %3, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.steal_pty_state, ptr %90, i32 0, i32 7
  %92 = load ptr, ptr %3, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.steal_pty_state, ptr %92, i32 0, i32 8
  %94 = load i64, ptr %93, align 8, !tbaa !27
  %95 = call i32 @ptrace_memcpy_from_child(ptr noundef %91, ptr noundef %10, i64 noundef %94, i64 noundef 4)
  store i32 %95, ptr %7, align 4, !tbaa !18
  %96 = load i32, ptr %7, align 4, !tbaa !18
  %97 = icmp slt i32 %96, 0
  br i1 %97, label %98, label %104

98:                                               ; preds = %89
  %99 = load ptr, ptr %3, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.steal_pty_state, ptr %99, i32 0, i32 7
  %101 = getelementptr inbounds %struct.ptrace_child, ptr %100, i32 0, i32 4
  %102 = load i32, ptr %101, align 8, !tbaa !28
  %103 = call ptr @strerror(i32 noundef %102) #7
  call void (ptr, ...) @debug(ptr noundef @.str.35, ptr noundef %103)
  store i32 2, ptr %9, align 4
  br label %128, !llvm.loop !20

104:                                              ; preds = %89
  %105 = load i32, ptr %10, align 4, !tbaa !18
  %106 = load ptr, ptr %3, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.steal_pty_state, ptr %106, i32 0, i32 0
  %108 = getelementptr inbounds %struct.proc_stat, ptr %107, i32 0, i32 6
  %109 = load i64, ptr %108, align 8, !tbaa !29
  %110 = call i32 @gnu_dev_minor(i64 noundef %109) #8
  %111 = icmp eq i32 %105, %110
  br i1 %111, label %112, label %127

112:                                              ; preds = %104
  %113 = load ptr, ptr %5, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.dirent, ptr %113, i32 0, i32 4
  %115 = getelementptr inbounds [256 x i8], ptr %114, i64 0, i64 0
  %116 = call i32 @atoi(ptr noundef %115) #9
  call void (ptr, ...) @debug(ptr noundef @.str.36, i32 noundef %116)
  %117 = load ptr, ptr %3, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.steal_pty_state, ptr %117, i32 0, i32 3
  %119 = load ptr, ptr %5, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.dirent, ptr %119, i32 0, i32 4
  %121 = getelementptr inbounds [256 x i8], ptr %120, i64 0, i64 0
  %122 = call i32 @atoi(ptr noundef %121) #9
  %123 = call i32 @fd_array_push(ptr noundef %118, i32 noundef %122)
  %124 = icmp ne i32 %123, 0
  br i1 %124, label %125, label %126

125:                                              ; preds = %112
  call void (ptr, ...) @error(ptr noundef @.str.37)
  store i32 12, ptr %2, align 4
  store i32 1, ptr %9, align 4
  br label %128

126:                                              ; preds = %112
  br label %127

127:                                              ; preds = %126, %104
  store i32 0, ptr %9, align 4
  br label %128

128:                                              ; preds = %127, %125, %98
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  %129 = load i32, ptr %9, align 4
  switch i32 %129, label %139 [
    i32 0, label %130
    i32 2, label %24
  ]

130:                                              ; preds = %128
  br label %24, !llvm.loop !20

131:                                              ; preds = %24
  %132 = load ptr, ptr %3, align 8, !tbaa !5
  %133 = getelementptr inbounds %struct.steal_pty_state, ptr %132, i32 0, i32 3
  %134 = getelementptr inbounds %struct.fd_array, ptr %133, i32 0, i32 1
  %135 = load i32, ptr %134, align 8, !tbaa !30
  %136 = icmp eq i32 %135, 0
  br i1 %136, label %137, label %138

137:                                              ; preds = %131
  store i32 3, ptr %2, align 4
  store i32 1, ptr %9, align 4
  br label %139

138:                                              ; preds = %131
  store i32 0, ptr %2, align 4
  store i32 1, ptr %9, align 4
  br label %139

139:                                              ; preds = %138, %137, %128, %20
  call void @llvm.lifetime.end.p0(i64 4096, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 144, ptr %6) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #7
  %140 = load i32, ptr %2, align 4
  ret i32 %140
}

; Function Attrs: inlinehint nounwind willreturn memory(none) uwtable
declare i64 @gnu_dev_makedev(i32 noundef, i32 noundef) #6

declare i64 @ptrace_remote_syscall(ptr noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef) #3

declare ptr @ptrace_syscall_numbers(ptr noundef) #3

declare i32 @ptrace_memcpy_from_child(ptr noundef, ptr noundef, i64 noundef, i64 noundef) #3

; Function Attrs: inlinehint nounwind willreturn memory(none) uwtable
declare i32 @gnu_dev_minor(i64 noundef) #6

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 = { 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 = { 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 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 = { inlinehint nounwind willreturn memory(none) 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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(none) }
attributes #9 = { 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 = !{!10, !12, i64 4288}
!10 = !{!"steal_pty_state", !11, i64 0, !12, i64 48, !12, i64 52, !14, i64 56, !7, i64 72, !7, i64 4168, !12, i64 4280, !15, i64 4288, !13, i64 4544, !12, i64 4552, !12, i64 4556}
!11 = !{!"proc_stat", !12, i64 0, !7, i64 4, !7, i64 21, !12, i64 24, !12, i64 28, !12, i64 32, !13, i64 40}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"fd_array", !6, i64 0, !12, i64 8, !12, i64 12}
!15 = !{!"ptrace_child", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !13, i64 24, !13, i64 32, !16, i64 40}
!16 = !{!"user_regs_struct", !17, i64 0, !17, i64 8, !17, i64 16, !17, i64 24, !17, i64 32, !17, i64 40, !17, i64 48, !17, i64 56, !17, i64 64, !17, i64 72, !17, i64 80, !17, i64 88, !17, i64 96, !17, i64 104, !17, i64 112, !17, i64 120, !17, i64 128, !17, i64 136, !17, i64 144, !17, i64 152, !17, i64 160, !17, i64 168, !17, i64 176, !17, i64 184, !17, i64 192, !17, i64 200, !17, i64 208}
!17 = !{!"long long", !7, i64 0}
!18 = !{!12, !12, i64 0}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!23, !13, i64 40}
!23 = !{!"stat", !13, i64 0, !13, i64 8, !13, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !24, i64 72, !24, i64 88, !24, i64 104, !7, i64 120}
!24 = !{!"timespec", !13, i64 0, !13, i64 8}
!25 = !{!26, !13, i64 104}
!26 = !{!"syscall_numbers", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !13, i64 72, !13, i64 80, !13, i64 88, !13, i64 96, !13, i64 104, !13, i64 112, !13, i64 120, !13, i64 128, !13, i64 136, !13, i64 144, !13, i64 152}
!27 = !{!10, !13, i64 4544}
!28 = !{!10, !12, i64 4304}
!29 = !{!10, !13, i64 40}
!30 = !{!10, !12, i64 64}


; 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.27 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [40 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: 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 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

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

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

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

; 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: nofree nounwind
declare noundef i32 @stat(ptr nocapture noundef readonly, ptr nocapture noundef) local_unnamed_addr #2

declare i32 @fd_array_push(ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local i32 @find_master_fd(ptr noundef %0) local_unnamed_addr #6 {
  %2 = alloca %struct.stat, align 8
  %3 = alloca [4096 x i8], align 16
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %2) #8
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %3) #8
  %5 = getelementptr inbounds i8, ptr %0, i64 4288
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %3, i64 noundef 4096, ptr noundef nonnull @.str.27, i32 noundef %6) #8
  %8 = call ptr @opendir(ptr noundef nonnull %3)
  %9 = icmp eq ptr %8, null
  br i1 %9, label %16, label %.preheader

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

.lr.ph:                                           ; preds = %.preheader
  %11 = getelementptr inbounds i8, ptr %2, i64 40
  %12 = getelementptr inbounds i8, ptr %0, i64 4544
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  %14 = getelementptr inbounds i8, ptr %0, i64 56
  %15 = getelementptr inbounds i8, ptr %0, i64 4304
  br label %19

16:                                               ; preds = %1
  %17 = tail call ptr @__errno_location() #9
  %18 = load i32, ptr %17, align 4, !tbaa !17
  br label %67

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

24:                                               ; preds = %19
  %25 = load i32, ptr %5, align 8, !tbaa !5
  %26 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %3, i64 noundef 4096, ptr noundef nonnull @.str.28, i32 noundef %25, ptr noundef nonnull %21) #8
  %27 = call i32 @stat(ptr noundef nonnull %3, ptr noundef nonnull %2) #8
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %.backedge, label %29

29:                                               ; preds = %24
  %30 = load i64, ptr %11, align 8, !tbaa !19
  %31 = trunc i64 %30 to i32
  call void (ptr, ...) @debug(ptr noundef nonnull @.str.32, ptr noundef nonnull %21, i32 noundef %31) #8
  %32 = call i64 @gnu_dev_makedev(i32 noundef 5, i32 noundef 2) #9
  %.not26 = icmp eq i64 %30, %32
  br i1 %.not26, label %33, label %.backedge

33:                                               ; preds = %29
  call void (ptr, ...) @debug(ptr noundef nonnull @.str.33, ptr noundef nonnull %21) #8
  %34 = call ptr @ptrace_syscall_numbers(ptr noundef nonnull %5) #8
  %35 = getelementptr inbounds i8, ptr %34, i64 104
  %36 = load i64, ptr %35, align 8, !tbaa !22
  %37 = call i32 @atoi(ptr nocapture noundef %21) #10
  %38 = sext i32 %37 to i64
  %39 = load i64, ptr %12, align 8, !tbaa !24
  %40 = call i64 @ptrace_remote_syscall(ptr noundef nonnull %5, i64 noundef %36, i64 noundef %38, i64 noundef 2147767344, i64 noundef %39, i64 noundef 0, i64 noundef 0, i64 noundef 0) #8
  %41 = trunc i64 %40 to i32
  %42 = icmp slt i32 %41, 0
  br i1 %42, label %43, label %47

43:                                               ; preds = %33
  %44 = sub nsw i32 0, %41
  %45 = call ptr @strerror(i32 noundef %44) #8
  call void (ptr, ...) @debug(ptr noundef nonnull @.str.34, ptr noundef %45) #8
  br label %.backedge

.backedge:                                        ; preds = %43, %19, %24, %29, %63
  %46 = call ptr @readdir(ptr noundef nonnull %8) #8
  %.not = icmp eq ptr %46, null
  br i1 %.not, label %._crit_edge, label %19, !llvm.loop !25

47:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #8
  %48 = load i64, ptr %12, align 8, !tbaa !24
  %49 = call i32 @ptrace_memcpy_from_child(ptr noundef nonnull %5, ptr noundef nonnull %4, i64 noundef %48, i64 noundef 4) #8
  %50 = icmp slt i32 %49, 0
  br i1 %50, label %51, label %54

51:                                               ; preds = %47
  %52 = load i32, ptr %15, align 8, !tbaa !27
  %53 = call ptr @strerror(i32 noundef %52) #8
  call void (ptr, ...) @debug(ptr noundef nonnull @.str.35, ptr noundef %53) #8
  br label %63, !llvm.loop !25

54:                                               ; preds = %47
  %55 = load i32, ptr %4, align 4, !tbaa !17
  %56 = load i64, ptr %13, align 8, !tbaa !28
  %57 = call i32 @gnu_dev_minor(i64 noundef %56) #9
  %58 = icmp eq i32 %55, %57
  br i1 %58, label %59, label %63

59:                                               ; preds = %54
  %60 = call i32 @atoi(ptr nocapture noundef %21) #10
  call void (ptr, ...) @debug(ptr noundef nonnull @.str.36, i32 noundef %60) #8
  %61 = call i32 @atoi(ptr nocapture noundef %21) #10
  %62 = call i32 @fd_array_push(ptr noundef nonnull %14, i32 noundef %61) #8
  %.not27 = icmp eq i32 %62, 0
  br i1 %.not27, label %63, label %.thread

.thread:                                          ; preds = %59
  call void (ptr, ...) @error(ptr noundef nonnull @.str.37) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #8
  br label %67

63:                                               ; preds = %54, %59, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #8
  br label %.backedge

._crit_edge:                                      ; preds = %.backedge, %.preheader
  %64 = getelementptr inbounds i8, ptr %0, i64 64
  %65 = load i32, ptr %64, align 8, !tbaa !29
  %66 = icmp eq i32 %65, 0
  %. = select i1 %66, i32 3, i32 0
  br label %67

67:                                               ; preds = %.thread, %._crit_edge, %16
  %.2 = phi i32 [ %18, %16 ], [ %., %._crit_edge ], [ 12, %.thread ]
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %3) #8
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %2) #8
  ret i32 %.2
}

; Function Attrs: inlinehint mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare i64 @gnu_dev_makedev(i32 noundef, i32 noundef) local_unnamed_addr #7

declare i64 @ptrace_remote_syscall(ptr noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #3

declare ptr @ptrace_syscall_numbers(ptr noundef) local_unnamed_addr #3

declare i32 @ptrace_memcpy_from_child(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare i32 @gnu_dev_minor(i64 noundef) local_unnamed_addr #7

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 = { 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 = { 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 = { 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 = { 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 #7 = { inlinehint mustprogress nofree nosync nounwind willreturn memory(none) 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 #8 = { nounwind }
attributes #9 = { nounwind willreturn memory(none) }
attributes #10 = { 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 4288}
!6 = !{!"steal_pty_state", !7, i64 0, !8, i64 48, !8, i64 52, !12, i64 56, !9, i64 72, !9, i64 4168, !8, i64 4280, !14, i64 4288, !11, i64 4544, !8, i64 4552, !8, i64 4556}
!7 = !{!"proc_stat", !8, i64 0, !9, i64 4, !9, i64 21, !8, i64 24, !8, i64 28, !8, i64 32, !11, i64 40}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"fd_array", !13, i64 0, !8, i64 8, !8, i64 12}
!13 = !{!"any pointer", !9, i64 0}
!14 = !{!"ptrace_child", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !8, i64 16, !11, i64 24, !11, i64 32, !15, i64 40}
!15 = !{!"user_regs_struct", !16, i64 0, !16, i64 8, !16, i64 16, !16, i64 24, !16, i64 32, !16, i64 40, !16, i64 48, !16, i64 56, !16, i64 64, !16, i64 72, !16, i64 80, !16, i64 88, !16, i64 96, !16, i64 104, !16, i64 112, !16, i64 120, !16, i64 128, !16, i64 136, !16, i64 144, !16, i64 152, !16, i64 160, !16, i64 168, !16, i64 176, !16, i64 184, !16, i64 192, !16, i64 200, !16, i64 208}
!16 = !{!"long long", !9, i64 0}
!17 = !{!8, !8, i64 0}
!18 = !{!9, !9, i64 0}
!19 = !{!20, !11, i64 40}
!20 = !{!"stat", !11, i64 0, !11, i64 8, !11, i64 16, !8, i64 24, !8, i64 28, !8, i64 32, !8, i64 36, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !21, i64 72, !21, i64 88, !21, i64 104, !9, i64 120}
!21 = !{!"timespec", !11, i64 0, !11, i64 8}
!22 = !{!23, !11, i64 104}
!23 = !{!"syscall_numbers", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !11, i64 112, !11, i64 120, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152}
!24 = !{!6, !11, i64 4544}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = !{!6, !8, i64 4304}
!28 = !{!6, !11, i64 40}
!29 = !{!6, !8, i64 64}


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