#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 */
typedef int /*<<< orphan*/ time_t;
typedef int pid_t;
typedef int mode_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int S_IRGRP;
int S_IRUSR;
int S_IWGRP;
int S_IWUSR;
int /*<<< orphan*/ asctime(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dprintf(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ dup2(int, int);
int execv(char *, char **);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
int open(char *, int, int);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ waitpid(int, int *, int);
int useLs() {
  FILE *fp;
  fp = fopen("/tmp/1.txt", "w");
  fprintf(fp, "a\n");
  fprintf(fp, "d\n");
  fprintf(fp, "c\n");
  fprintf(fp, "e\n");
  fprintf(fp, "f\n");
  fprintf(fp, "b\n");
  fprintf(fp, "z\n");
  fprintf(fp, "h\n");
  fclose(fp);
  enum PIPES { READ, WRITE };
  mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
  int fd = open("/tmp/resultFile.txt", O_RDWR | O_CREAT, mode);
  int filedes[2];
  int filedes2[2];
  int filedes3[2];
  pipe(filedes);
  pipe(filedes2);
  pipe(filedes3);
  pid_t pid = fork();
  if (pid == 0) {
    dup2(filedes[WRITE], 1);
    char *argv[] = {"cat", "/tmp/1.txt", NULL};
    int result = execv("/bin/cat", argv);
    printf("proc %d, if CAT file result = %d\n", result, pid);
  } else {
    close(filedes[1]);
    printf("proc %d, if ELSE CAT file\n", pid);
  }
  pid_t pid2 = fork();
  if (pid2 == 0) {
    dup2(filedes[READ], 0);
    dup2(filedes2[WRITE], 1);
    char *argv[] = {"fakemap.sh", "-c", NULL};
    int result = execv("/home/utnso/Documentos/fakemap.sh", argv);
    printf("proc %d, if MAP file result = %d\n", result, pid2);
  } else {
    close(filedes2[1]);
    printf("proc %d, if ELSE MAP file\n", pid2);
  }
  pid_t pid3 = fork();
  if (pid3 == 0) {
    dup2(filedes2[READ], 0);
    dup2(filedes3[WRITE], 1);
    char *argv1[] = {"sort", NULL};
    int result = execv("/usr/bin/sort", argv1);
    printf("proc %d, if SORT file result = %d\n", result, pid3);
  } else {
    close(filedes3[1]);
    printf("proc %d, if ELSE SORT file\n", pid3);
  }
  pid_t pid4 = fork();
  if (pid4 == 0) {
    dup2(filedes3[READ], 0);
    dup2(fd, 1);
    char *argv1[] = {"fakereduce.sh", NULL};
    int result = execv("/home/utnso/Documentos/fakereduce.sh", argv1);
    printf("proc %d, if REDUCE file result = %d\n", result, pid4);
  } else {
    printf("proc %d, if ELSE REDUCE file\n", pid4);
  }
  waitpid(pid, (int *)NULL, (int)NULL);
  waitpid(pid2, (int *)NULL, (int)NULL);
  waitpid(pid3, (int *)NULL, (int)NULL);
  time_t now = time(NULL);
  dprintf(fd, "%s\n", asctime(localtime(&now)));
  close(fd);
  close(filedes3[0]);
  close(filedes3[1]);
  close(filedes[0]);
  close(filedes[1]);
  close(filedes2[0]);
  close(filedes2[1]);
  printf("closing\n");
  return 0;
}


x86 assembly (clang, -O0):
<useLs>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
lea    0xdfe(%rip),%rdi
lea    0xe02(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xf42(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xdd3(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xf40(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xdb6(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xda9(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xd9c(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xd8f(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%eax
mov    0x2d25(%rip),%rcx
or     (%rcx),%eax
mov    0x2d0c(%rip),%rcx
or     (%rcx),%eax
mov    0x2d1b(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0xc(%rbp)
mov    0x2d17(%rip),%rax
mov    (%rax),%esi
mov    0x2d26(%rip),%rax
or     (%rax),%esi
mov    -0xc(%rbp),%edx
lea    0xd41(%rip),%rdi
call   10e0 <open@plt>
mov    %eax,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   10a0 <pipe@plt>
lea    -0x20(%rbp),%rdi
call   10a0 <pipe@plt>
lea    -0x28(%rbp),%rdi
call   10a0 <pipe@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    136f <useLs+0x17f>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1060 <dup2@plt>
mov    0x2a67(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0x2a64(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0x2a61(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    -0x50(%rbp),%rsi
lea    0xce5(%rip),%rdi
call   1100 <execv@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%esi
mov    -0x2c(%rbp),%edx
lea    0xcd9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1388 <useLs+0x198>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    -0x2c(%rbp),%esi
lea    0xcdd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x58(%rbp)
jne    1400 <useLs+0x210>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   1060 <dup2@plt>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1060 <dup2@plt>
mov    0x29f6(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0x29f3(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    0x29f0(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    -0x70(%rbp),%rsi
lea    0xc9d(%rip),%rdi
call   1100 <execv@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%esi
mov    -0x58(%rbp),%edx
lea    0xcaa(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1419 <useLs+0x229>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    -0x58(%rbp),%esi
lea    0xcae(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %eax,-0x78(%rbp)
cmpl   $0x0,-0x78(%rbp)
jne    1495 <useLs+0x2a5>
mov    -0x20(%rbp),%edi
xor    %esi,%esi
call   1060 <dup2@plt>
mov    -0x24(%rbp),%edi
mov    $0x1,%esi
call   1060 <dup2@plt>
mov    0x2985(%rip),%rax
mov    %rax,-0x90(%rbp)
mov    0x297f(%rip),%rax
mov    %rax,-0x88(%rbp)
lea    -0x90(%rbp),%rsi
lea    0xc6d(%rip),%rdi
call   1100 <execv@plt>
mov    %eax,-0x94(%rbp)
mov    -0x94(%rbp),%esi
mov    -0x78(%rbp),%edx
lea    0xc60(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14ae <useLs+0x2be>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
mov    -0x78(%rbp),%esi
lea    0xc65(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %eax,-0x98(%rbp)
cmpl   $0x0,-0x98(%rbp)
jne    1533 <useLs+0x343>
mov    -0x28(%rbp),%edi
xor    %esi,%esi
call   1060 <dup2@plt>
mov    -0x10(%rbp),%edi
mov    $0x1,%esi
call   1060 <dup2@plt>
mov    0x28fa(%rip),%rax
mov    %rax,-0xb0(%rbp)
mov    0x28f4(%rip),%rax
mov    %rax,-0xa8(%rbp)
lea    -0xb0(%rbp),%rsi
lea    0xc1f(%rip),%rdi
call   1100 <execv@plt>
mov    %eax,-0xb4(%rbp)
mov    -0xb4(%rbp),%esi
mov    -0x98(%rbp),%edx
lea    0xc26(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1547 <useLs+0x357>
mov    -0x98(%rbp),%esi
lea    0xc32(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x2c(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10d0 <waitpid@plt>
mov    -0x58(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10d0 <waitpid@plt>
mov    -0x78(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10d0 <waitpid@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,-0xb8(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0xbc(%rbp)
lea    -0xb8(%rbp),%rdi
call   1030 <localtime@plt>
mov    %eax,%edi
call   1050 <asctime@plt>
mov    -0xbc(%rbp),%edi
mov    %eax,%edx
lea    0xbe5(%rip),%rsi
call   1090 <dprintf@plt>
mov    -0x10(%rbp),%edi
call   1080 <close@plt>
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
lea    0xba5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<useLs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    0xdef(%rip),%rdi
lea    0xdf3(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,%rbx
lea    0xde6(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1100 <fwrite@plt>
lea    0xf2f(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1100 <fwrite@plt>
lea    0xdb7(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1100 <fwrite@plt>
lea    0xf1b(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1100 <fwrite@plt>
lea    0xd88(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1100 <fwrite@plt>
lea    0xd72(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1100 <fwrite@plt>
lea    0xd5c(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1100 <fwrite@plt>
lea    0xd46(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1100 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x2cc1(%rip),%rax
mov    0x2cd2(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2cb7(%rip),%rax
or     (%rax),%edx
mov    0x2cc6(%rip),%rax
or     (%rax),%edx
mov    0x2cc5(%rip),%rax
mov    0x2cd6(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xcf2(%rip),%rdi
call   10e0 <open@plt>
mov    %eax,%r14d
lea    0x18(%rsp),%rdi
call   10b0 <pipe@plt>
lea    0x10(%rsp),%rdi
call   10b0 <pipe@plt>
lea    0x8(%rsp),%rdi
call   10b0 <pipe@plt>
xor    %eax,%eax
call   1120 <fork@plt>
mov    %eax,%r15d
mov    0x1c(%rsp),%edi
test   %eax,%eax
je     137d <useLs+0x17d>
call   1090 <close@plt>
lea    0xced(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    13c2 <useLs+0x1c2>
mov    $0x1,%esi
call   1070 <dup2@plt>
mov    0x2a12(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0x29f6(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0xc8d(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1110 <execv@plt>
lea    0xc85(%rip),%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
call   1120 <fork@plt>
mov    %eax,%ebx
test   %eax,%eax
je     13ea <useLs+0x1ea>
mov    0x14(%rsp),%edi
call   1090 <close@plt>
lea    0xce1(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    143e <useLs+0x23e>
mov    0x18(%rsp),%edi
xor    %esi,%esi
call   1070 <dup2@plt>
mov    0x14(%rsp),%edi
mov    $0x1,%esi
call   1070 <dup2@plt>
mov    0x29b6(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0x299a(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0xc5a(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1110 <execv@plt>
lea    0xc6b(%rip),%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
call   1120 <fork@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1466 <useLs+0x266>
mov    0xc(%rsp),%edi
call   1090 <close@plt>
lea    0xcb1(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    14ae <useLs+0x2ae>
mov    0x10(%rsp),%edi
xor    %esi,%esi
call   1070 <dup2@plt>
mov    0xc(%rsp),%edi
mov    $0x1,%esi
call   1070 <dup2@plt>
movaps 0x294a(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0xc49(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1110 <execv@plt>
lea    0xc46(%rip),%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
call   1120 <fork@plt>
test   %eax,%eax
je     14cb <useLs+0x2cb>
lea    0xcb2(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1512 <useLs+0x312>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1070 <dup2@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   1070 <dup2@plt>
movaps 0x28f6(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0xc32(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1110 <execv@plt>
lea    0xc46(%rip),%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <waitpid@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <waitpid@plt>
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <waitpid@plt>
xor    %edi,%edi
call   10c0 <time@plt>
mov    %eax,0x20(%rsp)
lea    0x20(%rsp),%rdi
call   1030 <localtime@plt>
mov    %eax,%edi
call   1060 <asctime@plt>
lea    0xc39(%rip),%rsi
mov    %r14d,%edi
mov    %eax,%edx
call   10a0 <dprintf@plt>
mov    %r14d,%edi
call   1090 <close@plt>
mov    0x8(%rsp),%edi
call   1090 <close@plt>
mov    0xc(%rsp),%edi
call   1090 <close@plt>
mov    0x18(%rsp),%edi
call   1090 <close@plt>
mov    0x1c(%rsp),%edi
call   1090 <close@plt>
mov    0x10(%rsp),%edi
call   1090 <close@plt>
mov    0x14(%rsp),%edi
call   1090 <close@plt>
lea    0xbee(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/tmp/1.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"a\0A\00"
@.str.3 = [3 x i8] c"d\0A\00"
@.str.4 = [3 x i8] c"c\0A\00"
@.str.5 = [3 x i8] c"e\0A\00"
@.str.6 = [3 x i8] c"f\0A\00"
@.str.7 = [3 x i8] c"b\0A\00"
@.str.8 = [3 x i8] c"z\0A\00"
@.str.9 = [3 x i8] c"h\0A\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@.str.10 = [20 x i8] c"/tmp/resultFile.txt\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.11 = [4 x i8] c"cat\00"
@__const.useLs.argv = [3 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.12 = [9 x i8] c"/bin/cat\00"
@.str.13 = [34 x i8] c"proc %d, if CAT file result = %d\0A\00"
@.str.14 = [27 x i8] c"proc %d, if ELSE CAT file\0A\00"
@.str.15 = [11 x i8] c"fakemap.sh\00"
@.str.16 = [3 x i8] c"-c\00"
@__const.useLs.argv.17 = [3 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i32 0, i32 0), i8* null]
@.str.18 = [34 x i8] c"/home/utnso/Documentos/fakemap.sh\00"
@.str.19 = [34 x i8] c"proc %d, if MAP file result = %d\0A\00"
@.str.20 = [27 x i8] c"proc %d, if ELSE MAP file\0A\00"
@.str.21 = [5 x i8] c"sort\00"
@__const.useLs.argv1 = [2 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.21, i32 0, i32 0), i8* null]
@.str.22 = [14 x i8] c"/usr/bin/sort\00"
@.str.23 = [35 x i8] c"proc %d, if SORT file result = %d\0A\00"
@.str.24 = [28 x i8] c"proc %d, if ELSE SORT file\0A\00"
@.str.25 = [14 x i8] c"fakereduce.sh\00"
@__const.useLs.argv1.26 = [2 x i8*] [i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.25, i32 0, i32 0), i8* null]
@.str.27 = [37 x i8] c"/home/utnso/Documentos/fakereduce.sh\00"
@.str.28 = [37 x i8] c"proc %d, if REDUCE file result = %d\0A\00"
@.str.29 = [30 x i8] c"proc %d, if ELSE REDUCE file\0A\00"
@.str.30 = [4 x i8] c"%s\0A\00"
@.str.31 = [9 x i8] c"closing\0A\00"
define i32 @useLs() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x i32]
%5 = alloca [2 x i32]
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca [3 x i8*]
%9 = alloca i32
%10 = alloca i32
%11 = alloca [3 x i8*]
%12 = alloca i32
%13 = alloca i32
%14 = alloca [2 x i8*]
%15 = alloca i32
%16 = alloca i32
%17 = alloca [2 x i8*]
%18 = alloca i32
%19 = alloca i32
%20 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %1
%21 = load i32*, i32** %1
%22 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32*, i32** %1
%24 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32*, i32** %1
%26 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%27 = load i32*, i32** %1
%28 = call i32 @fprintf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%29 = load i32*, i32** %1
%30 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%31 = load i32*, i32** %1
%32 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%33 = load i32*, i32** %1
%34 = call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%35 = load i32*, i32** %1
%36 = call i32 @fprintf(i32* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%37 = load i32*, i32** %1
%38 = call i32 @fclose(i32* %37)
%39 = load i32, i32* @S_IRUSR
%40 = load i32, i32* @S_IWUSR
%41 = or i32 %39, %40
%42 = load i32, i32* @S_IRGRP
%43 = or i32 %41, %42
%44 = load i32, i32* @S_IWGRP
%45 = or i32 %43, %44
store i32 %45, i32* %2
%46 = load i32, i32* @O_RDWR
%47 = load i32, i32* @O_CREAT
%48 = or i32 %46, %47
%49 = load i32, i32* %2
%50 = call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i32 %48, i32 %49)
store i32 %50, i32* %3
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%52 = call i32 @pipe(i32* %51)
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%54 = call i32 @pipe(i32* %53)
%55 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%56 = call i32 @pipe(i32* %55)
%57 = call i32 (...) @fork()
store i32 %57, i32* %7
%58 = load i32, i32* %7
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %70
60: ; preds = %0
%61 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%62 = load i32, i32* %61
%63 = call i32 @dup2(i32 %62, i32 1)
%64 = bitcast [3 x i8*]* %8 to i8*
%65 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
%66 = call i32 @execv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8** %65)
store i32 %66, i32* %9
%67 = load i32, i32* %9
%68 = load i32, i32* %7
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.13, i64 0, i64 0), i32 %67, i32 %68)
br label %76
70: ; preds = %0
%71 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%72 = load i32, i32* %71
%73 = call i32 @close(i32 %72)
%74 = load i32, i32* %7
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %70, %60
%77 = call i32 (...) @fork()
store i32 %77, i32* %10
%78 = load i32, i32* %10
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %93
80: ; preds = %76
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%82 = load i32, i32* %81
%83 = call i32 @dup2(i32 %82, i32 0)
%84 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%85 = load i32, i32* %84
%86 = call i32 @dup2(i32 %85, i32 1)
%87 = bitcast [3 x i8*]* %11 to i8*
%88 = getelementptr inbounds [3 x i8*], [3 x i8*]* %11, i64 0, i64 0
%89 = call i32 @execv(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.18, i64 0, i64 0), i8** %88)
store i32 %89, i32* %12
%90 = load i32, i32* %12
%91 = load i32, i32* %10
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.19, i64 0, i64 0), i32 %90, i32 %91)
br label %99
93: ; preds = %76
%94 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%95 = load i32, i32* %94
%96 = call i32 @close(i32 %95)
%97 = load i32, i32* %10
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.20, i64 0, i64 0), i32 %97)
br label %99
99: ; preds = %93, %80
%100 = call i32 (...) @fork()
store i32 %100, i32* %13
%101 = load i32, i32* %13
%102 = icmp eq i32 %101, 0
br i1 %102, label %103, label %116
103: ; preds = %99
%104 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%105 = load i32, i32* %104
%106 = call i32 @dup2(i32 %105, i32 0)
%107 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%108 = load i32, i32* %107
%109 = call i32 @dup2(i32 %108, i32 1)
%110 = bitcast [2 x i8*]* %14 to i8*
%111 = getelementptr inbounds [2 x i8*], [2 x i8*]* %14, i64 0, i64 0
%112 = call i32 @execv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.22, i64 0, i64 0), i8** %111)
store i32 %112, i32* %15
%113 = load i32, i32* %15
%114 = load i32, i32* %13
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.23, i64 0, i64 0), i32 %113, i32 %114)
br label %122
116: ; preds = %99
%117 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%118 = load i32, i32* %117
%119 = call i32 @close(i32 %118)
%120 = load i32, i32* %13
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.24, i64 0, i64 0), i32 %120)
br label %122
122: ; preds = %116, %103
%123 = call i32 (...) @fork()
store i32 %123, i32* %16
%124 = load i32, i32* %16
%125 = icmp eq i32 %124, 0
br i1 %125, label %126, label %138
126: ; preds = %122
%127 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%128 = load i32, i32* %127
%129 = call i32 @dup2(i32 %128, i32 0)
%130 = load i32, i32* %3
%131 = call i32 @dup2(i32 %130, i32 1)
%132 = bitcast [2 x i8*]* %17 to i8*
%133 = getelementptr inbounds [2 x i8*], [2 x i8*]* %17, i64 0, i64 0
%134 = call i32 @execv(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.27, i64 0, i64 0), i8** %133)
store i32 %134, i32* %18
%135 = load i32, i32* %18
%136 = load i32, i32* %16
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.28, i64 0, i64 0), i32 %135, i32 %136)
br label %141
138: ; preds = %122
%139 = load i32, i32* %16
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.29, i64 0, i64 0), i32 %139)
br label %141
141: ; preds = %138, %126
%142 = load i32, i32* %7
%143 = call i32 @waitpid(i32 %142, i32* null, i32 0)
%144 = load i32, i32* %10
%145 = call i32 @waitpid(i32 %144, i32* null, i32 0)
%146 = load i32, i32* %13
%147 = call i32 @waitpid(i32 %146, i32* null, i32 0)
%148 = call i32 @time(i32* null)
store i32 %148, i32* %19
%149 = load i32, i32* %3
%150 = call i32 @localtime(i32* %19)
%151 = call i32 @asctime(i32 %150)
%152 = call i32 @dprintf(i32 %149, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.30, i64 0, i64 0), i32 %151)
%153 = load i32, i32* %3
%154 = call i32 @close(i32 %153)
%155 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%156 = load i32, i32* %155
%157 = call i32 @close(i32 %156)
%158 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%159 = load i32, i32* %158
%160 = call i32 @close(i32 %159)
%161 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%162 = load i32, i32* %161
%163 = call i32 @close(i32 %162)
%164 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%165 = load i32, i32* %164
%166 = call i32 @close(i32 %165)
%167 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%168 = load i32, i32* %167
%169 = call i32 @close(i32 %168)
%170 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%171 = load i32, i32* %170
%172 = call i32 @close(i32 %171)
%173 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.31, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"/tmp/1.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"a\0A\00"
@.str.3 = [3 x i8] c"d\0A\00"
@.str.4 = [3 x i8] c"c\0A\00"
@.str.5 = [3 x i8] c"e\0A\00"
@.str.6 = [3 x i8] c"f\0A\00"
@.str.7 = [3 x i8] c"b\0A\00"
@.str.8 = [3 x i8] c"z\0A\00"
@.str.9 = [3 x i8] c"h\0A\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@.str.10 = [20 x i8] c"/tmp/resultFile.txt\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.11 = [4 x i8] c"cat\00"
@__const.useLs.argv = [3 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.12 = [9 x i8] c"/bin/cat\00"
@.str.13 = [34 x i8] c"proc %d, if CAT file result = %d\0A\00"
@.str.14 = [27 x i8] c"proc %d, if ELSE CAT file\0A\00"
@.str.15 = [11 x i8] c"fakemap.sh\00"
@.str.16 = [3 x i8] c"-c\00"
@__const.useLs.argv.17 = [3 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i32 0, i32 0), i8* null]
@.str.18 = [34 x i8] c"/home/utnso/Documentos/fakemap.sh\00"
@.str.19 = [34 x i8] c"proc %d, if MAP file result = %d\0A\00"
@.str.20 = [27 x i8] c"proc %d, if ELSE MAP file\0A\00"
@.str.21 = [5 x i8] c"sort\00"
@__const.useLs.argv1 = [2 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.21, i32 0, i32 0), i8* null]
@.str.22 = [14 x i8] c"/usr/bin/sort\00"
@.str.23 = [35 x i8] c"proc %d, if SORT file result = %d\0A\00"
@.str.24 = [28 x i8] c"proc %d, if ELSE SORT file\0A\00"
@.str.25 = [14 x i8] c"fakereduce.sh\00"
@__const.useLs.argv1.26 = [2 x i8*] [i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.25, i32 0, i32 0), i8* null]
@.str.27 = [37 x i8] c"/home/utnso/Documentos/fakereduce.sh\00"
@.str.28 = [37 x i8] c"proc %d, if REDUCE file result = %d\0A\00"
@.str.29 = [30 x i8] c"proc %d, if ELSE REDUCE file\0A\00"
@.str.30 = [4 x i8] c"%s\0A\00"
@str = [8 x i8] c"closing\00"
define i32 @useLs() {
%1 = alloca [2 x i32]
%2 = alloca [2 x i32]
%3 = alloca [2 x i32]
%4 = alloca [3 x i8*]
%5 = alloca [3 x i8*]
%6 = alloca [2 x i8*]
%7 = alloca [2 x i8*]
%8 = alloca i32
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 2, i64 1, i32* %9)
%11 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 2, i64 1, i32* %9)
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 2, i64 1, i32* %9)
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64 2, i64 1, i32* %9)
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i64 2, i64 1, i32* %9)
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i64 2, i64 1, i32* %9)
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i64 2, i64 1, i32* %9)
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i64 2, i64 1, i32* %9)
%18 = tail call i32 @fclose(i32* %9)
%19 = load i32, i32* @S_IRUSR
%20 = load i32, i32* @S_IWUSR
%21 = or i32 %20, %19
%22 = load i32, i32* @S_IRGRP
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IWGRP
%25 = or i32 %23, %24
%26 = load i32, i32* @O_RDWR
%27 = load i32, i32* @O_CREAT
%28 = or i32 %27, %26
%29 = tail call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i32 %28, i32 %25)
%30 = bitcast [2 x i32]* %1 to i8*
%31 = bitcast [2 x i32]* %2 to i8*
%32 = bitcast [2 x i32]* %3 to i8*
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%34 = call i32 @pipe(i32* %33)
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%36 = call i32 @pipe(i32* %35)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%38 = call i32 @pipe(i32* %37)
%39 = call i32 (...) @fork()
%40 = icmp eq i32 %39, 0
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%42 = load i32, i32* %41
br i1 %40, label %43, label %49
43: ; preds = %0
%44 = call i32 @dup2(i32 %42, i32 1)
%45 = bitcast [3 x i8*]* %4 to i8*
%46 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%47 = call i32 @execv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8** %46)
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.13, i64 0, i64 0), i32 %47, i32 0)
br label %52
49: ; preds = %0
%50 = call i32 @close(i32 %42)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i32 %39)
br label %52
52: ; preds = %49, %43
%53 = call i32 (...) @fork()
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %65
55: ; preds = %52
%56 = load i32, i32* %33
%57 = call i32 @dup2(i32 %56, i32 0)
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%59 = load i32, i32* %58
%60 = call i32 @dup2(i32 %59, i32 1)
%61 = bitcast [3 x i8*]* %5 to i8*
%62 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
%63 = call i32 @execv(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.18, i64 0, i64 0), i8** %62)
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.19, i64 0, i64 0), i32 %63, i32 0)
br label %70
65: ; preds = %52
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%67 = load i32, i32* %66
%68 = call i32 @close(i32 %67)
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.20, i64 0, i64 0), i32 %53)
br label %70
70: ; preds = %65, %55
%71 = call i32 (...) @fork()
%72 = icmp eq i32 %71, 0
br i1 %72, label %73, label %83
73: ; preds = %70
%74 = load i32, i32* %35
%75 = call i32 @dup2(i32 %74, i32 0)
%76 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%77 = load i32, i32* %76
%78 = call i32 @dup2(i32 %77, i32 1)
%79 = bitcast [2 x i8*]* %6 to i8*
%80 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
%81 = call i32 @execv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.22, i64 0, i64 0), i8** %80)
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.23, i64 0, i64 0), i32 %81, i32 0)
br label %88
83: ; preds = %70
%84 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%85 = load i32, i32* %84
%86 = call i32 @close(i32 %85)
%87 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.24, i64 0, i64 0), i32 %71)
br label %88
88: ; preds = %83, %73
%89 = call i32 (...) @fork()
%90 = icmp eq i32 %89, 0
br i1 %90, label %91, label %99
91: ; preds = %88
%92 = load i32, i32* %37
%93 = call i32 @dup2(i32 %92, i32 0)
%94 = call i32 @dup2(i32 %29, i32 1)
%95 = bitcast [2 x i8*]* %7 to i8*
%96 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%97 = call i32 @execv(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.27, i64 0, i64 0), i8** %96)
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.28, i64 0, i64 0), i32 %97, i32 0)
br label %101
99: ; preds = %88
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.29, i64 0, i64 0), i32 %89)
br label %101
101: ; preds = %99, %91
%102 = call i32 @waitpid(i32 %39, i32* null, i32 0)
%103 = call i32 @waitpid(i32 %53, i32* null, i32 0)
%104 = call i32 @waitpid(i32 %71, i32* null, i32 0)
%105 = bitcast i32* %8 to i8*
%106 = call i32 @time(i32* null)
store i32 %106, i32* %8
%107 = call i32 @localtime(i32* %8)
%108 = call i32 @asctime(i32 %107)
%109 = call i32 @dprintf(i32 %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.30, i64 0, i64 0), i32 %108)
%110 = call i32 @close(i32 %29)
%111 = load i32, i32* %37
%112 = call i32 @close(i32 %111)
%113 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%114 = load i32, i32* %113
%115 = call i32 @close(i32 %114)
%116 = load i32, i32* %33
%117 = call i32 @close(i32 %116)
%118 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%119 = load i32, i32* %118
%120 = call i32 @close(i32 %119)
%121 = load i32, i32* %35
%122 = call i32 @close(i32 %121)
%123 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%124 = load i32, i32* %123
%125 = call i32 @close(i32 %124)
%126 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
ret i32 0
}