#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int proc_read_text(int, char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *strstr(char *, char *);
int proc_check_stopped(int pid) {
  char buf[4096];
  int len;
  len = proc_read_text(pid, "stat", buf, sizeof(buf));
  if (len == -1) {
    fprintf(stderr, "Can't get %d stat\n", pid);
    return -1;
  }
  if (strstr(buf, "(test_freezer) T ") == NULL) {
    fprintf(stderr, "Process %d in the unexpected state: %s\n", pid, buf);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<proc_check_stopped>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x1010(%rbp),%rdx
lea    0xeb1(%rip),%rsi
mov    $0x1000,%ecx
call   1040 <proc_read_text@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0xffffffff,-0x1014(%rbp)
jne    1192 <proc_check_stopped+0x62>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e3 <proc_check_stopped+0xb3>
lea    -0x1010(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
jne    11dc <proc_check_stopped+0xac>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    -0x1010(%rbp),%rcx
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e3 <proc_check_stopped+0xb3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proc_check_stopped>:
push   %rbx
sub    $0x1000,%rsp
mov    %edi,%ebx
lea    0xebf(%rip),%rsi
mov    %rsp,%rdx
mov    $0x1000,%ecx
call   1040 <proc_read_text@plt>
cmp    $0xffffffff,%eax
je     118a <proc_check_stopped+0x5a>
lea    0xebe(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    11a8 <proc_check_stopped+0x78>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
mov    %rsp,%rcx
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11a3 <proc_check_stopped+0x73>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x1000,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"stat\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Can't get %d stat\0A\00"
@.str.2 = [18 x i8] c"(test_freezer) T \00"
@.str.3 = [40 x i8] c"Process %d in the unexpected state: %s\0A\00"
define i32 @proc_check_stopped(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [4096 x i8]
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%8 = call i32 @proc_read_text(i32 %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %7, i32 4096)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i32, i32* %3
%14 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i32 -1, i32* %2
br label %25
15: ; preds = %1
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%17 = call i32* @strstr(i8* %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = load i32, i32* %3
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%23 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %21, i8* %22)
store i32 -1, i32* %2
br label %25
24: ; preds = %15
store i32 0, i32* %2
br label %25
25: ; preds = %24, %19, %11
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [5 x i8] c"stat\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Can't get %d stat\0A\00"
@.str.2 = [18 x i8] c"(test_freezer) T \00"
@.str.3 = [40 x i8] c"Process %d in the unexpected state: %s\0A\00"
define i32 @proc_check_stopped(i32 %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = call i32 @proc_read_text(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %3, i32 4096)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %15
9: ; preds = %1
%10 = call i32* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %0, i8* %3)
br label %15
15: ; preds = %9, %12, %6
%16 = phi i32 [ -1, %6 ], [ -1, %12 ], [ 0, %9 ]
ret i32 %16
}