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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ dup2(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fread(int *, int, int, int /*<<< orphan*/ *);
int fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int read(int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ *tmpfile();
int write(int /*<<< orphan*/, int *, int);
int main(int argc, char **argv) {
  dup2(STDOUT_FILENO, STDERR_FILENO);
  int buf[1024];
  int numbytes;
  FILE *tmpFile = tmpfile();
  int orden = 0;
  numbytes = read(STDIN_FILENO, buf, sizeof(buf));
  if (numbytes == -1) {
    perror("Error en la lectura en del proxy.\n");
    exit(EXIT_FAILURE);
  }
  while (numbytes > 0) {
    if (fwrite(buf, sizeof(char), numbytes, tmpFile) == -1) {
      perror("Error en fwrite la escritura del proxy1\n");
      exit(EXIT_FAILURE);
    }
    numbytes = read(STDIN_FILENO, buf, sizeof(buf));
    if (numbytes == -1) {
      perror("Error en la lectura en del proxy2\n");
      exit(EXIT_FAILURE);
    }
  }
  if (numbytes == 0) {
    numbytes = fread(buf, sizeof(char), sizeof(buf), tmpFile);
    if (numbytes == -1) {
      perror("Error en fread la lectura en del proxy.\n");
      exit(EXIT_FAILURE);
    }
    while (numbytes > 0) {
      if (write(STDOUT_FILENO, buf, numbytes) == -1) {
        perror("Error en la escritura del proxy1\n");
        exit(EXIT_FAILURE);
      }
      numbytes = fread(buf, sizeof(char), sizeof(buf), tmpFile);
      if (numbytes == -1) {
        perror("Error en la fread lectura en del proxy2\n");
        exit(EXIT_FAILURE);
      }
      orden++;
    }
    if (numbytes == 0) {
      fclose(tmpFile);
      exit(EXIT_FAILURE);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
mov    $0x0,%al
call   1080 <tmpfile@plt>
mov    %rax,-0x1020(%rbp)
movl   $0x0,-0x1024(%rbp)
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0xffffffff,-0x1014(%rbp)
jne    121f <main+0x8f>
lea    0xdf4(%rip),%rdi
call   1090 <perror@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1224 <main+0x94>
cmpl   $0x0,-0x1014(%rbp)
jle    12be <main+0x12e>
lea    -0x1010(%rbp),%rdi
mov    -0x1014(%rbp),%edx
mov    -0x1020(%rbp),%rcx
mov    $0x1,%esi
call   10b0 <fwrite@plt>
cmp    $0xffffffff,%eax
jne    1272 <main+0xe2>
lea    0xdc4(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0xffffffff,-0x1014(%rbp)
jne    12b9 <main+0x129>
lea    0xda6(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1224 <main+0x94>
cmpl   $0x0,-0x1014(%rbp)
jne    13ef <main+0x25f>
lea    -0x1010(%rbp),%rdi
mov    -0x1020(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0xffffffff,-0x1014(%rbp)
jne    1315 <main+0x185>
lea    0xd6d(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    131a <main+0x18a>
cmpl   $0x0,-0x1014(%rbp)
jle    13c3 <main+0x233>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
lea    -0x1010(%rbp),%rsi
mov    -0x1014(%rbp),%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1365 <main+0x1d5>
lea    0xd46(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c72(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x1010(%rbp),%rdi
mov    -0x1020(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0xffffffff,-0x1014(%rbp)
jne    13af <main+0x21f>
lea    0xd1e(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c28(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x1024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1024(%rbp)
jmp    131a <main+0x18a>
cmpl   $0x0,-0x1014(%rbp)
jne    13ea <main+0x25a>
mov    -0x1020(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x2bed(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    13ef <main+0x25f>
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    0x2e4b(%rip),%r12
mov    (%r12),%edi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
xor    %eax,%eax
call   1080 <tmpfile@plt>
mov    %rax,%r15
mov    0x2e00(%rip),%r14
mov    (%r14),%edi
mov    %rsp,%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     12d0 <main+0x140>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %eax,%eax
jle    1230 <main+0xa0>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   10b0 <fwrite@plt>
cmp    $0xffffffff,%eax
je     12ad <main+0x11d>
mov    (%r14),%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
jne    11f0 <main+0x60>
lea    0xe21(%rip),%rdi
jmp    12bd <main+0x12d>
jne    129c <main+0x10c>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
cmp    $0xffffffff,%eax
je     12d9 <main+0x149>
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %eax,%eax
jle    129a <main+0x10a>
mov    (%r12),%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     12b6 <main+0x126>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
cmp    $0xffffffff,%eax
jne    1260 <main+0xd0>
lea    0xe22(%rip),%rdi
jmp    12bd <main+0x12d>
je     12e2 <main+0x152>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd6f(%rip),%rdi
jmp    12bd <main+0x12d>
lea    0xddb(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xd29(%rip),%rdi
jmp    12bd <main+0x12d>
lea    0xd8f(%rip),%rdi
jmp    12bd <main+0x12d>
mov    %r15,%rdi
call   1050 <fclose@plt>
jmp    12c2 <main+0x132>

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@STDIN_FILENO = global i32 0
@.str = [35 x i8] c"Error en la lectura en del proxy.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [41 x i8] c"Error en fwrite la escritura del proxy1\0A\00"
@.str.2 = [35 x i8] c"Error en la lectura en del proxy2\0A\00"
@.str.3 = [41 x i8] c"Error en fread la lectura en del proxy.\0A\00"
@.str.4 = [34 x i8] c"Error en la escritura del proxy1\0A\00"
@.str.5 = [41 x i8] c"Error en la fread lectura en del proxy2\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i32]
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @STDOUT_FILENO
%11 = load i32, i32* @STDERR_FILENO
%12 = call i32 @dup2(i32 %10, i32 %11)
%13 = call i32* (...) @tmpfile()
store i32* %13, i32** %8
store i32 0, i32* %9
%14 = load i32, i32* @STDIN_FILENO
%15 = getelementptr inbounds [1024 x i32], [1024 x i32]* %6, i64 0, i64 0
%16 = call i32 @read(i32 %14, i32* %15, i32 4096)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
br label %24
24: ; preds = %47, %23
%25 = load i32, i32* %7
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %48
27: ; preds = %24
%28 = getelementptr inbounds [1024 x i32], [1024 x i32]* %6, i64 0, i64 0
%29 = load i32, i32* %7
%30 = load i32*, i32** %8
%31 = call i32 @fwrite(i32* %28, i32 1, i32 %29, i32* %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %27
%34 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %27
%38 = load i32, i32* @STDIN_FILENO
%39 = getelementptr inbounds [1024 x i32], [1024 x i32]* %6, i64 0, i64 0
%40 = call i32 @read(i32 %38, i32* %39, i32 4096)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %47
43: ; preds = %37
%44 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %37
br label %24
48: ; preds = %24
%49 = load i32, i32* %7
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %97
51: ; preds = %48
%52 = getelementptr inbounds [1024 x i32], [1024 x i32]* %6, i64 0, i64 0
%53 = load i32*, i32** %8
%54 = call i32 @fread(i32* %52, i32 1, i32 4096, i32* %53)
store i32 %54, i32* %7
%55 = load i32, i32* %7
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %61
57: ; preds = %51
%58 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %51
br label %62
62: ; preds = %85, %61
%63 = load i32, i32* %7
%64 = icmp sgt i32 %63, 0
br i1 %64, label %65, label %88
65: ; preds = %62
%66 = load i32, i32* @STDOUT_FILENO
%67 = getelementptr inbounds [1024 x i32], [1024 x i32]* %6, i64 0, i64 0
%68 = load i32, i32* %7
%69 = call i32 @write(i32 %66, i32* %67, i32 %68)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %75
71: ; preds = %65
%72 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %65
%76 = getelementptr inbounds [1024 x i32], [1024 x i32]* %6, i64 0, i64 0
%77 = load i32*, i32** %8
%78 = call i32 @fread(i32* %76, i32 1, i32 4096, i32* %77)
store i32 %78, i32* %7
%79 = load i32, i32* %7
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %85
81: ; preds = %75
%82 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%83 = load i32, i32* @EXIT_FAILURE
%84 = call i32 @exit(i32 %83)
unreachable
85: ; preds = %75
%86 = load i32, i32* %9
%87 = add nsw i32 %86, 1
store i32 %87, i32* %9
br label %62
88: ; preds = %62
%89 = load i32, i32* %7
%90 = icmp eq i32 %89, 0
br i1 %90, label %91, label %96
91: ; preds = %88
%92 = load i32*, i32** %8
%93 = call i32 @fclose(i32* %92)
%94 = load i32, i32* @EXIT_FAILURE
%95 = call i32 @exit(i32 %94)
unreachable
96: ; preds = %88
br label %97
97: ; preds = %96, %48
%98 = load i32, i32* %3
ret i32 %98
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@STDIN_FILENO = global i32 0
@.str = [35 x i8] c"Error en la lectura en del proxy.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [41 x i8] c"Error en fwrite la escritura del proxy1\0A\00"
@.str.2 = [35 x i8] c"Error en la lectura en del proxy2\0A\00"
@.str.3 = [41 x i8] c"Error en fread la lectura en del proxy.\0A\00"
@.str.4 = [34 x i8] c"Error en la escritura del proxy1\0A\00"
@.str.5 = [41 x i8] c"Error en la fread lectura en del proxy2\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i32]
%4 = load i32, i32* @STDOUT_FILENO
%5 = load i32, i32* @STDERR_FILENO
%6 = tail call i32 @dup2(i32 %4, i32 %5)
%7 = bitcast [1024 x i32]* %3 to i8*
%8 = tail call i32* (...) @tmpfile()
%9 = load i32, i32* @STDIN_FILENO
%10 = getelementptr inbounds [1024 x i32], [1024 x i32]* %3, i64 0, i64 0
%11 = call i32 @read(i32 %9, i32* %10, i32 4096)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %2, %27
%18 = phi i32 [ %29, %27 ], [ %11, %2 ]
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %35
20: ; preds = %17
%21 = call i32 @fwrite(i32* %10, i32 1, i32 %18, i32* %8)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = tail call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @exit(i32 %25)
unreachable
27: ; preds = %20
%28 = load i32, i32* @STDIN_FILENO
%29 = call i32 @read(i32 %28, i32* %10, i32 4096)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %17
31: ; preds = %27
%32 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = tail call i32 @exit(i32 %33)
unreachable
35: ; preds = %17
%36 = icmp eq i32 %18, 0
br i1 %36, label %37, label %68
37: ; preds = %35
%38 = call i32 @fread(i32* %10, i32 1, i32 4096, i32* %8)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = tail call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = tail call i32 @exit(i32 %42)
unreachable
44: ; preds = %37, %55
%45 = phi i32 [ %56, %55 ], [ %38, %37 ]
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %62
47: ; preds = %44
%48 = load i32, i32* @STDOUT_FILENO
%49 = call i32 @write(i32 %48, i32* %10, i32 %45)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%53 = load i32, i32* @EXIT_FAILURE
%54 = tail call i32 @exit(i32 %53)
unreachable
55: ; preds = %47
%56 = call i32 @fread(i32* %10, i32 1, i32 4096, i32* %8)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %44
58: ; preds = %55
%59 = tail call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%60 = load i32, i32* @EXIT_FAILURE
%61 = tail call i32 @exit(i32 %60)
unreachable
62: ; preds = %44
%63 = icmp eq i32 %45, 0
br i1 %63, label %64, label %68
64: ; preds = %62
%65 = tail call i32 @fclose(i32* %8)
%66 = load i32, i32* @EXIT_FAILURE
%67 = tail call i32 @exit(i32 %66)
unreachable
68: ; preds = %62, %35
ret i32 0
}