#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*/ F_DUPFD;
int O_CREAT;
int O_RDONLY;
int O_WRONLY;
int STDIN_FILENO;
int STDOUT_FILENO;
int /*<<< orphan*/ close(int);
scalar_t__ execlp(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int fcntl(int, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  if (argc != 4) {
    printf("Modo de uso: %s <programa> <simbolo> <archivo>\n\n", argv[0]);
    exit(1);
  } else {
    char *str_command;
    char *str_file;
    int fd;
    str_command = argv[1];
    str_file = argv[3];
    if (strcmp(argv[2], "<") == 0) {
      fd = open(str_file, O_RDONLY);
      close(STDIN_FILENO);
      if (fcntl(fd, F_DUPFD, STDIN_FILENO) == -1)
        perror("fcntl falló");
    } else if (strcmp(argv[2], ">") == 0) {
      fd = open(str_file, O_CREAT | O_WRONLY);
      close(STDOUT_FILENO);
      if (fcntl(fd, F_DUPFD, STDOUT_FILENO) == -1)
        perror("fcntl falló");
    } else {
      printf("Debe pasarse \"<\" o \">\" con las comillas %s\n\n", argv[2]);
      printf("Modo de uso: %s <programa> [opciones] [bg]\n\n", argv[0]);
      exit(1);
    }
    if ((execlp(str_command, "", NULL) < 0)) {
      perror("Error en el execlp\n");
      exit(-1);
    }
    close(fd);
  }
}


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)
cmpl   $0x4,-0x8(%rbp)
je     11bd <main+0x3d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe4d(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    124a <main+0xca>
mov    -0x20(%rbp),%rdi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%edi
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
mov    0x2d97(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    1245 <main+0xc5>
lea    0xdf3(%rip),%rdi
call   1080 <perror@plt>
jmp    12fe <main+0x17e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xde7(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12c8 <main+0x148>
mov    -0x20(%rbp),%rdi
mov    0x2d85(%rip),%rax
mov    (%rax),%esi
mov    0x2d34(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%edi
mov    0x2d32(%rip),%rax
mov    (%rax),%esi
mov    0x2d41(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    12c3 <main+0x143>
lea    0xd75(%rip),%rdi
call   1080 <perror@plt>
jmp    12f9 <main+0x179>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd6b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd85(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    12fe <main+0x17e>
mov    -0x18(%rbp),%rdi
lea    0xd27(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10a0 <execlp@plt>
cmp    $0x0,%rax
jge    1332 <main+0x1b2>
lea    0xd79(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
cmp    $0x4,%edi
jne    1255 <main+0xd5>
mov    0x8(%rbp),%r14
mov    0x10(%rbp),%rdi
mov    0x18(%rbp),%rbx
lea    0xe8e(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11eb <main+0x6b>
mov    0x10(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1278 <main+0xf8>
mov    0x2e2b(%rip),%rax
mov    0x2ddc(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
mov    %eax,%ebp
mov    0x2dff(%rip),%rbx
jmp    1205 <main+0x85>
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
mov    %eax,%ebp
mov    0x2dbb(%rip),%rbx
mov    (%rbx),%edi
call   1050 <close@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
mov    (%rbx),%edx
mov    %ebp,%edi
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1247 <main+0xc7>
lea    0xe06(%rip),%rsi
mov    %r14,%rdi
xor    %edx,%edx
call   10a0 <execlp@plt>
test   %rax,%rax
js     1262 <main+0xe2>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xde5(%rip),%rdi
call   1080 <perror@plt>
jmp    1223 <main+0xa3>
mov    0x0(%rbp),%rsi
lea    0xda0(%rip),%rdi
jmp    1293 <main+0x113>
lea    0xe33(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    0x10(%rbp),%rsi
lea    0xdbf(%rip),%rdi
call   1040 <printf@plt>
mov    0x0(%rbp),%rsi
lea    0xddc(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [49 x i8] c"Modo de uso: %s <programa> <simbolo> <archivo>\0A\0A\00"
@.str.1 = [2 x i8] c"<\00"
@O_RDONLY = global i32 0
@STDIN_FILENO = global i32 0
@F_DUPFD = global i32 0
@.str.2 = [13 x i8] c"fcntl fall\C3\B3\00"
@.str.3 = [2 x i8] c">\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@STDOUT_FILENO = global i32 0
@.str.4 = [45 x i8] c"Debe pasarse \22<\22 o \22>\22 con las comillas %s\0A\0A\00"
@.str.5 = [45 x i8] c"Modo de uso: %s <programa> [opciones] [bg]\0A\0A\00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [20 x i8] c"Error en el execlp\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 4
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %6
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 3
%23 = load i8*, i8** %22
store i8* %23, i8** %7
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %43
29: ; preds = %17
%30 = load i8*, i8** %7
%31 = load i32, i32* @O_RDONLY
%32 = call i32 @open(i8* %30, i32 %31)
store i32 %32, i32* %8
%33 = load i32, i32* @STDIN_FILENO
%34 = call i32 @close(i32 %33)
%35 = load i32, i32* %8
%36 = load i32, i32* @F_DUPFD
%37 = load i32, i32* @STDIN_FILENO
%38 = call i32 @fcntl(i32 %35, i32 %36, i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %29
%41 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %40, %29
br label %76
43: ; preds = %17
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %65
49: ; preds = %43
%50 = load i8*, i8** %7
%51 = load i32, i32* @O_CREAT
%52 = load i32, i32* @O_WRONLY
%53 = or i32 %51, %52
%54 = call i32 @open(i8* %50, i32 %53)
store i32 %54, i32* %8
%55 = load i32, i32* @STDOUT_FILENO
%56 = call i32 @close(i32 %55)
%57 = load i32, i32* %8
%58 = load i32, i32* @F_DUPFD
%59 = load i32, i32* @STDOUT_FILENO
%60 = call i32 @fcntl(i32 %57, i32 %58, i32 %59)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %64
62: ; preds = %49
%63 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %64
64: ; preds = %62, %49
br label %75
65: ; preds = %43
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 2
%68 = load i8*, i8** %67
%69 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %68)
%70 = load i8**, i8*** %5
%71 = getelementptr inbounds i8*, i8** %70, i64 0
%72 = load i8*, i8** %71
%73 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i8* %72)
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %64
br label %76
76: ; preds = %75, %42
%77 = load i8*, i8** %6
%78 = call i64 @execlp(i8* %77, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i32* null)
%79 = icmp slt i64 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %76
%81 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%82 = call i32 @exit(i32 -1)
unreachable
83: ; preds = %76
%84 = load i32, i32* %8
%85 = call i32 @close(i32 %84)
br label %86
86: ; preds = %83
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@.str = [49 x i8] c"Modo de uso: %s <programa> <simbolo> <archivo>\0A\0A\00"
@.str.1 = [2 x i8] c"<\00"
@O_RDONLY = global i32 0
@STDIN_FILENO = global i32 0
@F_DUPFD = global i32 0
@.str.2 = [13 x i8] c"fcntl fall\C3\B3\00"
@.str.3 = [2 x i8] c">\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@STDOUT_FILENO = global i32 0
@.str.4 = [45 x i8] c"Debe pasarse \22<\22 o \22>\22 con las comillas %s\0A\0A\00"
@.str.5 = [45 x i8] c"Modo de uso: %s <programa> [opciones] [bg]\0A\0A\00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [20 x i8] c"Error en el execlp\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 3
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %8
%18 = load i32, i32* @O_RDONLY
%19 = tail call i32 @open(i8* %12, i32 %18)
%20 = load i32, i32* @STDIN_FILENO
%21 = tail call i32 @close(i32 %20)
%22 = load i32, i32* @F_DUPFD
%23 = load i32, i32* @STDIN_FILENO
%24 = tail call i32 @fcntl(i32 %19, i32 %22, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %47, label %50
26: ; preds = %8
%27 = load i8*, i8** %13
%28 = tail call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %41
30: ; preds = %26
%31 = load i32, i32* @O_CREAT
%32 = load i32, i32* @O_WRONLY
%33 = or i32 %32, %31
%34 = tail call i32 @open(i8* %12, i32 %33)
%35 = load i32, i32* @STDOUT_FILENO
%36 = tail call i32 @close(i32 %35)
%37 = load i32, i32* @F_DUPFD
%38 = load i32, i32* @STDOUT_FILENO
%39 = tail call i32 @fcntl(i32 %34, i32 %37, i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %47, label %50
41: ; preds = %26
%42 = load i8*, i8** %13
%43 = tail call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %42)
%44 = load i8*, i8** %1
%45 = tail call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i8* %44)
%46 = tail call i32 @exit(i32 1)
unreachable
47: ; preds = %30, %17
%48 = phi i32 [ %19, %17 ], [ %34, %30 ]
%49 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %47, %30, %17
%51 = phi i32 [ %19, %17 ], [ %34, %30 ], [ %48, %47 ]
%52 = tail call i64 @execlp(i8* %10, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i32* null)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%56 = tail call i32 @exit(i32 -1)
unreachable
57: ; preds = %50
%58 = tail call i32 @close(i32 %51)
ret i32 0
}