; 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.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.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.10 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [36 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 @debug(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @find_terminal_emulator(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %struct.proc_stat, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.steal_pty_state, ptr %7, i32 0, i32 0
  %9 = getelementptr inbounds %struct.proc_stat, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.steal_pty_state, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds %struct.proc_stat, ptr %12, i32 0, i32 4
  %14 = load i32, ptr %13, align 4, !tbaa !18
  call void (ptr, ...) @debug(ptr noundef @.str.10, i32 noundef %10, i32 noundef %14)
  call void @llvm.lifetime.start.p0(i64 48, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.steal_pty_state, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds %struct.proc_stat, ptr %16, i32 0, i32 4
  %18 = load i32, ptr %17, align 4, !tbaa !18
  %19 = call i32 @read_proc_stat(i32 noundef %18, ptr noundef %4)
  store i32 %19, ptr %5, align 4, !tbaa !19
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %1
  %22 = load i32, ptr %5, align 4, !tbaa !19
  store i32 %22, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %30

23:                                               ; preds = %1
  %24 = getelementptr inbounds %struct.proc_stat, ptr %4, i32 0, i32 3
  %25 = load i32, ptr %24, align 8, !tbaa !20
  call void (ptr, ...) @debug(ptr noundef @.str.11, i32 noundef %25)
  %26 = getelementptr inbounds %struct.proc_stat, ptr %4, i32 0, i32 3
  %27 = load i32, ptr %26, align 8, !tbaa !20
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.steal_pty_state, ptr %28, i32 0, i32 1
  store i32 %27, ptr %29, align 8, !tbaa !21
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %30

30:                                               ; preds = %23, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 48, ptr %4) #3
  %31 = load i32, ptr %2, align 4
  ret i32 %31
}

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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 0}
!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 = !{!10, !12, i64 28}
!19 = !{!12, !12, i64 0}
!20 = !{!11, !12, i64 24}
!21 = !{!10, !12, 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"

%struct.proc_stat = type { i32, [17 x i8], i8, i32, i32, i32, i64 }

@.str.10 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [36 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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @find_terminal_emulator(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = alloca %struct.proc_stat, align 8
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 28
  %5 = load i32, ptr %4, align 4, !tbaa !17
  tail call void (ptr, ...) @debug(ptr noundef nonnull @.str.10, i32 noundef %3, i32 noundef %5) #3
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %2) #3
  %6 = load i32, ptr %4, align 4, !tbaa !17
  %7 = call i32 @read_proc_stat(i32 noundef %6, ptr noundef nonnull %2)
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %13

8:                                                ; preds = %1
  %9 = getelementptr inbounds i8, ptr %2, i64 24
  %10 = load i32, ptr %9, align 8, !tbaa !18
  call void (ptr, ...) @debug(ptr noundef nonnull @.str.11, i32 noundef %10) #3
  %11 = load i32, ptr %9, align 8, !tbaa !18
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %11, ptr %12, align 8, !tbaa !19
  br label %13

13:                                               ; preds = %1, %8
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %2) #3
  ret i32 %7
}

attributes #0 = { mustprogress 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 = { 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, !8, i64 0}
!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 28}
!18 = !{!7, !8, i64 24}
!19 = !{!6, !8, i64 48}


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