#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*/ avanzar_n_pasos(char);
char get_posicion();
int /*<<< orphan*/ ir_hasta_pos(char);
int /*<<< orphan*/ modem_enviar_sms(char *);
int /*<<< orphan*/ modem_init();
char *modem_leer_sms();
int /*<<< orphan*/ motor_init();
int /*<<< orphan*/ retroceder_n_pasos(char);
int main(void) {
  motor_init();
  modem_init();
  char rcvChar = 0, pos;
  char *comandoRecibido;
  char posicion[3];
  char tipoComando;
  char d, u;
  while (1) {
    comandoRecibido = "";
    comandoRecibido = modem_leer_sms();
    tipoComando = comandoRecibido[0];
    switch (tipoComando) {
    case 'H':
      d = (comandoRecibido[1] - 48) * 10;
      u = comandoRecibido[2] - 48;
      ir_hasta_pos(d + u);
      break;
    case 'F':
      d = (comandoRecibido[1] - 48) * 10;
      u = comandoRecibido[2] - 48;
      avanzar_n_pasos(d + u);
      break;
    case 'B':
      d = (comandoRecibido[1] - 48) * 10;
      u = comandoRecibido[2] - 48;
      retroceder_n_pasos(d + u);
      break;
    case 'G':
      pos = get_posicion();
      if (pos < 10) {
        posicion[0] = 58;
        posicion[1] = pos + 48;
        posicion[2] = 0;
      } else {
        d = pos / 10;
        u = pos % 10;
        posicion[0] = 58;
        posicion[1] = d + 48;
        posicion[2] = u + 48;
        posicion[3] = 0;
      }
      modem_enviar_sms(posicion);
      break;
    case 'R':
      motor_init();
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <motor_init@plt>
mov    $0x0,%al
call   10a0 <modem_init@plt>
movb   $0x0,-0x5(%rbp)
lea    0xe9c(%rip),%rax
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
call   1050 <modem_leer_sms@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x14(%rbp)
movsbl -0x14(%rbp),%eax
add    $0xffffffbe,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x10,%eax
ja     130b <main+0x18b>
mov    -0x20(%rbp),%rax
lea    0xe1f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
sub    $0x30,%eax
imul   $0xa,%eax,%eax
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
sub    $0x30,%eax
mov    %al,-0x16(%rbp)
movsbl -0x15(%rbp),%eax
movsbl -0x16(%rbp),%ecx
add    %ecx,%eax
movsbl %al,%edi
call   1040 <ir_hasta_pos@plt>
jmp    130b <main+0x18b>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
sub    $0x30,%eax
imul   $0xa,%eax,%eax
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
sub    $0x30,%eax
mov    %al,-0x16(%rbp)
movsbl -0x15(%rbp),%eax
movsbl -0x16(%rbp),%ecx
add    %ecx,%eax
movsbl %al,%edi
call   1080 <avanzar_n_pasos@plt>
jmp    130b <main+0x18b>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
sub    $0x30,%eax
imul   $0xa,%eax,%eax
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
sub    $0x30,%eax
mov    %al,-0x16(%rbp)
movsbl -0x15(%rbp),%eax
movsbl -0x16(%rbp),%ecx
add    %ecx,%eax
movsbl %al,%edi
call   1090 <retroceder_n_pasos@plt>
jmp    130b <main+0x18b>
mov    $0x0,%al
call   1070 <get_posicion@plt>
mov    %al,-0x6(%rbp)
movsbl -0x6(%rbp),%eax
cmp    $0xa,%eax
jge    12ba <main+0x13a>
movb   $0x3a,-0x13(%rbp)
movsbl -0x6(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x12(%rbp)
movb   $0x0,-0x11(%rbp)
jmp    12f6 <main+0x176>
movsbl -0x6(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %al,-0x15(%rbp)
movsbl -0x6(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x16(%rbp)
movb   $0x3a,-0x13(%rbp)
movsbl -0x15(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x12(%rbp)
movsbl -0x16(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x11(%rbp)
movb   $0x0,-0x10(%rbp)
lea    -0x13(%rbp),%rdi
call   1030 <modem_enviar_sms@plt>
jmp    130b <main+0x18b>
mov    $0x0,%al
call   1060 <motor_init@plt>
jmp    11a1 <main+0x21>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1060 <motor_init@plt>
xor    %eax,%eax
call   10a0 <modem_init@plt>
lea    0xe(%rsp),%r14
lea    0xf(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xe4f(%rip),%rbx
lea    0xd(%rsp),%r13
jmp    11c0 <main+0x40>
xor    %eax,%eax
call   1060 <motor_init@plt>
nop
xor    %eax,%eax
call   1050 <modem_leer_sms@plt>
movsbl (%rax),%ecx
add    $0xffffffbe,%ecx
cmp    $0x10,%ecx
ja     11c0 <main+0x40>
movslq (%rbx,%rcx,4),%rcx
add    %rbx,%rcx
jmp    *%rcx
movzbl 0x1(%rax),%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
add    0x2(%rax),%cl
add    $0xf0,%cl
movsbl %cl,%edi
call   1090 <retroceder_n_pasos@plt>
jmp    11c0 <main+0x40>
movzbl 0x1(%rax),%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
add    0x2(%rax),%cl
add    $0xf0,%cl
movsbl %cl,%edi
call   1080 <avanzar_n_pasos@plt>
jmp    11c0 <main+0x40>
xor    %eax,%eax
call   1070 <get_posicion@plt>
cmp    $0x9,%al
jg     123e <main+0xbe>
movb   $0x3a,0xd(%rsp)
mov    %r14,%rcx
mov    %r15,%rdx
jmp    1264 <main+0xe4>
movzbl 0x1(%rax),%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
add    0x2(%rax),%cl
add    $0xf0,%cl
movsbl %cl,%edi
call   1040 <ir_hasta_pos@plt>
jmp    11c0 <main+0x40>
movzbl %al,%ecx
imul   $0xcd,%ecx,%ecx
shr    $0xb,%ecx
lea    (%rcx,%rcx,1),%edx
lea    (%rdx,%rdx,4),%edx
sub    %dl,%al
movb   $0x3a,0xd(%rsp)
add    $0x30,%cl
mov    %cl,0xe(%rsp)
mov    %r15,%rcx
mov    %r12,%rdx
add    $0x30,%al
mov    %al,(%rcx)
movb   $0x0,(%rdx)
mov    %r13,%rdi
call   1030 <modem_enviar_sms@plt>
jmp    11c0 <main+0x40>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8*
%5 = alloca [3 x i8]
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
store i32 0, i32* %1
%9 = call i32 (...) @motor_init()
%10 = call i32 (...) @modem_init()
store i8 0, i8* %2
br label %11
11: ; preds = %0, %120
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %4
%12 = call i8* (...) @modem_leer_sms()
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
store i8 %15, i8* %6
%16 = load i8, i8* %6
%17 = sext i8 %16 to i32
switch i32 %17, label %120 [
i32 72, label %18
i32 70, label %39
i32 66, label %60
i32 71, label %81
i32 82, label %118
]
18: ; preds = %11
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = sub nsw i32 %22, 48
%24 = mul nsw i32 %23, 10
%25 = trunc i32 %24 to i8
store i8 %25, i8* %7
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 2
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = sub nsw i32 %29, 48
%31 = trunc i32 %30 to i8
store i8 %31, i8* %8
%32 = load i8, i8* %7
%33 = sext i8 %32 to i32
%34 = load i8, i8* %8
%35 = sext i8 %34 to i32
%36 = add nsw i32 %33, %35
%37 = trunc i32 %36 to i8
%38 = call i32 @ir_hasta_pos(i8 signext %37)
br label %120
39: ; preds = %11
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = sub nsw i32 %43, 48
%45 = mul nsw i32 %44, 10
%46 = trunc i32 %45 to i8
store i8 %46, i8* %7
%47 = load i8*, i8** %4
%48 = getelementptr inbounds i8, i8* %47, i64 2
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = sub nsw i32 %50, 48
%52 = trunc i32 %51 to i8
store i8 %52, i8* %8
%53 = load i8, i8* %7
%54 = sext i8 %53 to i32
%55 = load i8, i8* %8
%56 = sext i8 %55 to i32
%57 = add nsw i32 %54, %56
%58 = trunc i32 %57 to i8
%59 = call i32 @avanzar_n_pasos(i8 signext %58)
br label %120
60: ; preds = %11
%61 = load i8*, i8** %4
%62 = getelementptr inbounds i8, i8* %61, i64 1
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = sub nsw i32 %64, 48
%66 = mul nsw i32 %65, 10
%67 = trunc i32 %66 to i8
store i8 %67, i8* %7
%68 = load i8*, i8** %4
%69 = getelementptr inbounds i8, i8* %68, i64 2
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = sub nsw i32 %71, 48
%73 = trunc i32 %72 to i8
store i8 %73, i8* %8
%74 = load i8, i8* %7
%75 = sext i8 %74 to i32
%76 = load i8, i8* %8
%77 = sext i8 %76 to i32
%78 = add nsw i32 %75, %77
%79 = trunc i32 %78 to i8
%80 = call i32 @retroceder_n_pasos(i8 signext %79)
br label %120
81: ; preds = %11
%82 = call signext i8 (...) @get_posicion()
store i8 %82, i8* %3
%83 = load i8, i8* %3
%84 = sext i8 %83 to i32
%85 = icmp slt i32 %84, 10
br i1 %85, label %86, label %94
86: ; preds = %81
%87 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 58, i8* %87
%88 = load i8, i8* %3
%89 = sext i8 %88 to i32
%90 = add nsw i32 %89, 48
%91 = trunc i32 %90 to i8
%92 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 %91, i8* %92
%93 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
store i8 0, i8* %93
br label %115
94: ; preds = %81
%95 = load i8, i8* %3
%96 = sext i8 %95 to i32
%97 = sdiv i32 %96, 10
%98 = trunc i32 %97 to i8
store i8 %98, i8* %7
%99 = load i8, i8* %3
%100 = sext i8 %99 to i32
%101 = srem i32 %100, 10
%102 = trunc i32 %101 to i8
store i8 %102, i8* %8
%103 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 58, i8* %103
%104 = load i8, i8* %7
%105 = sext i8 %104 to i32
%106 = add nsw i32 %105, 48
%107 = trunc i32 %106 to i8
%108 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 %107, i8* %108
%109 = load i8, i8* %8
%110 = sext i8 %109 to i32
%111 = add nsw i32 %110, 48
%112 = trunc i32 %111 to i8
%113 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
store i8 %112, i8* %113
%114 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 3
store i8 0, i8* %114
br label %115
115: ; preds = %94, %86
%116 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%117 = call i32 @modem_enviar_sms(i8* %116)
br label %120
118: ; preds = %11
%119 = call i32 (...) @motor_init()
br label %120
120: ; preds = %11, %118, %115, %60, %39, %18
br label %11
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [3 x i8]
%2 = tail call i32 (...) @motor_init()
%3 = tail call i32 (...) @modem_init()
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 1
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 2
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 3
br label %8
8: ; preds = %12, %0
%9 = call i8* (...) @modem_leer_sms()
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
switch i32 %11, label %12 [
i32 72, label %13
i32 70, label %22
i32 66, label %31
i32 71, label %40
i32 82, label %54
]
12: ; preds = %8, %54, %48, %31, %22, %13
br label %8
13: ; preds = %8
%14 = getelementptr inbounds i8, i8* %9, i64 1
%15 = load i8, i8* %14
%16 = mul i8 %15, 10
%17 = getelementptr inbounds i8, i8* %9, i64 2
%18 = load i8, i8* %17
%19 = add i8 %18, -16
%20 = add i8 %19, %16
%21 = call i32 @ir_hasta_pos(i8 signext %20)
br label %12
22: ; preds = %8
%23 = getelementptr inbounds i8, i8* %9, i64 1
%24 = load i8, i8* %23
%25 = mul i8 %24, 10
%26 = getelementptr inbounds i8, i8* %9, i64 2
%27 = load i8, i8* %26
%28 = add i8 %27, -16
%29 = add i8 %28, %25
%30 = call i32 @avanzar_n_pasos(i8 signext %29)
br label %12
31: ; preds = %8
%32 = getelementptr inbounds i8, i8* %9, i64 1
%33 = load i8, i8* %32
%34 = mul i8 %33, 10
%35 = getelementptr inbounds i8, i8* %9, i64 2
%36 = load i8, i8* %35
%37 = add i8 %36, -16
%38 = add i8 %37, %34
%39 = call i32 @retroceder_n_pasos(i8 signext %38)
br label %12
40: ; preds = %8
%41 = call signext i8 (...) @get_posicion()
%42 = icmp slt i8 %41, 10
br i1 %42, label %43, label %44
43: ; preds = %40
store i8 58, i8* %4
br label %48
44: ; preds = %40
%45 = udiv i8 %41, 10
%46 = urem i8 %41, 10
store i8 58, i8* %4
%47 = add nuw nsw i8 %45, 48
store i8 %47, i8* %5
br label %48
48: ; preds = %44, %43
%49 = phi i8 [ %46, %44 ], [ %41, %43 ]
%50 = phi i8* [ %6, %44 ], [ %5, %43 ]
%51 = phi i8* [ %7, %44 ], [ %6, %43 ]
%52 = add nsw i8 %49, 48
store i8 %52, i8* %50
store i8 0, i8* %51
%53 = call i32 @modem_enviar_sms(i8* %4)
br label %12
54: ; preds = %8
%55 = call i32 (...) @motor_init()
br label %12
}