#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *, int *, int *, int *, int *,
           char *);
int test_procstat(void) {
  int euid, pid, ppid, pgrp, session, got;
  char state;
  char command[128];
  FILE *pstat = fopen("/dev/procstat", "r");
  assert(pstat != NULL);
  for (;;) {
    if ((got = fscanf(pstat, "%d\t%d\t%d\t%d\t%d\t%c\t", &euid, &pid, &ppid,
                      &pgrp, &session, &state)) == -1)
      break;
    if (got < 6)
      return 1;
    if ((fgets(command, 128, pstat)) == NULL)
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_procstat>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
lea    0xeae(%rip),%rdi
lea    0xeb5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0xa8(%rbp),%rdi
lea    0xe88(%rip),%rsi
lea    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rcx
lea    -0x10(%rbp),%r8
lea    -0x14(%rbp),%r9
lea    -0x18(%rbp),%r10
lea    -0x1d(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <fscanf@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    11bf <test_procstat+0x7f>
jmp    1208 <test_procstat+0xc8>
cmpl   $0x6,-0x1c(%rbp)
jge    11d5 <test_procstat+0x95>
movl   $0x1,-0x4(%rbp)
jmp    120f <test_procstat+0xcf>
lea    -0xa0(%rbp),%rdi
mov    -0xa8(%rbp),%rdx
mov    $0x80,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    1203 <test_procstat+0xc3>
movl   $0x1,-0x4(%rbp)
jmp    120f <test_procstat+0xcf>
jmp    117a <test_procstat+0x3a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_procstat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
lea    0xea8(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
lea    0x18(%rsp),%r12
lea    0x14(%rsp),%r13
lea    0x10(%rsp),%rbp
lea    0x20(%rsp),%r14
mov    $0x1,%r15d
nop
mov    %rbx,%rdi
lea    0xe76(%rip),%rsi
lea    0x1c(%rsp),%rdx
mov    %r12,%rcx
mov    %r13,%r8
mov    %rbp,%r9
lea    0xb(%rsp),%rax
push   %rax
lea    0x14(%rsp),%rax
push   %rax
call   1030 <fscanf@plt>
add    $0x10,%rsp
cmp    $0xffffffff,%eax
je     11de <test_procstat+0x9e>
cmp    $0x6,%eax
jl     11e1 <test_procstat+0xa1>
mov    %r14,%rdi
mov    $0x80,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1190 <test_procstat+0x50>
jmp    11e1 <test_procstat+0xa1>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/dev/procstat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"%d\09%d\09%d\09%d\09%d\09%c\09\00"
define i32 @test_procstat() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca [128 x i8]
%10 = alloca i32*
%11 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %10
%12 = load i32*, i32** %10
%13 = icmp ne i32* %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
br label %16
16: ; preds = %31, %0
%17 = load i32*, i32** %10
%18 = call i32 @fscanf(i32* %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i8* %8)
store i32 %18, i32* %7
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %16
br label %32
21: ; preds = %16
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 6
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 1, i32* %1
br label %33
25: ; preds = %21
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%27 = load i32*, i32** %10
%28 = call i32* @fgets(i8* %26, i32 128, i32* %27)
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %31
30: ; preds = %25
store i32 1, i32* %1
br label %33
31: ; preds = %25
br label %16
32: ; preds = %20
store i32 0, i32* %1
br label %33
33: ; preds = %32, %30, %24
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str = [14 x i8] c"/dev/procstat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"%d\09%d\09%d\09%d\09%d\09%c\09\00"
define i32 @test_procstat() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca [128 x i8]
%8 = bitcast i32* %1 to i8*
%9 = bitcast i32* %2 to i8*
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = bitcast i32* %5 to i8*
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp ne i32* %14, null
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
br label %18
18: ; preds = %23, %0
%19 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i8* %6)
%20 = icmp eq i32 %19, -1
br i1 %20, label %26, label %21
21: ; preds = %18
%22 = icmp slt i32 %19, 6
br i1 %22, label %26, label %23
23: ; preds = %21
%24 = call i32* @fgets(i8* %13, i32 128, i32* %14)
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %18
26: ; preds = %18, %23, %21
%27 = phi i32 [ 1, %21 ], [ 1, %23 ], [ 0, %18 ]
ret i32 %27
}