#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ _use_keypad;
};
typedef TYPE_1__ WINDOW;

/* Variables and functions */
int PDC_validchar(int c) {
  extern WINDOW *_getch_win_;
  int ch = c;
  if (_getch_win_ == (WINDOW *)NULL)
    ch = (-1);
  else if ((unsigned int)c < 256)
    ch = c;
  else if (!(_getch_win_->_use_keypad))
    ch = (-1);
  return (ch);
}


x86 assembly (clang, -O0):
<PDC_validchar>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2ecc(%rip),%rax
cmpq   $0x0,(%rax)
jne    112a <PDC_validchar+0x2a>
movl   $0xffffffff,-0x8(%rbp)
jmp    1166 <PDC_validchar+0x66>
cmpl   $0x100,-0x4(%rbp)
jae    1142 <PDC_validchar+0x42>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1161 <PDC_validchar+0x61>
mov    0x2e97(%rip),%rax
mov    (%rax),%rax
cmpl   $0x0,(%rax)
jne    115c <PDC_validchar+0x5c>
movl   $0xffffffff,-0x8(%rbp)
jmp    1161 <PDC_validchar+0x61>
jmp    1166 <PDC_validchar+0x66>
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<PDC_validchar>:
mov    0x2ed9(%rip),%rcx
mov    (%rcx),%rcx
test   %rcx,%rcx
je     1121 <PDC_validchar+0x21>
mov    %edi,%eax
cmp    $0x100,%edi
jb     1120 <PDC_validchar+0x20>
cmpl   $0x1,(%rcx)
sbb    %ecx,%ecx
or     %ecx,%eax
ret
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
%struct.TYPE_2__ = type { i32 }
@_getch_win_ = external global %struct.TYPE_2__*
define i32 @PDC_validchar(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
store i32 %4, i32* %3
%5 = load %struct.TYPE_2__*, %struct.TYPE_2__** @_getch_win_
%6 = icmp eq %struct.TYPE_2__* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 -1, i32* %3
br label %21
8: ; preds = %1
%9 = load i32, i32* %2
%10 = icmp ult i32 %9, 256
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = load i32, i32* %2
store i32 %12, i32* %3
br label %20
13: ; preds = %8
%14 = load %struct.TYPE_2__*, %struct.TYPE_2__** @_getch_win_
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %13
store i32 -1, i32* %3
br label %19
19: ; preds = %18, %13
br label %20
20: ; preds = %19, %11
br label %21
21: ; preds = %20, %7
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
%struct.TYPE_2__ = type { i32 }
@_getch_win_ = external global %struct.TYPE_2__*
define i32 @PDC_validchar(i32 %0) {
%2 = load %struct.TYPE_2__*, %struct.TYPE_2__** @_getch_win_
%3 = icmp eq %struct.TYPE_2__* %2, null
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = icmp ult i32 %0, 256
br i1 %5, label %11, label %6
6: ; preds = %4
%7 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i32 -1, i32 %0
br label %11
11: ; preds = %6, %4, %1
%12 = phi i32 [ -1, %1 ], [ %0, %4 ], [ %10, %6 ]
ret i32 %12
}