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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NDELAY;
int /*<<< orphan*/ assert(int);
int fcntl(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int getchar();
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/);
unsigned Sys_HasChar() {
  int ret, flags, rflags;
  flags = fcntl(fileno(stdin), F_GETFL, 0);
  assert(flags != -1);
  rflags = fcntl(fileno(stdin), F_SETFL, flags | O_NDELAY);
  assert(rflags != -1);
  ret = getchar();
  ungetc(ret, stdin);
  rflags = fcntl(fileno(stdin), F_SETFL, flags);
  assert(rflags != -1);
  return ret != EOF;
}


x86 assembly (clang, -O0):
<Sys_HasChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    0x2e19(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
call   1070 <ungetc@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x4(%rbp),%eax
mov    0x2dbc(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Sys_HasChar>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e8a(%rip),%r14
mov    (%r14),%edi
call   1060 <fileno@plt>
mov    0x2e53(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1050 <assert@plt>
mov    (%r14),%edi
call   1060 <fileno@plt>
mov    0x2e39(%rip),%r15
mov    (%r15),%esi
mov    0x2e27(%rip),%rcx
mov    (%rcx),%edx
or     %ebx,%edx
mov    %eax,%edi
call   1030 <fcntl@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1050 <assert@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebp
mov    (%r14),%esi
mov    %eax,%edi
call   1070 <ungetc@plt>
mov    (%r14),%edi
call   1060 <fileno@plt>
mov    (%r15),%esi
mov    %eax,%edi
mov    %ebx,%edx
call   1030 <fcntl@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1050 <assert@plt>
mov    0x2dea(%rip),%rcx
xor    %eax,%eax
cmp    (%rcx),%ebp
setne  %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NDELAY = global i32 0
@EOF = global i32 0
define i32 @Sys_HasChar() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = load i32, i32* @stdin
%5 = call i32 @fileno(i32 %4)
%6 = load i32, i32* @F_GETFL
%7 = call i32 @fcntl(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, -1
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i32, i32* @stdin
%13 = call i32 @fileno(i32 %12)
%14 = load i32, i32* @F_SETFL
%15 = load i32, i32* %2
%16 = load i32, i32* @O_NDELAY
%17 = or i32 %15, %16
%18 = call i32 @fcntl(i32 %13, i32 %14, i32 %17)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = icmp ne i32 %19, -1
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = call i32 (...) @getchar()
store i32 %23, i32* %1
%24 = load i32, i32* %1
%25 = load i32, i32* @stdin
%26 = call i32 @ungetc(i32 %24, i32 %25)
%27 = load i32, i32* @stdin
%28 = call i32 @fileno(i32 %27)
%29 = load i32, i32* @F_SETFL
%30 = load i32, i32* %2
%31 = call i32 @fcntl(i32 %28, i32 %29, i32 %30)
store i32 %31, i32* %3
%32 = load i32, i32* %3
%33 = icmp ne i32 %32, -1
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i32, i32* %1
%37 = load i32, i32* @EOF
%38 = icmp ne i32 %36, %37
%39 = zext i1 %38 to i32
ret i32 %39
}

LLVM IR (-O2):
@stdin = global i32 0
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NDELAY = global i32 0
@EOF = global i32 0
define i32 @Sys_HasChar() {
%1 = load i32, i32* @stdin
%2 = tail call i32 @fileno(i32 %1)
%3 = load i32, i32* @F_GETFL
%4 = tail call i32 @fcntl(i32 %2, i32 %3, i32 0)
%5 = icmp ne i32 %4, -1
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = load i32, i32* @stdin
%9 = tail call i32 @fileno(i32 %8)
%10 = load i32, i32* @F_SETFL
%11 = load i32, i32* @O_NDELAY
%12 = or i32 %11, %4
%13 = tail call i32 @fcntl(i32 %9, i32 %10, i32 %12)
%14 = icmp ne i32 %13, -1
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = tail call i32 (...) @getchar()
%18 = load i32, i32* @stdin
%19 = tail call i32 @ungetc(i32 %17, i32 %18)
%20 = load i32, i32* @stdin
%21 = tail call i32 @fileno(i32 %20)
%22 = load i32, i32* @F_SETFL
%23 = tail call i32 @fcntl(i32 %21, i32 %22, i32 %4)
%24 = icmp ne i32 %23, -1
%25 = zext i1 %24 to i32
%26 = tail call i32 @assert(i32 %25)
%27 = load i32, i32* @EOF
%28 = icmp ne i32 %17, %27
%29 = zext i1 %28 to i32
ret i32 %29
}