#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*/ devices();
int /*<<< orphan*/ error();
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ help();
int /*<<< orphan*/ infoBeacons();
int /*<<< orphan*/ lista_beacons();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcmp(char *, char *);
main() {
  printf("-->Aplicación de detección y tratamiento de Beacons\n");
  char action[20];
  printf("-->Introduzca una acción de las siguientes: \nlistaBeacons \ndevices "
         "\ninfobeacons \nhelp \n");
  fgets(action, 20, stdin);
  printf("-->La cadena leída es: %s \n", action);
  if (!strcmp(action, "listaBeacons\n")) {
    int pid;
    pid = fork();
    switch (pid) {
    case -1:
      perror("No se ha podido crear el proceso\n");
      break;
    case 0:
      lista_beacons();
      break;
    default:
      break;
    }
  } else if (!strcmp(action, "devices\n")) {
    int pid;
    pid = fork();
    switch (pid) {
    case -1:
      perror("No se ha podido crear el proceso\n");
      break;
    case 0:
      devices();
      break;
    default:
      break;
    }
  } else if (!strcmp(action, "infobeacons\n")) {
    int pid;
    pid = fork();
    switch (pid) {
    case -1:
      perror("No se ha podido crear el proceso\n");
      break;
    case 0:
      infoBeacons();
      break;
    default:
      break;
    }
  } else if (!strcmp(action, "help\n")) {
    help();
  } else {
    error();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1070 <fgets@plt>
lea    -0x20(%rbp),%rsi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    0xeae(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1262 <main+0xc2>
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0xffffffff,%eax
je     123b <main+0x9b>
jmp    122b <main+0x8b>
mov    -0x30(%rbp),%eax
test   %eax,%eax
je     124c <main+0xac>
jmp    1258 <main+0xb8>
lea    0xe79(%rip),%rdi
call   10a0 <perror@plt>
jmp    125d <main+0xbd>
mov    $0x0,%al
call   1040 <lista_beacons@plt>
jmp    125d <main+0xbd>
jmp    125d <main+0xbd>
jmp    1379 <main+0x1d9>
lea    -0x20(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    12d0 <main+0x130>
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0xffffffff,%eax
je     12a9 <main+0x109>
jmp    1299 <main+0xf9>
mov    -0x34(%rbp),%eax
test   %eax,%eax
je     12ba <main+0x11a>
jmp    12c6 <main+0x126>
lea    0xe0b(%rip),%rdi
call   10a0 <perror@plt>
jmp    12cb <main+0x12b>
mov    $0x0,%al
call   1050 <devices@plt>
jmp    12cb <main+0x12b>
jmp    12cb <main+0x12b>
jmp    1374 <main+0x1d4>
lea    -0x20(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    133e <main+0x19e>
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0xffffffff,%eax
je     1317 <main+0x177>
jmp    1307 <main+0x167>
mov    -0x38(%rbp),%eax
test   %eax,%eax
je     1328 <main+0x188>
jmp    1334 <main+0x194>
lea    0xd9d(%rip),%rdi
call   10a0 <perror@plt>
jmp    1339 <main+0x199>
mov    $0x0,%al
call   1030 <infoBeacons@plt>
jmp    1339 <main+0x199>
jmp    1339 <main+0x199>
jmp    136f <main+0x1cf>
lea    -0x20(%rbp),%rdi
lea    0xdaa(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1363 <main+0x1c3>
mov    $0x0,%al
call   10b0 <help@plt>
jmp    136a <main+0x1ca>
mov    $0x0,%al
call   1090 <error@plt>
jmp    136f <main+0x1cf>
jmp    1374 <main+0x1d4>
jmp    1379 <main+0x1d9>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movabs $0xa736e6f636165,%rbx
lea    0xeb1(%rip),%rdi
call   1040 <puts@plt>
lea    0xedb(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x14,%esi
call   1080 <fgets@plt>
lea    0xe17(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
movabs $0x616542617473696c,%rax
42 65 61
xor    (%rsp),%rax
mov    0x6(%rsp),%rcx
xor    %rbx,%rcx
or     %rax,%rcx
je     125b <main+0xbb>
movabs $0xa73656369766564,%rax
65 73 0a
xor    (%rsp),%rax
movzbl 0x8(%rsp),%ecx
or     %rax,%rcx
je     126f <main+0xcf>
movabs $0x636165626f666e69,%rax
65 61 63
xor    (%rsp),%rax
xor    0x5(%rsp),%rbx
or     %rax,%rbx
je     1283 <main+0xe3>
mov    $0x706c6568,%eax
xor    (%rsp),%eax
movzwl 0x4(%rsp),%ecx
xor    $0xa,%ecx
or     %eax,%ecx
je     129d <main+0xfd>
xor    %eax,%eax
call   1090 <error@plt>
jmp    1293 <main+0xf3>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
jne    128e <main+0xee>
xor    %eax,%eax
call   1050 <lista_beacons@plt>
jmp    1293 <main+0xf3>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
jne    128e <main+0xee>
xor    %eax,%eax
call   1060 <devices@plt>
jmp    1293 <main+0xf3>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
je     12a6 <main+0x106>
cmp    $0xffffffff,%eax
je     12af <main+0x10f>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   10b0 <help@plt>
jmp    1293 <main+0xf3>
xor    %eax,%eax
call   1030 <infoBeacons@plt>
jmp    1293 <main+0xf3>
lea    0xd75(%rip),%rdi
call   10a0 <perror@plt>
jmp    1293 <main+0xf3>

LLVM IR (-O0):
@.str = [55 x i8] c"-->Aplicaci\C3\B3n de detecci\C3\B3n y tratamiento de Beacons\0A\00"
@.str.1 = [89 x i8] c"-->Introduzca una acci\C3\B3n de las siguientes: \0AlistaBeacons \0Adevices \0Ainfobeacons \0Ahelp \0A\00"
@stdin = global i32 0
@.str.2 = [29 x i8] c"-->La cadena le\C3\ADda es: %s \0A\00"
@.str.3 = [14 x i8] c"listaBeacons\0A\00"
@.str.4 = [34 x i8] c"No se ha podido crear el proceso\0A\00"
@.str.5 = [9 x i8] c"devices\0A\00"
@.str.6 = [13 x i8] c"infobeacons\0A\00"
@.str.7 = [6 x i8] c"help\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %8, i32 20, i32 %9)
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%14 = call i32 @strcmp(i8* %13, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp ne i32 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %0
%17 = call i32 (...) @fork()
store i32 %17, i32* %3
%18 = load i32, i32* %3
switch i32 %18, label %23 [
i32 -1, label %19
i32 0, label %21
]
19: ; preds = %16
%20 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %24
21: ; preds = %16
%22 = call i32 (...) @lista_beacons()
br label %24
23: ; preds = %16
br label %24
24: ; preds = %23, %21, %19
br label %62
25: ; preds = %0
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %38, label %29
29: ; preds = %25
%30 = call i32 (...) @fork()
store i32 %30, i32* %4
%31 = load i32, i32* %4
switch i32 %31, label %36 [
i32 -1, label %32
i32 0, label %34
]
32: ; preds = %29
%33 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %37
34: ; preds = %29
%35 = call i32 (...) @devices()
br label %37
36: ; preds = %29
br label %37
37: ; preds = %36, %34, %32
br label %61
38: ; preds = %25
%39 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%40 = call i32 @strcmp(i8* %39, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%41 = icmp ne i32 %40, 0
br i1 %41, label %51, label %42
42: ; preds = %38
%43 = call i32 (...) @fork()
store i32 %43, i32* %5
%44 = load i32, i32* %5
switch i32 %44, label %49 [
i32 -1, label %45
i32 0, label %47
]
45: ; preds = %42
%46 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %50
47: ; preds = %42
%48 = call i32 (...) @infoBeacons()
br label %50
49: ; preds = %42
br label %50
50: ; preds = %49, %47, %45
br label %60
51: ; preds = %38
%52 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%53 = call i32 @strcmp(i8* %52, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%54 = icmp ne i32 %53, 0
br i1 %54, label %57, label %55
55: ; preds = %51
%56 = call i32 (...) @help()
br label %59
57: ; preds = %51
%58 = call i32 (...) @error()
br label %59
59: ; preds = %57, %55
br label %60
60: ; preds = %59, %50
br label %61
61: ; preds = %60, %37
br label %62
62: ; preds = %61, %24
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.2 = [29 x i8] c"-->La cadena le\C3\ADda es: %s \0A\00"
@.str.3 = [14 x i8] c"listaBeacons\0A\00"
@.str.4 = [34 x i8] c"No se ha podido crear el proceso\0A\00"
@.str.5 = [9 x i8] c"devices\0A\00"
@.str.6 = [13 x i8] c"infobeacons\0A\00"
@.str.7 = [6 x i8] c"help\0A\00"
@str = [54 x i8] c"-->Aplicaci\C3\B3n de detecci\C3\B3n y tratamiento de Beacons\00"
@str.8 = [88 x i8] c"-->Introduzca una acci\C3\B3n de las siguientes: \0AlistaBeacons \0Adevices \0Ainfobeacons \0Ahelp \00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str, i64 0, i64 0))
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([88 x i8], [88 x i8]* @str.8, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %3, i32 20, i32 %5)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%8 = call i32 @bcmp(i8* dereferenceable(14) %3, i8* dereferenceable(14) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i64 14)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %0
%11 = call i32 (...) @fork()
switch i32 %11, label %41 [
i32 -1, label %12
i32 0, label %14
]
12: ; preds = %10
%13 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %41
14: ; preds = %10
%15 = call i32 (...) @lista_beacons()
br label %41
16: ; preds = %0
%17 = call i32 @bcmp(i8* dereferenceable(9) %3, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i64 9)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = call i32 (...) @fork()
switch i32 %20, label %41 [
i32 -1, label %21
i32 0, label %23
]
21: ; preds = %19
%22 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %41
23: ; preds = %19
%24 = call i32 (...) @devices()
br label %41
25: ; preds = %16
%26 = call i32 @bcmp(i8* dereferenceable(13) %3, i8* dereferenceable(13) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i64 13)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = call i32 (...) @fork()
switch i32 %29, label %41 [
i32 -1, label %30
i32 0, label %32
]
30: ; preds = %28
%31 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %41
32: ; preds = %28
%33 = call i32 (...) @infoBeacons()
br label %41
34: ; preds = %25
%35 = call i32 @bcmp(i8* dereferenceable(6) %3, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i64 6)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 (...) @help()
br label %41
39: ; preds = %34
%40 = call i32 (...) @error()
br label %41
41: ; preds = %30, %32, %28, %21, %23, %19, %12, %14, %10, %37, %39
ret i32 0
}