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

@.str.31 = external hidden unnamed_addr constant [61 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

; Function Attrs: nounwind uwtable
declare dso_local i32 @read_proc_stat(i32 noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @read_uid(i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @find_terminal_emulator(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @get_terminal_state(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.steal_pty_state, ptr %9, i32 0, i32 0
  %11 = call i32 @read_proc_stat(i32 noundef %8, ptr noundef %10)
  store i32 %11, ptr %6, align 4, !tbaa !9
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %2
  %14 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %14, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %40

15:                                               ; preds = %2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.steal_pty_state, ptr %16, i32 0, i32 0
  %18 = getelementptr inbounds %struct.proc_stat, ptr %17, i32 0, i32 6
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = call i32 @gnu_dev_major(i64 noundef %19) #5
  %21 = icmp ne i32 %20, 136
  br i1 %21, label %22, label %23

22:                                               ; preds = %15
  call void (ptr, ...) @error(ptr noundef @.str.31)
  store i32 22, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %40

23:                                               ; preds = %15
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = call i32 @find_terminal_emulator(ptr noundef %24)
  store i32 %25, ptr %6, align 4, !tbaa !9
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %23
  %28 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %28, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %40

29:                                               ; preds = %23
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.steal_pty_state, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 8, !tbaa !19
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.steal_pty_state, ptr %33, i32 0, i32 2
  %35 = call i32 @read_uid(i32 noundef %32, ptr noundef %34)
  store i32 %35, ptr %6, align 4, !tbaa !9
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %29
  %38 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %38, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %40

39:                                               ; preds = %29
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %40

40:                                               ; preds = %39, %37, %27, %22, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %41 = load i32, ptr %3, align 4
  ret i32 %41
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { 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 #4 = { nounwind }
attributes #5 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !14, i64 40}
!12 = !{!"steal_pty_state", !13, i64 0, !10, i64 48, !10, i64 52, !15, i64 56, !7, i64 72, !7, i64 4168, !10, i64 4280, !16, i64 4288, !14, i64 4544, !10, i64 4552, !10, i64 4556}
!13 = !{!"proc_stat", !10, i64 0, !7, i64 4, !7, i64 21, !10, i64 24, !10, i64 28, !10, i64 32, !14, i64 40}
!14 = !{!"long", !7, i64 0}
!15 = !{!"fd_array", !6, i64 0, !10, i64 8, !10, i64 12}
!16 = !{!"ptrace_child", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !14, i64 24, !14, i64 32, !17, i64 40}
!17 = !{!"user_regs_struct", !18, i64 0, !18, i64 8, !18, i64 16, !18, i64 24, !18, i64 32, !18, i64 40, !18, i64 48, !18, i64 56, !18, i64 64, !18, i64 72, !18, i64 80, !18, i64 88, !18, i64 96, !18, i64 104, !18, i64 112, !18, i64 120, !18, i64 128, !18, i64 136, !18, i64 144, !18, i64 152, !18, i64 160, !18, i64 168, !18, i64 176, !18, i64 184, !18, i64 192, !18, i64 200, !18, i64 208}
!18 = !{!"long long", !7, i64 0}
!19 = !{!12, !10, i64 48}


; 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.31 = external hidden unnamed_addr constant [61 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @read_proc_stat(i32 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @read_uid(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @find_terminal_emulator(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @get_terminal_state(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @read_proc_stat(i32 noundef %1, ptr noundef %0)
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %16

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = tail call i32 @gnu_dev_major(i64 noundef %6) #3
  %.not12 = icmp eq i32 %7, 136
  br i1 %.not12, label %9, label %8

8:                                                ; preds = %4
  tail call void (ptr, ...) @error(ptr noundef nonnull @.str.31) #4
  br label %16

9:                                                ; preds = %4
  %10 = tail call i32 @find_terminal_emulator(ptr noundef nonnull %0)
  %.not13 = icmp eq i32 %10, 0
  br i1 %.not13, label %11, label %16

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  %13 = load i32, ptr %12, align 8, !tbaa !17
  %14 = getelementptr inbounds i8, ptr %0, i64 52
  %15 = tail call i32 @read_uid(i32 noundef %13, ptr noundef nonnull %14)
  br label %16

16:                                               ; preds = %11, %9, %2, %8
  %.0 = phi i32 [ 22, %8 ], [ %3, %2 ], [ %10, %9 ], [ %15, %11 ]
  ret i32 %.0
}

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

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "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 = { 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 #3 = { nounwind willreturn memory(none) }
attributes #4 = { 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, !11, i64 40}
!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 = !{!6, !8, i64 48}


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