; LLVM IR from nelhage/reptyr :: attach (steal_child_pty)

; 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.anon = type { %struct.msghdr, [24 x i8] }
%struct.msghdr = type { ptr, i32, ptr, i64, ptr, i64, i32 }
%struct.cmsghdr = type { i64, i32, i32, [0 x i8] }
%struct.steal_pty_state = type { %struct.proc_stat, i32, i32, %struct.fd_array, [4096 x i8], %union.anon.0, 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.0 = 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.syscall_numbers = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }

@.str.26 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [15 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

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

declare ptr @ptrace_syscall_numbers(ptr noundef) #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare i32 @ptrace_memcpy_to_child(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #1

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

; Function Attrs: nounwind
declare i64 @sysconf(i32 noundef) #4

declare i64 @ptrace_socketcall(ptr noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @steal_child_pty(ptr noundef %0) #5 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %struct.anon, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 80, ptr %4) #7
  call void @llvm.memset.p0.i64(ptr align 8 %4, i8 0, i64 80, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  %10 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 1
  %11 = getelementptr inbounds [24 x i8], ptr %10, i64 0, i64 0
  %12 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 0
  %13 = getelementptr inbounds %struct.msghdr, ptr %12, i32 0, i32 4
  store ptr %11, ptr %13, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 0
  %15 = getelementptr inbounds %struct.msghdr, ptr %14, i32 0, i32 5
  store i64 24, ptr %15, align 8, !tbaa !14
  %16 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 0
  %17 = getelementptr inbounds %struct.msghdr, ptr %16, i32 0, i32 5
  %18 = load i64, ptr %17, align 8, !tbaa !14
  %19 = icmp uge i64 %18, 16
  br i1 %19, label %20, label %24

20:                                               ; preds = %1
  %21 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 0
  %22 = getelementptr inbounds %struct.msghdr, ptr %21, i32 0, i32 4
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  br label %25

24:                                               ; preds = %1
  br label %25

25:                                               ; preds = %24, %20
  %26 = phi ptr [ %23, %20 ], [ null, %24 ]
  store ptr %26, ptr %5, align 8, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.cmsghdr, ptr %27, i32 0, i32 1
  store i32 1, ptr %28, align 8, !tbaa !15
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.cmsghdr, ptr %29, i32 0, i32 2
  store i32 1, ptr %30, align 4, !tbaa !15
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.cmsghdr, ptr %31, i32 0, i32 0
  store i64 20, ptr %32, align 8, !tbaa !16
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.cmsghdr, ptr %33, i32 0, i32 3
  %35 = getelementptr inbounds [0 x i8], ptr %34, i64 0, i64 0
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.steal_pty_state, ptr %36, i32 0, i32 3
  %38 = getelementptr inbounds %struct.fd_array, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !17
  %40 = getelementptr inbounds i32, ptr %39, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %35, ptr align 4 %40, i64 4, i1 false)
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.cmsghdr, ptr %41, i32 0, i32 0
  %43 = load i64, ptr %42, align 8, !tbaa !16
  %44 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 0
  %45 = getelementptr inbounds %struct.msghdr, ptr %44, i32 0, i32 5
  store i64 %43, ptr %45, align 8, !tbaa !14
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.steal_pty_state, ptr %46, i32 0, i32 8
  %48 = load i64, ptr %47, align 8, !tbaa !24
  %49 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 0
  %50 = getelementptr inbounds %struct.msghdr, ptr %49, i32 0, i32 4
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  %52 = ptrtoint ptr %51 to i64
  %53 = ptrtoint ptr %4 to i64
  %54 = sub i64 %52, %53
  %55 = add i64 %48, %54
  %56 = inttoptr i64 %55 to ptr
  %57 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 0
  %58 = getelementptr inbounds %struct.msghdr, ptr %57, i32 0, i32 4
  store ptr %56, ptr %58, align 8, !tbaa !9
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.steal_pty_state, ptr %59, i32 0, i32 7
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.steal_pty_state, ptr %61, i32 0, i32 8
  %63 = load i64, ptr %62, align 8, !tbaa !24
  %64 = call i32 @ptrace_memcpy_to_child(ptr noundef %60, i64 noundef %63, ptr noundef %4, i64 noundef 80)
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %71

66:                                               ; preds = %25
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.steal_pty_state, ptr %67, i32 0, i32 7
  %69 = getelementptr inbounds %struct.ptrace_child, ptr %68, i32 0, i32 4
  %70 = load i32, ptr %69, align 8, !tbaa !25
  store i32 %70, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %174

71:                                               ; preds = %25
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.steal_pty_state, ptr %72, i32 0, i32 7
  %74 = getelementptr inbounds %struct.ptrace_child, ptr %73, i32 0, i32 4
  store i32 0, ptr %74, align 8, !tbaa !25
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.steal_pty_state, ptr %75, i32 0, i32 7
  %77 = call ptr @ptrace_syscall_numbers(ptr noundef %76)
  %78 = getelementptr inbounds %struct.syscall_numbers, ptr %77, i32 0, i32 18
  %79 = load i64, ptr %78, align 8, !tbaa !26
  %80 = icmp ne i64 %79, 0
  br i1 %80, label %81, label %98

81:                                               ; preds = %71
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.steal_pty_state, ptr %82, i32 0, i32 7
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.steal_pty_state, ptr %84, i32 0, i32 7
  %86 = call ptr @ptrace_syscall_numbers(ptr noundef %85)
  %87 = getelementptr inbounds %struct.syscall_numbers, ptr %86, i32 0, i32 18
  %88 = load i64, ptr %87, align 8, !tbaa !26
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.steal_pty_state, ptr %89, i32 0, i32 9
  %91 = load i32, ptr %90, align 8, !tbaa !28
  %92 = sext i32 %91 to i64
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.steal_pty_state, ptr %93, i32 0, i32 8
  %95 = load i64, ptr %94, align 8, !tbaa !24
  %96 = call i64 @ptrace_remote_syscall(ptr noundef %83, i64 noundef %88, i64 noundef %92, i64 noundef %95, i64 noundef 64, i64 noundef 0, i64 noundef 0, i64 noundef 0)
  %97 = trunc i64 %96 to i32
  store i32 %97, ptr %8, align 4, !tbaa !15
  br label %116

98:                                               ; preds = %71
  %99 = load ptr, ptr %3, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.steal_pty_state, ptr %99, i32 0, i32 7
  %101 = load ptr, ptr %3, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.steal_pty_state, ptr %101, i32 0, i32 8
  %103 = load i64, ptr %102, align 8, !tbaa !24
  %104 = call i64 @sysconf(i32 noundef 30) #7
  %105 = sdiv i64 %104, 2
  %106 = add i64 %103, %105
  %107 = load ptr, ptr %3, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.steal_pty_state, ptr %107, i32 0, i32 9
  %109 = load i32, ptr %108, align 8, !tbaa !28
  %110 = sext i32 %109 to i64
  %111 = load ptr, ptr %3, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.steal_pty_state, ptr %111, i32 0, i32 8
  %113 = load i64, ptr %112, align 8, !tbaa !24
  %114 = call i64 @ptrace_socketcall(ptr noundef %100, i64 noundef %106, i64 noundef 16, i64 noundef %110, i64 noundef %113, i64 noundef 64, i64 noundef 0, i64 noundef 0)
  %115 = trunc i64 %114 to i32
  store i32 %115, ptr %8, align 4, !tbaa !15
  br label %116

116:                                              ; preds = %98, %81
  %117 = load i32, ptr %8, align 4, !tbaa !15
  store i32 %117, ptr %9, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  %118 = load i32, ptr %9, align 4, !tbaa !15
  store i32 %118, ptr %6, align 4, !tbaa !15
  %119 = load i32, ptr %6, align 4, !tbaa !15
  %120 = icmp slt i32 %119, 0
  br i1 %120, label %121, label %137

121:                                              ; preds = %116
  %122 = load ptr, ptr %3, align 8, !tbaa !5
  %123 = getelementptr inbounds %struct.steal_pty_state, ptr %122, i32 0, i32 7
  %124 = getelementptr inbounds %struct.ptrace_child, ptr %123, i32 0, i32 4
  %125 = load i32, ptr %124, align 8, !tbaa !25
  %126 = icmp ne i32 %125, 0
  br i1 %126, label %127, label %132

127:                                              ; preds = %121
  %128 = load ptr, ptr %3, align 8, !tbaa !5
  %129 = getelementptr inbounds %struct.steal_pty_state, ptr %128, i32 0, i32 7
  %130 = getelementptr inbounds %struct.ptrace_child, ptr %129, i32 0, i32 4
  %131 = load i32, ptr %130, align 8, !tbaa !25
  br label %135

132:                                              ; preds = %121
  %133 = load i32, ptr %6, align 4, !tbaa !15
  %134 = sub nsw i32 0, %133
  br label %135

135:                                              ; preds = %132, %127
  %136 = phi i32 [ %131, %127 ], [ %134, %132 ]
  store i32 %136, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %174

137:                                              ; preds = %116
  call void (ptr, ...) @debug(ptr noundef @.str.26)
  %138 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 1
  %139 = getelementptr inbounds [24 x i8], ptr %138, i64 0, i64 0
  %140 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 0
  %141 = getelementptr inbounds %struct.msghdr, ptr %140, i32 0, i32 4
  store ptr %139, ptr %141, align 8, !tbaa !9
  %142 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 0
  %143 = getelementptr inbounds %struct.msghdr, ptr %142, i32 0, i32 5
  store i64 24, ptr %143, align 8, !tbaa !14
  %144 = load ptr, ptr %3, align 8, !tbaa !5
  %145 = getelementptr inbounds %struct.steal_pty_state, ptr %144, i32 0, i32 6
  %146 = load i32, ptr %145, align 8, !tbaa !29
  %147 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 0
  %148 = call i64 @recvmsg(i32 noundef %146, ptr noundef %147, i32 noundef 64)
  %149 = trunc i64 %148 to i32
  store i32 %149, ptr %6, align 4, !tbaa !15
  %150 = load i32, ptr %6, align 4, !tbaa !15
  %151 = icmp slt i32 %150, 0
  br i1 %151, label %152, label %155

152:                                              ; preds = %137
  call void (ptr, ...) @error(ptr noundef @.str.27)
  %153 = call ptr @__errno_location() #8
  %154 = load i32, ptr %153, align 4, !tbaa !15
  store i32 %154, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %174

155:                                              ; preds = %137
  %156 = load i32, ptr %6, align 4, !tbaa !15
  %157 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 0
  %158 = getelementptr inbounds %struct.msghdr, ptr %157, i32 0, i32 5
  %159 = load i64, ptr %158, align 8, !tbaa !14
  call void (ptr, ...) @debug(ptr noundef @.str.28, i32 noundef %156, i64 noundef %159)
  %160 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 0
  %161 = getelementptr inbounds %struct.msghdr, ptr %160, i32 0, i32 5
  %162 = load i64, ptr %161, align 8, !tbaa !14
  %163 = icmp ult i64 %162, 20
  br i1 %163, label %164, label %165

164:                                              ; preds = %155
  call void (ptr, ...) @error(ptr noundef @.str.29)
  store i32 22, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %174

165:                                              ; preds = %155
  %166 = load ptr, ptr %3, align 8, !tbaa !5
  %167 = getelementptr inbounds %struct.steal_pty_state, ptr %166, i32 0, i32 10
  %168 = load ptr, ptr %5, align 8, !tbaa !5
  %169 = getelementptr inbounds %struct.cmsghdr, ptr %168, i32 0, i32 3
  %170 = getelementptr inbounds [0 x i8], ptr %169, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %167, ptr align 8 %170, i64 4, i1 false)
  %171 = load ptr, ptr %3, align 8, !tbaa !5
  %172 = getelementptr inbounds %struct.steal_pty_state, ptr %171, i32 0, i32 10
  %173 = load i32, ptr %172, align 4, !tbaa !30
  call void (ptr, ...) @debug(ptr noundef @.str.30, i32 noundef %173)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %174

174:                                              ; preds = %165, %164, %152, %135, %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 80, ptr %4) #7
  %175 = load i32, ptr %2, align 4
  ret i32 %175
}

