#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*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ strcmp(char *, char *);
int getDirection(void) {
  char command[10];
  int direction;
  int commandDone = -1;
  while (commandDone == -1) {
    scanf("%9s", command);
    printf("\n");
    if (strcmp(command, "down") == 0) {
      direction = 1;
      commandDone = 1;
    } else if (strcmp(command, "up") == 0) {
      direction = 0;
      commandDone = 1;
    } else if (strcmp(command, "right") == 0) {
      direction = 2;
      commandDone = 1;
    } else if (strcmp(command, "left") == 0) {
      direction = 3;
      commandDone = 1;
    } else if (strcmp(command, "cancel") == 0) {
      direction = -1;
      commandDone = 1;
    } else {
      printf("Enter a valid direction or cancel.\n");
    }
  }
  return direction;
}


x86 assembly (clang, -O0):
<getDirection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xffffffff,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    126b <getDirection+0x13b>
lea    -0xa(%rbp),%rsi
lea    0xeac(%rip),%rdi
call   1050 <scanf@plt>
lea    0xee0(%rip),%rdi
call   1030 <printf@plt>
lea    -0xa(%rbp),%rdi
lea    0xe94(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1192 <getDirection+0x62>
movl   $0x1,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    1266 <getDirection+0x136>
lea    -0xa(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11bf <getDirection+0x8f>
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    1261 <getDirection+0x131>
lea    -0xa(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ec <getDirection+0xbc>
movl   $0x2,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    125c <getDirection+0x12c>
lea    -0xa(%rbp),%rdi
lea    0xe1b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1219 <getDirection+0xe9>
movl   $0x3,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    1257 <getDirection+0x127>
lea    -0xa(%rbp),%rdi
lea    0xdf3(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1246 <getDirection+0x116>
movl   $0xffffffff,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    1252 <getDirection+0x122>
lea    0xdd1(%rip),%rdi
call   1030 <printf@plt>
jmp    1257 <getDirection+0x127>
jmp    125c <getDirection+0x12c>
jmp    1261 <getDirection+0x131>
jmp    1266 <getDirection+0x136>
jmp    113f <getDirection+0xf>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDirection>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeab(%rip),%rdi
lea    0xe(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe91(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
mov    $0x1,%ecx
test   %rax,%rax
je     1253 <getDirection+0x113>
lea    0xe79(%rip),%rbx
lea    0xe(%rsp),%rbp
lea    0xe70(%rip),%r15
lea    0xe6f(%rip),%r12
lea    0xe6d(%rip),%r13
lea    0xe53(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     123c <getDirection+0xfc>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1240 <getDirection+0x100>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1247 <getDirection+0x107>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     124e <getDirection+0x10e>
lea    0xe17(%rip),%rdi
call   1040 <puts@plt>
lea    0xded(%rip),%rdi
mov    %rbp,%rsi
call   1060 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11c0 <getDirection+0x80>
mov    $0x1,%ecx
jmp    1253 <getDirection+0x113>
xor    %ecx,%ecx
jmp    1253 <getDirection+0x113>
mov    $0x2,%ecx
jmp    1253 <getDirection+0x113>
mov    $0x3,%ecx
jmp    1253 <getDirection+0x113>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%9s\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [5 x i8] c"down\00"
@.str.3 = [3 x i8] c"up\00"
@.str.4 = [6 x i8] c"right\00"
@.str.5 = [5 x i8] c"left\00"
@.str.6 = [7 x i8] c"cancel\00"
@.str.7 = [36 x i8] c"Enter a valid direction or cancel.\0A\00"
define i32 @getDirection() {
%1 = alloca [10 x i8]
%2 = alloca i32
%3 = alloca i32
store i32 -1, i32* %3
br label %4
4: ; preds = %41, %0
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %42
7: ; preds = %4
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%9 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %7
store i32 1, i32* %2
store i32 1, i32* %3
br label %41
15: ; preds = %7
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 0, i32* %2
store i32 1, i32* %3
br label %40
20: ; preds = %15
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 2, i32* %2
store i32 1, i32* %3
br label %39
25: ; preds = %20
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 3, i32* %2
store i32 1, i32* %3
br label %38
30: ; preds = %25
%31 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 -1, i32* %2
store i32 1, i32* %3
br label %37
35: ; preds = %30
%36 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0))
br label %37
37: ; preds = %35, %34
br label %38
38: ; preds = %37, %29
br label %39
39: ; preds = %38, %24
br label %40
40: ; preds = %39, %19
br label %41
41: ; preds = %40, %14
br label %4
42: ; preds = %4
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
@.str = [4 x i8] c"%9s\00"
@.str.2 = [5 x i8] c"down\00"
@.str.3 = [3 x i8] c"up\00"
@.str.4 = [6 x i8] c"right\00"
@.str.5 = [5 x i8] c"left\00"
@.str.6 = [7 x i8] c"cancel\00"
@str = [35 x i8] c"Enter a valid direction or cancel.\00"
define i32 @getDirection() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = call i32 @putchar(i32 10)
%5 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %25, label %7
7: ; preds = %0, %19
%8 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %25, label %10
10: ; preds = %7
%11 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %25, label %13
13: ; preds = %10
%14 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %13
%17 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %16
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
%22 = call i32 @putchar(i32 10)
%23 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %7
25: ; preds = %16, %13, %10, %7, %19, %0
%26 = phi i32 [ 1, %0 ], [ -1, %16 ], [ 3, %13 ], [ 2, %10 ], [ 0, %7 ], [ 1, %19 ]
ret i32 %26
}