#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 */
scalar_t__ EAGAIN;
int EOF;
int _PollIn(int, int);
int /*<<< orphan*/ clearerr(int /*<<< orphan*/ *);
scalar_t__ errno;
scalar_t__ feof(int /*<<< orphan*/ *);
int fileno(int /*<<< orphan*/ *);
scalar_t__ fpop_fd(int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
scalar_t__ readyAlways(int);
scalar_t__ ready_cc(int /*<<< orphan*/ *);
int /*<<< orphan*/ syslog_ERROR(char *, int, ...);
scalar_t__ top_fd(int, int /*<<< orphan*/);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int _fPollIn(FILE *fp, int msec) {
  int nready, fd, ch;
  if (fp == NULL)
    return -1;
  if (feof(fp))
    return -1;
  if (0 < ready_cc(fp))
    return 1;
  if (readyAlways(fileno(fp)))
    return 1;
  fd = fileno(fp);
  nready = _PollIn(fd, msec);
  if (nready != 0 && 0 <= top_fd(fd, 0)) {
    ch = getc(fp);
    if (ch != EOF)
      ungetc(ch, fp);
    else if (errno == EAGAIN) {
      clearerr(fp);
      syslog_ERROR("## _PollIn(%d,%d) pop_fd %d\n", fd, msec, nready);
      return _fPollIn(fp, msec);
    } else if (fpop_fd(fp)) {
      syslog_ERROR("## _fPollIn(%d) fpop_fd()\n", fd);
      return _fPollIn(fp, msec);
    }
  }
  if (0 < nready)
    return 2;
  return 0;
}


x86 assembly (clang, -O0):
<_fPollIn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e6 <_fPollIn+0x26>
movl   $0xffffffff,-0x4(%rbp)
jmp    136c <_fPollIn+0x1ac>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1205 <_fPollIn+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    136c <_fPollIn+0x1ac>
mov    -0x10(%rbp),%rdi
call   1030 <ready_cc@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jge    1228 <_fPollIn+0x68>
movl   $0x1,-0x4(%rbp)
jmp    136c <_fPollIn+0x1ac>
mov    -0x10(%rbp),%rdi
call   1090 <fileno@plt>
mov    %eax,%edi
call   1040 <readyAlways@plt>
cmp    $0x0,%rax
je     124e <_fPollIn+0x8e>
movl   $0x1,-0x4(%rbp)
jmp    136c <_fPollIn+0x1ac>
mov    -0x10(%rbp),%rdi
call   1090 <fileno@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   10c0 <_PollIn@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     134e <_fPollIn+0x18e>
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   1060 <top_fd@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jg     134e <_fPollIn+0x18e>
mov    -0x10(%rbp),%rdi
call   10e0 <getc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2d48(%rip),%rcx
cmp    (%rcx),%eax
je     12b9 <_fPollIn+0xf9>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10a0 <ungetc@plt>
jmp    1349 <_fPollIn+0x189>
mov    0x2d18(%rip),%rax
mov    (%rax),%rax
mov    0x2cfe(%rip),%rcx
cmp    (%rcx),%rax
jne    1307 <_fPollIn+0x147>
mov    -0x10(%rbp),%rdi
call   1080 <clearerr@plt>
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xd14(%rip),%rdi
mov    $0x0,%al
call   10b0 <syslog_ERROR@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10d0 <_fPollIn@plt>
mov    %eax,-0x4(%rbp)
jmp    136c <_fPollIn+0x1ac>
mov    -0x10(%rbp),%rdi
call   1050 <fpop_fd@plt>
cmp    $0x0,%rax
je     133f <_fPollIn+0x17f>
mov    -0x1c(%rbp),%esi
lea    0xcf9(%rip),%rdi
mov    $0x0,%al
call   10b0 <syslog_ERROR@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10d0 <_fPollIn@plt>
mov    %eax,-0x4(%rbp)
jmp    136c <_fPollIn+0x1ac>
jmp    1344 <_fPollIn+0x184>
jmp    1349 <_fPollIn+0x189>
jmp    134e <_fPollIn+0x18e>
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
jge    1365 <_fPollIn+0x1a5>
movl   $0x2,-0x4(%rbp)
jmp    136c <_fPollIn+0x1ac>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_fPollIn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11d0 <_fPollIn+0x20>
mov    %esi,%r12d
mov    %rdi,%r13
call   1070 <feof@plt>
test   %rax,%rax
je     11e6 <_fPollIn+0x36>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dfb(%rip),%r15
mov    0x2dd4(%rip),%r14
jmp    122a <_fPollIn+0x7a>
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1080 <clearerr@plt>
lea    0xdf1(%rip),%rdi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   10b0 <syslog_ERROR@plt>
mov    %r13,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    11d0 <_fPollIn+0x20>
mov    %r13,%rdi
call   1030 <ready_cc@plt>
mov    $0x1,%ebx
test   %rax,%rax
jg     11d5 <_fPollIn+0x25>
mov    %r13,%rdi
call   1090 <fileno@plt>
mov    %eax,%edi
call   1040 <readyAlways@plt>
test   %rax,%rax
jne    11d5 <_fPollIn+0x25>
mov    %r13,%rdi
call   1090 <fileno@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r12d,%esi
call   10c0 <_PollIn@plt>
test   %eax,%eax
je     12ba <_fPollIn+0x10a>
mov    %eax,%ebp
mov    %ebx,%edi
xor    %esi,%esi
call   1060 <top_fd@plt>
test   %rax,%rax
js     12cb <_fPollIn+0x11b>
mov    %r13,%rdi
call   10d0 <getc@plt>
cmp    (%r15),%eax
jne    12c1 <_fPollIn+0x111>
mov    0x2d4c(%rip),%rax
mov    (%rax),%rax
cmp    (%r14),%rax
je     1200 <_fPollIn+0x50>
mov    %r13,%rdi
call   1050 <fpop_fd@plt>
test   %rax,%rax
je     12cb <_fPollIn+0x11b>
lea    0xd71(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   10b0 <syslog_ERROR@plt>
jmp    121d <_fPollIn+0x6d>
xor    %ebx,%ebx
jmp    11d5 <_fPollIn+0x25>
mov    %eax,%edi
mov    %r13,%rsi
call   10a0 <ungetc@plt>
xor    %ebx,%ebx
test   %ebp,%ebp
setg   %bl
add    %ebx,%ebx
jmp    11d5 <_fPollIn+0x25>

LLVM IR (-O0):
@EOF = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@.str = [29 x i8] c"## _PollIn(%d,%d) pop_fd %d\0A\00"
@.str.1 = [27 x i8] c"## _fPollIn(%d) fpop_fd()\0A\00"
define i32 @_fPollIn(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%9 = load i32*, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %82
12: ; preds = %2
%13 = load i32*, i32** %4
%14 = call i64 @feof(i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 -1, i32* %3
br label %82
17: ; preds = %12
%18 = load i32*, i32** %4
%19 = call i64 @ready_cc(i32* %18)
%20 = icmp slt i64 0, %19
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 1, i32* %3
br label %82
22: ; preds = %17
%23 = load i32*, i32** %4
%24 = call i32 @fileno(i32* %23)
%25 = call i64 @readyAlways(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 1, i32* %3
br label %82
28: ; preds = %22
%29 = load i32*, i32** %4
%30 = call i32 @fileno(i32* %29)
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = load i32, i32* %5
%33 = call i32 @_PollIn(i32 %31, i32 %32)
store i32 %33, i32* %6
%34 = load i32, i32* %6
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %77
36: ; preds = %28
%37 = load i32, i32* %7
%38 = call i64 @top_fd(i32 %37, i32 0)
%39 = icmp sle i64 0, %38
br i1 %39, label %40, label %77
40: ; preds = %36
%41 = load i32*, i32** %4
%42 = call i32 @getc(i32* %41)
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = load i32, i32* @EOF
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %50
46: ; preds = %40
%47 = load i32, i32* %8
%48 = load i32*, i32** %4
%49 = call i32 @ungetc(i32 %47, i32* %48)
br label %76
50: ; preds = %40
%51 = load i64, i64* @errno
%52 = load i64, i64* @EAGAIN
%53 = icmp eq i64 %51, %52
br i1 %53, label %54, label %64
54: ; preds = %50
%55 = load i32*, i32** %4
%56 = call i32 @clearerr(i32* %55)
%57 = load i32, i32* %7
%58 = load i32, i32* %5
%59 = load i32, i32* %6
%60 = call i32 (i8*, i32, ...) @syslog_ERROR(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %57, i32 %58, i32 %59)
%61 = load i32*, i32** %4
%62 = load i32, i32* %5
%63 = call i32 @_fPollIn(i32* %61, i32 %62)
store i32 %63, i32* %3
br label %82
64: ; preds = %50
%65 = load i32*, i32** %4
%66 = call i64 @fpop_fd(i32* %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %74
68: ; preds = %64
%69 = load i32, i32* %7
%70 = call i32 (i8*, i32, ...) @syslog_ERROR(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %69)
%71 = load i32*, i32** %4
%72 = load i32, i32* %5
%73 = call i32 @_fPollIn(i32* %71, i32 %72)
store i32 %73, i32* %3
br label %82
74: ; preds = %64
br label %75
75: ; preds = %74
br label %76
76: ; preds = %75, %46
br label %77
77: ; preds = %76, %36, %28
%78 = load i32, i32* %6
%79 = icmp slt i32 0, %78
br i1 %79, label %80, label %81
80: ; preds = %77
store i32 2, i32* %3
br label %82
81: ; preds = %77
store i32 0, i32* %3
br label %82
82: ; preds = %81, %80, %68, %54, %27, %21, %16, %11
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
@EOF = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@.str = [29 x i8] c"## _PollIn(%d,%d) pop_fd %d\0A\00"
@.str.1 = [27 x i8] c"## _fPollIn(%d) fpop_fd()\0A\00"
define i32 @_fPollIn(i32* %0, i32 %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %45, label %4
4: ; preds = %2
%5 = tail call i64 @feof(i32* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %45
7: ; preds = %4, %34
%8 = tail call i64 @ready_cc(i32* %0)
%9 = icmp sgt i64 %8, 0
br i1 %9, label %45, label %10
10: ; preds = %7
%11 = tail call i32 @fileno(i32* %0)
%12 = tail call i64 @readyAlways(i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %45
14: ; preds = %10
%15 = tail call i32 @fileno(i32* %0)
%16 = tail call i32 @_PollIn(i32 %15, i32 %1)
%17 = icmp eq i32 %16, 0
br i1 %17, label %45, label %18
18: ; preds = %14
%19 = tail call i64 @top_fd(i32 %15, i32 0)
%20 = icmp sgt i64 %19, -1
br i1 %20, label %21, label %42
21: ; preds = %18
%22 = tail call i32 @getc(i32* %0)
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = tail call i32 @ungetc(i32 %22, i32* %0)
br label %42
27: ; preds = %21
%28 = load i64, i64* @errno
%29 = load i64, i64* @EAGAIN
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %37
31: ; preds = %27
%32 = tail call i32 @clearerr(i32* %0)
%33 = tail call i32 (i8*, i32, ...) @syslog_ERROR(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %1, i32 %16)
br label %34
34: ; preds = %31, %40
%35 = tail call i64 @feof(i32* %0)
%36 = icmp eq i64 %35, 0
br i1 %36, label %7, label %45
37: ; preds = %27
%38 = tail call i64 @fpop_fd(i32* %0)
%39 = icmp eq i64 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %37
%41 = tail call i32 (i8*, i32, ...) @syslog_ERROR(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %34
42: ; preds = %37, %18, %25
%43 = icmp sgt i32 %16, 0
%44 = select i1 %43, i32 2, i32 0
br label %45
45: ; preds = %10, %7, %34, %14, %4, %42, %2
%46 = phi i32 [ -1, %2 ], [ %44, %42 ], [ -1, %4 ], [ 0, %14 ], [ -1, %34 ], [ 1, %7 ], [ 1, %10 ]
ret i32 %46
}