#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char);
char getopt(int, char **, char *);
int open(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ testpr1(int);
int /*<<< orphan*/ testpr2(int);
int /*<<< orphan*/ testpr3(int);
int /*<<< orphan*/ testpr4(int);
int /*<<< orphan*/ usage(char **, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int pr = 0, optional = 0;
  char optc;
  int input_fd = 0;
  while ((optc = getopt(argc, argv, "+hp:oe::i:")) != -1) {
    switch (optc) {
    case 'h':
      usage(argv, EXIT_SUCCESS);
      exit(0);
      break;
    case 'p':
      pr = atoi(optarg);
      break;
    case 'o':
      optional = 1;
      break;
    case 'i':
      input_fd = open(optarg, O_RDONLY);
      if (input_fd < 0)
        usage(argv, EXIT_FAILURE);
      break;
    default:
      fprintf(stderr, "Opcion incorrecta: %c\n", optc);
      usage(argv, EXIT_FAILURE);
    }
  }
  switch (pr) {
  case 1:
    testpr1(optional);
    break;
  case 2:
    testpr2(optional);
    break;
  case 3:
    testpr3(input_fd);
    break;
  case 4:
    testpr4(optional);
    break;
  default:
    fprintf(stderr, "Practica incorrecta: %c\n", optc);
    usage(argv, EXIT_FAILURE);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe5b(%rip),%rdx
call   1080 <getopt@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     12bd <main+0x11d>
movsbl -0x19(%rbp),%eax
add    $0xffffff98,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x8,%eax
ja     128d <main+0xed>
mov    -0x28(%rbp),%rax
lea    0xe02(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    0x2d9e(%rip),%rax
mov    (%rax),%esi
call   1060 <usage@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    12b8 <main+0x118>
movl   $0x1,-0x18(%rbp)
jmp    12b8 <main+0x118>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1288 <main+0xe8>
mov    -0x10(%rbp),%rdi
mov    0x2d47(%rip),%rax
mov    (%rax),%esi
call   1060 <usage@plt>
jmp    12b8 <main+0x118>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
movsbl -0x19(%rbp),%edx
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d17(%rip),%rax
mov    (%rax),%esi
call   1060 <usage@plt>
jmp    11cb <main+0x2b>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x3,%eax
ja     131a <main+0x17a>
mov    -0x30(%rbp),%rax
lea    0xd23(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%edi
call   1040 <testpr1@plt>
jmp    1345 <main+0x1a5>
mov    -0x18(%rbp),%edi
call   10c0 <testpr2@plt>
jmp    1345 <main+0x1a5>
mov    -0x20(%rbp),%edi
call   1030 <testpr3@plt>
jmp    1345 <main+0x1a5>
mov    -0x18(%rbp),%edi
call   10b0 <testpr4@plt>
jmp    1345 <main+0x1a5>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
lea    0xd2c(%rip),%rsi
movsbl -0x19(%rbp),%edx
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2c8a(%rip),%rax
mov    (%rax),%esi
call   1060 <usage@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe7a(%rip),%rdx
call   1080 <getopt@plt>
cmp    $0xff,%al
je     12b2 <main+0x112>
movl   $0x0,0xc(%rsp)
lea    0xe5e(%rip),%r12
lea    0xe23(%rip),%r13
xor    %r15d,%r15d
xor    %ecx,%ecx
mov    %rcx,0x10(%rsp)
jmp    1217 <main+0x77>
nopl   0x0(%rax)
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
mov    %rax,0x10(%rsp)
mov    %r14d,%r15d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1080 <getopt@plt>
cmp    $0xff,%al
je     128b <main+0xeb>
mov    %r15d,%r14d
movsbl %al,%edx
lea    -0x68(%rdx),%eax
cmp    $0x8,%eax
ja     1260 <main+0xc0>
mov    $0x1,%r15d
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    0x2d9b(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
jns    1203 <main+0x63>
jmp    1275 <main+0xd5>
cs nopw 0x0(%rax,%rax,1)
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <usage@plt>
jmp    1203 <main+0x63>
mov    0x10(%rsp),%rcx
add    $0xffffffff,%ecx
cmp    $0x3,%ecx
ja     12b2 <main+0x112>
lea    0xd85(%rip),%rax
movslq (%rax,%rcx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    %r15d,%edi
call   1040 <testpr1@plt>
jmp    12dd <main+0x13d>
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
lea    0xd94(%rip),%rsi
mov    $0xffffffff,%edx
call   1050 <fprintf@plt>
mov    0x2cf5(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <usage@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15d,%edi
call   10c0 <testpr2@plt>
jmp    12dd <main+0x13d>
mov    0xc(%rsp),%edi
call   1030 <testpr3@plt>
jmp    12dd <main+0x13d>
mov    %r15d,%edi
call   10b0 <testpr4@plt>
jmp    12dd <main+0x13d>
mov    0x2cac(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <usage@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"+hp:oe::i:\00"
@EXIT_SUCCESS = global i32 0
@optarg = global i32 0
@O_RDONLY = global i32 0
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [23 x i8] c"Opcion incorrecta: %c\0A\00"
@.str.2 = [25 x i8] c"Practica incorrecta: %c\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %9
br label %10
10: ; preds = %46, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call signext i8 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8 %13, i8* %8
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %47
16: ; preds = %10
%17 = load i8, i8* %8
%18 = sext i8 %17 to i32
switch i32 %18, label %39 [
i32 104, label %19
i32 112, label %24
i32 111, label %27
i32 105, label %28
]
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = load i32, i32* @EXIT_SUCCESS
%22 = call i32 @usage(i8** %20, i32 %21)
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %16
%25 = load i32, i32* @optarg
%26 = call i32 @atoi(i32 %25)
store i32 %26, i32* %6
br label %46
27: ; preds = %16
store i32 1, i32* %7
br label %46
28: ; preds = %16
%29 = load i32, i32* @optarg
%30 = load i32, i32* @O_RDONLY
%31 = call i32 @open(i32 %29, i32 %30)
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %28
%35 = load i8**, i8*** %5
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @usage(i8** %35, i32 %36)
br label %38
38: ; preds = %34, %28
br label %46
39: ; preds = %16
%40 = load i32, i32* @stderr
%41 = load i8, i8* %8
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8 signext %41)
%43 = load i8**, i8*** %5
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @usage(i8** %43, i32 %44)
br label %46
46: ; preds = %39, %38, %27, %24
br label %10
47: ; preds = %10
%48 = load i32, i32* %6
switch i32 %48, label %61 [
i32 1, label %49
i32 2, label %52
i32 3, label %55
i32 4, label %58
]
49: ; preds = %47
%50 = load i32, i32* %7
%51 = call i32 @testpr1(i32 %50)
br label %68
52: ; preds = %47
%53 = load i32, i32* %7
%54 = call i32 @testpr2(i32 %53)
br label %68
55: ; preds = %47
%56 = load i32, i32* %9
%57 = call i32 @testpr3(i32 %56)
br label %68
58: ; preds = %47
%59 = load i32, i32* %7
%60 = call i32 @testpr4(i32 %59)
br label %68
61: ; preds = %47
%62 = load i32, i32* @stderr
%63 = load i8, i8* %8
%64 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8 signext %63)
%65 = load i8**, i8*** %5
%66 = load i32, i32* @EXIT_FAILURE
%67 = call i32 @usage(i8** %65, i32 %66)
br label %68
68: ; preds = %61, %58, %55, %52, %49
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"+hp:oe::i:\00"
@EXIT_SUCCESS = global i32 0
@optarg = global i32 0
@O_RDONLY = global i32 0
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [23 x i8] c"Opcion incorrecta: %c\0A\00"
@.str.2 = [25 x i8] c"Practica incorrecta: %c\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8 %3, -1
br i1 %4, label %46, label %5
5: ; preds = %2, %31
%6 = phi i8 [ %35, %31 ], [ %3, %2 ]
%7 = phi i32 [ %34, %31 ], [ 0, %2 ]
%8 = phi i32 [ %33, %31 ], [ 0, %2 ]
%9 = phi i32 [ %32, %31 ], [ 0, %2 ]
%10 = sext i8 %6 to i32
switch i32 %10, label %26 [
i32 104, label %11
i32 112, label %15
i32 111, label %31
i32 105, label %18
]
11: ; preds = %5
%12 = load i32, i32* @EXIT_SUCCESS
%13 = tail call i32 @usage(i8** %1, i32 %12)
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %5
%16 = load i32, i32* @optarg
%17 = tail call i32 @atoi(i32 %16)
br label %31
18: ; preds = %5
%19 = load i32, i32* @optarg
%20 = load i32, i32* @O_RDONLY
%21 = tail call i32 @open(i32 %19, i32 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %18
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @usage(i8** %1, i32 %24)
br label %31
26: ; preds = %5
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8 signext %6)
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @usage(i8** %1, i32 %29)
br label %31
31: ; preds = %5, %18, %23, %26, %15
%32 = phi i32 [ %9, %26 ], [ %9, %23 ], [ %9, %18 ], [ %17, %15 ], [ %9, %5 ]
%33 = phi i32 [ %8, %26 ], [ %8, %23 ], [ %8, %18 ], [ %8, %15 ], [ 1, %5 ]
%34 = phi i32 [ %7, %26 ], [ %21, %23 ], [ %21, %18 ], [ %7, %15 ], [ %7, %5 ]
%35 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%36 = icmp eq i8 %35, -1
br i1 %36, label %37, label %5
37: ; preds = %31
switch i32 %32, label %46 [
i32 1, label %38
i32 2, label %40
i32 3, label %42
i32 4, label %44
]
38: ; preds = %37
%39 = tail call i32 @testpr1(i32 %33)
br label %51
40: ; preds = %37
%41 = tail call i32 @testpr2(i32 %33)
br label %51
42: ; preds = %37
%43 = tail call i32 @testpr3(i32 %34)
br label %51
44: ; preds = %37
%45 = tail call i32 @testpr4(i32 %33)
br label %51
46: ; preds = %2, %37
%47 = load i32, i32* @stderr
%48 = tail call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8 signext -1)
%49 = load i32, i32* @EXIT_FAILURE
%50 = tail call i32 @usage(i8** %1, i32 %49)
br label %51
51: ; preds = %46, %44, %42, %40, %38
ret i32 0
}