#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 /*<<< orphan*/ check_message();
int /*<<< orphan*/ is_direction(short, short *);
int /*<<< orphan*/ messagef(int /*<<< orphan*/, char *);
int /*<<< orphan*/ one_move_rogue(short, int /*<<< orphan*/);
short rgetchar();
int /*<<< orphan*/ sound_bell();
void move_onto(void) {
  short ch, d;
  char first_miss = 1;
  while (!is_direction(ch = rgetchar(), &d)) {
    sound_bell();
    if (first_miss) {
      messagef(0, "direction? ");
      first_miss = 0;
    }
  }
  check_message();
  if (ch != '\033') {
    (void)one_move_rogue(ch, 0);
  }
}


x86 assembly (clang, -O0):
<move_onto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0x1,-0x5(%rbp)
mov    $0x0,%al
call   1030 <rgetchar@plt>
mov    %ax,-0x2(%rbp)
lea    -0x4(%rbp),%rsi
movswl %ax,%edi
call   1040 <is_direction@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1198 <move_onto+0x38>
jmp    11c0 <move_onto+0x60>
mov    $0x0,%al
call   1060 <sound_bell@plt>
cmpb   $0x0,-0x5(%rbp)
je     11bb <move_onto+0x5b>
xor    %edi,%edi
lea    0xe4e(%rip),%rsi
call   1050 <messagef@plt>
movb   $0x0,-0x5(%rbp)
jmp    116c <move_onto+0xc>
mov    $0x0,%al
call   1080 <check_message@plt>
movswl -0x2(%rbp),%eax
cmp    $0x1b,%eax
je     11df <move_onto+0x7f>
xor    %esi,%esi
movswl -0x2(%rbp),%edi
call   1070 <one_move_rogue@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<move_onto>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <rgetchar@plt>
mov    %eax,%ebx
movswl %ax,%edi
lea    0x6(%rsp),%rsi
call   1040 <is_direction@plt>
test   %eax,%eax
jne    11df <move_onto+0x7f>
xor    %eax,%eax
call   1060 <sound_bell@plt>
lea    0xe74(%rip),%rsi
xor    %edi,%edi
call   1050 <messagef@plt>
xor    %eax,%eax
call   1030 <rgetchar@plt>
mov    %eax,%ebx
movswl %ax,%edi
lea    0x6(%rsp),%rsi
call   1040 <is_direction@plt>
test   %eax,%eax
jne    11df <move_onto+0x7f>
lea    0x6(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <sound_bell@plt>
xor    %eax,%eax
call   1030 <rgetchar@plt>
mov    %eax,%ebx
movswl %ax,%edi
mov    %r14,%rsi
call   1040 <is_direction@plt>
test   %eax,%eax
je     11c0 <move_onto+0x60>
xor    %eax,%eax
call   1080 <check_message@plt>
cmp    $0x1b,%bx
je     11f6 <move_onto+0x96>
movswl %bx,%edi
xor    %esi,%esi
call   1070 <one_move_rogue@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"direction? \00"
define void @move_onto() {
%1 = alloca i16
%2 = alloca i16
%3 = alloca i8
store i8 1, i8* %3
br label %4
4: ; preds = %15, %0
%5 = call signext i16 (...) @rgetchar()
store i16 %5, i16* %1
%6 = call i32 @is_direction(i16 signext %5, i16* %2)
%7 = icmp ne i32 %6, 0
%8 = xor i1 %7, true
br i1 %8, label %9, label %16
9: ; preds = %4
%10 = call i32 (...) @sound_bell()
%11 = load i8, i8* %3
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @messagef(i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8 0, i8* %3
br label %15
15: ; preds = %13, %9
br label %4
16: ; preds = %4
%17 = call i32 (...) @check_message()
%18 = load i16, i16* %1
%19 = sext i16 %18 to i32
%20 = icmp ne i32 %19, 27
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i16, i16* %1
%23 = call i32 @one_move_rogue(i16 signext %22, i32 0)
br label %24
24: ; preds = %21, %16
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"direction? \00"
define void @move_onto() {
%1 = alloca i16
%2 = bitcast i16* %1 to i8*
%3 = call signext i16 (...) @rgetchar()
%4 = call i32 @is_direction(i16 signext %3, i16* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %17
6: ; preds = %0
%7 = call i32 (...) @sound_bell()
%8 = call i32 @messagef(i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = call signext i16 (...) @rgetchar()
%10 = call i32 @is_direction(i16 signext %9, i16* %1)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %6, %12
%13 = call i32 (...) @sound_bell()
%14 = call signext i16 (...) @rgetchar()
%15 = call i32 @is_direction(i16 signext %14, i16* %1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %12, label %17
17: ; preds = %12, %6, %0
%18 = phi i16 [ %3, %0 ], [ %9, %6 ], [ %14, %12 ]
%19 = call i32 (...) @check_message()
%20 = icmp eq i16 %18, 27
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = call i32 @one_move_rogue(i16 signext %18, i32 0)
br label %23
23: ; preds = %21, %17
ret void
}