#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 */
char KB_101;
char KB_84;
int /*<<< orphan*/ KDGKBTYPE;
scalar_t__ ioctl(int const, int /*<<< orphan*/, char *);
int is_a_console(const int fd) {
  char arg;
  arg = 0;
  return (ioctl(fd, KDGKBTYPE, &arg) == 0 &&
          ((arg == KB_101) || (arg == KB_84)));
}


x86 assembly (clang, -O0):
<is_a_console>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ec7(%rip),%rax
mov    (%rax),%esi
lea    -0x5(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x6(%rbp)
jne    117d <is_a_console+0x6d>
movsbl -0x5(%rbp),%ecx
mov    0x2e77(%rip),%rax
movsbl (%rax),%edx
mov    $0x1,%al
cmp    %edx,%ecx
mov    %al,-0x7(%rbp)
je     1177 <is_a_console+0x67>
movsbl -0x5(%rbp),%eax
mov    0x2e6c(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
sete   %al
mov    %al,-0x7(%rbp)
mov    -0x7(%rbp),%al
mov    %al,-0x6(%rbp)
mov    -0x6(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_a_console>:
push   %rax
movb   $0x0,0x7(%rsp)
mov    0x2ed3(%rip),%rax
mov    (%rax),%esi
lea    0x7(%rsp),%rdx
call   1030 <ioctl@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     1135 <is_a_console+0x25>
pop    %rcx
ret
mov    0x7(%rsp),%al
mov    0x2e88(%rip),%rcx
cmp    (%rcx),%al
sete   %cl
mov    0x2e8c(%rip),%rdx
cmp    (%rdx),%al
sete   %al
or     %cl,%al
movzbl %al,%eax
pop    %rcx
ret

LLVM IR (-O0):
@KDGKBTYPE = global i32 0
@KB_101 = global i8 0
@KB_84 = global i8 0
define i32 @is_a_console(i32 %0) {
%2 = alloca i32
%3 = alloca i8
store i32 %0, i32* %2
store i8 0, i8* %3
%4 = load i32, i32* %2
%5 = load i32, i32* @KDGKBTYPE
%6 = call i64 @ioctl(i32 %4, i32 %5, i8* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %22
8: ; preds = %1
%9 = load i8, i8* %3
%10 = sext i8 %9 to i32
%11 = load i8, i8* @KB_101
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %10, %12
br i1 %13, label %20, label %14
14: ; preds = %8
%15 = load i8, i8* %3
%16 = sext i8 %15 to i32
%17 = load i8, i8* @KB_84
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %16, %18
br label %20
20: ; preds = %14, %8
%21 = phi i1 [ true, %8 ], [ %19, %14 ]
br label %22
22: ; preds = %20, %1
%23 = phi i1 [ false, %1 ], [ %21, %20 ]
%24 = zext i1 %23 to i32
ret i32 %24
}

LLVM IR (-O2):
@KDGKBTYPE = global i32 0
@KB_101 = global i8 0
@KB_84 = global i8 0
define i32 @is_a_console(i32 %0) {
%2 = alloca i8
store i8 0, i8* %2
%3 = load i32, i32* @KDGKBTYPE
%4 = call i64 @ioctl(i32 %0, i32 %3, i8* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = load i8, i8* %2
%8 = load i8, i8* @KB_101
%9 = icmp eq i8 %7, %8
%10 = load i8, i8* @KB_84
%11 = icmp eq i8 %7, %10
%12 = select i1 %9, i1 true, i1 %11
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %6, %1
%15 = phi i32 [ 0, %1 ], [ %13, %6 ]
ret i32 %15
}