; 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 i64 @recvmsg(i32 noundef, ptr noundef, i32 noundef) #1

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(none) }

!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, !6, i64 32}
!10 = !{!"", !11, i64 0, !7, i64 56}
!11 = !{!"msghdr", !6, i64 0, !12, i64 8, !6, i64 16, !13, i64 24, !6, i64 32, !13, i64 40, !12, i64 48}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !13, i64 40}
!15 = !{!12, !12, i64 0}
!16 = !{!13, !13, i64 0}
!17 = !{!18, !6, i64 56}
!18 = !{!"steal_pty_state", !19, i64 0, !12, i64 48, !12, i64 52, !20, i64 56, !7, i64 72, !7, i64 4168, !12, i64 4280, !21, i64 4288, !13, i64 4544, !12, i64 4552, !12, i64 4556}
!19 = !{!"proc_stat", !12, i64 0, !7, i64 4, !7, i64 21, !12, i64 24, !12, i64 28, !12, i64 32, !13, i64 40}
!20 = !{!"fd_array", !6, i64 0, !12, i64 8, !12, i64 12}
!21 = !{!"ptrace_child", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !13, i64 24, !13, i64 32, !22, i64 40}
!22 = !{!"user_regs_struct", !23, i64 0, !23, i64 8, !23, i64 16, !23, i64 24, !23, i64 32, !23, i64 40, !23, i64 48, !23, i64 56, !23, i64 64, !23, i64 72, !23, i64 80, !23, i64 88, !23, i64 96, !23, i64 104, !23, i64 112, !23, i64 120, !23, i64 128, !23, i64 136, !23, i64 144, !23, i64 152, !23, i64 160, !23, i64 168, !23, i64 176, !23, i64 184, !23, i64 192, !23, i64 200, !23, i64 208}
!23 = !{!"long long", !7, i64 0}
!24 = !{!18, !13, i64 4544}
!25 = !{!18, !12, i64 4304}
!26 = !{!27, !13, i64 144}
!27 = !{!"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}
!28 = !{!18, !12, i64 4552}
!29 = !{!18, !12, i64 4280}
!30 = !{!18, !12, i64 4556}


; 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.anon = type { %struct.msghdr, [24 x i8] }
%struct.msghdr = type { ptr, i32, ptr, i64, ptr, i64, i32 }

@.str.26 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [15 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

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

declare ptr @ptrace_syscall_numbers(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare i32 @ptrace_memcpy_to_child(ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #3

; Function Attrs: nounwind
declare i64 @sysconf(i32 noundef) local_unnamed_addr #4

declare i64 @ptrace_socketcall(ptr noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @steal_child_pty(ptr noundef %0) local_unnamed_addr #5 {
  %2 = alloca %struct.anon, align 8
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %2) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(80) %2, i8 0, i64 80, i1 false)
  %3 = getelementptr inbounds i8, ptr %2, i64 56
  %4 = getelementptr inbounds i8, ptr %2, i64 32
  store ptr %3, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %2, i64 40
  store i64 24, ptr %5, align 8, !tbaa !13
  %6 = getelementptr inbounds i8, ptr %2, i64 64
  store i32 1, ptr %6, align 8, !tbaa !14
  %7 = getelementptr inbounds i8, ptr %2, i64 68
  store i32 1, ptr %7, align 4, !tbaa !14
  store i64 20, ptr %3, align 8, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %2, i64 72
  %9 = getelementptr inbounds i8, ptr %0, i64 56
  %10 = load ptr, ptr %9, align 8, !tbaa !16
  %11 = load i32, ptr %10, align 4
  store i32 %11, ptr %8, align 8
  store i64 20, ptr %5, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %0, i64 4544
  %13 = load i64, ptr %12, align 8, !tbaa !23
  %14 = add i64 %13, 56
  %15 = inttoptr i64 %14 to ptr
  store ptr %15, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %0, i64 4288
  %17 = call i32 @ptrace_memcpy_to_child(ptr noundef nonnull %16, i64 noundef %13, ptr noundef nonnull %2, i64 noundef 80) #6
  %.not = icmp eq i32 %17, 0
  %18 = getelementptr inbounds i8, ptr %0, i64 4304
  br i1 %.not, label %21, label %19

19:                                               ; preds = %1
  %20 = load i32, ptr %18, align 8, !tbaa !24
  br label %67

21:                                               ; preds = %1
  store i32 0, ptr %18, align 8, !tbaa !24
  %22 = call ptr @ptrace_syscall_numbers(ptr noundef nonnull %16) #6
  %23 = getelementptr inbounds i8, ptr %22, i64 144
  %24 = load i64, ptr %23, align 8, !tbaa !25
  %.not35 = icmp eq i64 %24, 0
  br i1 %.not35, label %34, label %25

25:                                               ; preds = %21
  %26 = call ptr @ptrace_syscall_numbers(ptr noundef nonnull %16) #6
  %27 = getelementptr inbounds i8, ptr %26, i64 144
  %28 = load i64, ptr %27, align 8, !tbaa !25
  %29 = getelementptr inbounds i8, ptr %0, i64 4552
  %30 = load i32, ptr %29, align 8, !tbaa !27
  %31 = sext i32 %30 to i64
  %32 = load i64, ptr %12, align 8, !tbaa !23
  %33 = call i64 @ptrace_remote_syscall(ptr noundef nonnull %16, i64 noundef %28, i64 noundef %31, i64 noundef %32, i64 noundef 64, i64 noundef 0, i64 noundef 0, i64 noundef 0) #6
  br label %44

34:                                               ; preds = %21
  %35 = load i64, ptr %12, align 8, !tbaa !23
  %36 = call i64 @sysconf(i32 noundef 30) #6
  %37 = sdiv i64 %36, 2
  %38 = add i64 %37, %35
  %39 = getelementptr inbounds i8, ptr %0, i64 4552
  %40 = load i32, ptr %39, align 8, !tbaa !27
  %41 = sext i32 %40 to i64
  %42 = load i64, ptr %12, align 8, !tbaa !23
  %43 = call i64 @ptrace_socketcall(ptr noundef nonnull %16, i64 noundef %38, i64 noundef 16, i64 noundef %41, i64 noundef %42, i64 noundef 64, i64 noundef 0, i64 noundef 0) #6
  br label %44

44:                                               ; preds = %34, %25
  %.032.in = phi i64 [ %33, %25 ], [ %43, %34 ]
  %.032 = trunc i64 %.032.in to i32
  %45 = icmp slt i32 %.032, 0
  br i1 %45, label %46, label %50

46:                                               ; preds = %44
  %47 = load i32, ptr %18, align 8, !tbaa !24
  %.not36 = icmp eq i32 %47, 0
  %48 = sub nsw i32 0, %.032
  %49 = select i1 %.not36, i32 %48, i32 %47
  br label %67

50:                                               ; preds = %44
  call void (ptr, ...) @debug(ptr noundef nonnull @.str.26) #6
  store ptr %3, ptr %4, align 8, !tbaa !5
  store i64 24, ptr %5, align 8, !tbaa !13
  %51 = getelementptr inbounds i8, ptr %0, i64 4280
  %52 = load i32, ptr %51, align 8, !tbaa !28
  %53 = call i64 @recvmsg(i32 noundef %52, ptr noundef nonnull %2, i32 noundef 64) #6
  %54 = trunc i64 %53 to i32
  %55 = icmp slt i32 %54, 0
  br i1 %55, label %56, label %59

56:                                               ; preds = %50
  call void (ptr, ...) @error(ptr noundef nonnull @.str.27) #6
  %57 = tail call ptr @__errno_location() #7
  %58 = load i32, ptr %57, align 4, !tbaa !14
  br label %67

59:                                               ; preds = %50
  %60 = load i64, ptr %5, align 8, !tbaa !13
  call void (ptr, ...) @debug(ptr noundef nonnull @.str.28, i32 noundef %54, i64 noundef %60) #6
  %61 = load i64, ptr %5, align 8, !tbaa !13
  %62 = icmp ult i64 %61, 20
  br i1 %62, label %63, label %64

63:                                               ; preds = %59
  call void (ptr, ...) @error(ptr noundef nonnull @.str.29) #6
  br label %67

64:                                               ; preds = %59
  %65 = getelementptr inbounds i8, ptr %0, i64 4556
  %66 = load i32, ptr %8, align 8
  store i32 %66, ptr %65, align 4
  call void (ptr, ...) @debug(ptr noundef nonnull @.str.30, i32 noundef %66) #6
  br label %67

67:                                               ; preds = %64, %63, %56, %46, %19
  %.0 = phi i32 [ %20, %19 ], [ %49, %46 ], [ %58, %56 ], [ 22, %63 ], [ 0, %64 ]
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %2) #6
  ret i32 %.0
}

declare i64 @recvmsg(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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 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 }
attributes #7 = { nounwind willreturn memory(none) }

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass