#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*/ FILE;

/* Variables and functions */
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ printf(char *, int, int);
int main(int argc, char **argv) {
  FILE *f[6];
  int i = 0;
  for (i = 0; i < 3; i++)
    f[i] = fopen("/dev/tty", "r");
  for (i = 3; i < 6; i++)
    f[i] = fopen("/dev/tty", "w");
  for (i = 0; i < 6; i++)
    printf("File descriptor f[%d]: %d\n", i, fileno(f[i]));
  for (i = 3; i < 6; i++)
    fprintf(f[i], "Mensaje dirijido al flujo nro %d\n", i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x3,-0x44(%rbp)
jge    119b <main+0x5b>
lea    0xe8b(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rcx
movslq -0x44(%rbp),%rax
mov    %rcx,-0x40(%rbp,%rax,8)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1164 <main+0x24>
movl   $0x3,-0x44(%rbp)
cmpl   $0x6,-0x44(%rbp)
jge    11d9 <main+0x99>
lea    0xe4d(%rip),%rdi
lea    0xe51(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rcx
movslq -0x44(%rbp),%rax
mov    %rcx,-0x40(%rbp,%rax,8)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11a2 <main+0x62>
movl   $0x0,-0x44(%rbp)
cmpl   $0x6,-0x44(%rbp)
jge    121d <main+0xdd>
mov    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
call   1050 <fileno@plt>
mov    -0x48(%rbp),%esi
mov    %eax,%edx
lea    0xe03(%rip),%rdi
call   1030 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11e0 <main+0xa0>
movl   $0x3,-0x44(%rbp)
cmpl   $0x6,-0x44(%rbp)
jge    1254 <main+0x114>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
mov    -0x44(%rbp),%edx
lea    0xde7(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1224 <main+0xe4>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeae(%rip),%rbx
lea    0xeb0(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <fopen@plt>
mov    %rax,%r13
lea    0xe81(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <fopen@plt>
mov    %rax,(%rsp)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <fileno@plt>
lea    0xe49(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %r15,%rdi
call   1050 <fileno@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %r13,%rdi
call   1050 <fileno@plt>
mov    %r14,%rdi
mov    $0x2,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %r12,%rdi
call   1050 <fileno@plt>
mov    %r14,%rdi
mov    $0x3,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    (%rsp),%rbp
mov    %rbp,%rdi
call   1050 <fileno@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1050 <fileno@plt>
mov    %r14,%rdi
mov    $0x5,%esi
mov    %eax,%edx
call   1030 <printf@plt>
lea    0xdda(%rip),%r14
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1040 <fprintf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/tty\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [27 x i8] c"File descriptor f[%d]: %d\0A\00"
@.str.4 = [34 x i8] c"Mensaje dirijido al flujo nro %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [6 x i32*]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %7
br label %8
8: ; preds = %16, %2
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* %7
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [6 x i32*], [6 x i32*]* %6, i64 0, i64 %14
store i32* %12, i32** %15
br label %16
16: ; preds = %11
%17 = load i32, i32* %7
%18 = add nsw i32 %17, 1
store i32 %18, i32* %7
br label %8
19: ; preds = %8
store i32 3, i32* %7
br label %20
20: ; preds = %28, %19
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 6
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [6 x i32*], [6 x i32*]* %6, i64 0, i64 %26
store i32* %24, i32** %27
br label %28
28: ; preds = %23
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %20
31: ; preds = %20
store i32 0, i32* %7
br label %32
32: ; preds = %43, %31
%33 = load i32, i32* %7
%34 = icmp slt i32 %33, 6
br i1 %34, label %35, label %46
35: ; preds = %32
%36 = load i32, i32* %7
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [6 x i32*], [6 x i32*]* %6, i64 0, i64 %38
%40 = load i32*, i32** %39
%41 = call i32 @fileno(i32* %40)
%42 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %36, i32 %41)
br label %43
43: ; preds = %35
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %32
46: ; preds = %32
store i32 3, i32* %7
br label %47
47: ; preds = %57, %46
%48 = load i32, i32* %7
%49 = icmp slt i32 %48, 6
br i1 %49, label %50, label %60
50: ; preds = %47
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [6 x i32*], [6 x i32*]* %6, i64 0, i64 %52
%54 = load i32*, i32** %53
%55 = load i32, i32* %7
%56 = call i32 @fprintf(i32* %54, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %50
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %47
60: ; preds = %47
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/tty\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [27 x i8] c"File descriptor f[%d]: %d\0A\00"
@.str.4 = [34 x i8] c"Mensaje dirijido al flujo nro %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @fileno(i32* %3)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 %9)
%11 = tail call i32 @fileno(i32* %4)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 %11)
%13 = tail call i32 @fileno(i32* %5)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 2, i32 %13)
%15 = tail call i32 @fileno(i32* %6)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 3, i32 %15)
%17 = tail call i32 @fileno(i32* %7)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 4, i32 %17)
%19 = tail call i32 @fileno(i32* %8)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 5, i32 %19)
%21 = tail call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 3)
%22 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 4)
%23 = tail call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 5)
ret i32 0
}