#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 getchar();
int /*<<< orphan*/ system(char *);
char llegeixMando() {
  char c;
  system("/bin/stty raw");
  c = getchar();
  if (c == 27) {
    c = getchar();
    c = getchar();
  }
  system("/bin/stty cooked");
  if (c == 'A')
    c = 'A';
  else if (c == 'B')
    c = 'B';
  else if (c == 'C')
    c = 'C';
  else if (c == 'D')
    c = 'D';
  return c;
}


x86 assembly (clang, -O0):
<llegeixMando>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
call   1030 <system@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x1b,%eax
jne    115f <llegeixMando+0x3f>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x1(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x1(%rbp)
lea    0xea8(%rip),%rdi
call   1030 <system@plt>
movsbl -0x1(%rbp),%eax
cmp    $0x41,%eax
jne    1181 <llegeixMando+0x61>
movb   $0x41,-0x1(%rbp)
jmp    11cd <llegeixMando+0xad>
movsbl -0x1(%rbp),%eax
cmp    $0x42,%eax
jne    1197 <llegeixMando+0x77>
movb   $0x42,-0x1(%rbp)
jmp    11c8 <llegeixMando+0xa8>
movsbl -0x1(%rbp),%eax
cmp    $0x43,%eax
jne    11ad <llegeixMando+0x8d>
movb   $0x43,-0x1(%rbp)
jmp    11c3 <llegeixMando+0xa3>
movsbl -0x1(%rbp),%eax
cmp    $0x44,%eax
jne    11be <llegeixMando+0x9e>
movb   $0x44,-0x1(%rbp)
jmp    11c3 <llegeixMando+0xa3>
jmp    11c8 <llegeixMando+0xa8>
jmp    11cd <llegeixMando+0xad>
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<llegeixMando>:
push   %rbx
lea    0xed8(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
cmp    $0x1b,%al
jne    114a <llegeixMando+0x2a>
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
lea    0xebd(%rip),%rdi
call   1030 <system@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/bin/stty raw\00"
@.str.1 = [17 x i8] c"/bin/stty cooked\00"
define signext i8 @llegeixMando() {
%1 = alloca i8
%2 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%3 = call signext i8 (...) @getchar()
store i8 %3, i8* %1
%4 = load i8, i8* %1
%5 = sext i8 %4 to i32
%6 = icmp eq i32 %5, 27
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call signext i8 (...) @getchar()
store i8 %8, i8* %1
%9 = call signext i8 (...) @getchar()
store i8 %9, i8* %1
br label %10
10: ; preds = %7, %0
%11 = call i32 @system(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%12 = load i8, i8* %1
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 65
br i1 %14, label %15, label %16
15: ; preds = %10
store i8 65, i8* %1
br label %34
16: ; preds = %10
%17 = load i8, i8* %1
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 66
br i1 %19, label %20, label %21
20: ; preds = %16
store i8 66, i8* %1
br label %33
21: ; preds = %16
%22 = load i8, i8* %1
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 67
br i1 %24, label %25, label %26
25: ; preds = %21
store i8 67, i8* %1
br label %32
26: ; preds = %21
%27 = load i8, i8* %1
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 68
br i1 %29, label %30, label %31
30: ; preds = %26
store i8 68, i8* %1
br label %31
31: ; preds = %30, %26
br label %32
32: ; preds = %31, %25
br label %33
33: ; preds = %32, %20
br label %34
34: ; preds = %33, %15
%35 = load i8, i8* %1
ret i8 %35
}

LLVM IR (-O2):
@.str = [14 x i8] c"/bin/stty raw\00"
@.str.1 = [17 x i8] c"/bin/stty cooked\00"
define signext i8 @llegeixMando() {
%1 = tail call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%2 = tail call signext i8 (...) @getchar()
%3 = icmp eq i8 %2, 27
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call signext i8 (...) @getchar()
%6 = tail call signext i8 (...) @getchar()
br label %7
7: ; preds = %4, %0
%8 = phi i8 [ %6, %4 ], [ %2, %0 ]
%9 = tail call i32 @system(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
ret i8 %8
}