#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 */
char EOF;
char fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ *stdout;
void tee(FILE **out_files, int *num_files) {
  char c;
  int i;
  while (1) {
    c = fgetc(stdin);
    if (c == EOF) {
      break;
    }
    fprintf(stdout, "%c", c);
    for (i = 0; i < *num_files; ++i) {
      if (out_files[i] != NULL) {
        fprintf(out_files[i], "%c", c);
      }
    }
  }
}


x86 assembly (clang, -O0):
<tee>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2eb1(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
mov    0x2e94(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    115c <tee+0x3c>
jmp    11d3 <tee+0xb3>
mov    0x2e6d(%rip),%rax
mov    (%rax),%rdi
lea    0xe93(%rip),%rsi
movsbl -0x11(%rbp),%edx
call   1040 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    11ce <tee+0xae>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11bb <tee+0x9b>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe4e(%rip),%rsi
movsbl -0x11(%rbp),%edx
call   1040 <fprintf@plt>
jmp    11c0 <tee+0xa0>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117d <tee+0x5d>
jmp    1130 <tee+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tee>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2eb0(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
mov    0x2e9a(%rip),%r12
cmp    (%r12),%al
jne    115b <tee+0x3b>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e6e(%rip),%r13
jmp    1184 <tee+0x64>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
cmp    (%r12),%al
je     114c <tee+0x2c>
mov    0x0(%r13),%rsi
movsbl %al,%ebp
mov    %ebp,%edi
call   1040 <fputc@plt>
mov    (%r14),%eax
test   %eax,%eax
jle    1170 <tee+0x50>
xor    %r15d,%r15d
jmp    11ac <tee+0x8c>
xchg   %ax,%ax
add    $0x1,%r15
movslq %eax,%rcx
cmp    %rcx,%r15
jge    1170 <tee+0x50>
mov    (%rbx,%r15,8),%rsi
test   %rsi,%rsi
je     11a0 <tee+0x80>
mov    %ebp,%edi
call   1040 <fputc@plt>
mov    (%r14),%eax
jmp    11a0 <tee+0x80>

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i8 0
@stdout = global i32* null
@.str = [3 x i8] c"%c\00"
define void @tee(i32** %0, i32* %1) {
%3 = alloca i32**
%4 = alloca i32*
%5 = alloca i8
%6 = alloca i32
store i32** %0, i32*** %3
store i32* %1, i32** %4
br label %7
7: ; preds = %2, %44
%8 = load i32, i32* @stdin
%9 = call signext i8 @fgetc(i32 %8)
store i8 %9, i8* %5
%10 = load i8, i8* %5
%11 = sext i8 %10 to i32
%12 = load i8, i8* @EOF
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %11, %13
br i1 %14, label %15, label %16
15: ; preds = %7
br label %45
16: ; preds = %7
%17 = load i32*, i32** @stdout
%18 = load i8, i8* %5
%19 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %18)
store i32 0, i32* %6
br label %20
20: ; preds = %41, %16
%21 = load i32, i32* %6
%22 = load i32*, i32** %4
%23 = load i32, i32* %22
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %44
25: ; preds = %20
%26 = load i32**, i32*** %3
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32*, i32** %26, i64 %28
%30 = load i32*, i32** %29
%31 = icmp ne i32* %30, null
br i1 %31, label %32, label %40
32: ; preds = %25
%33 = load i32**, i32*** %3
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32*, i32** %33, i64 %35
%37 = load i32*, i32** %36
%38 = load i8, i8* %5
%39 = call i32 @fprintf(i32* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %38)
br label %40
40: ; preds = %32, %25
br label %41
41: ; preds = %40
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %20
44: ; preds = %20
br label %7
45: ; preds = %15
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i8 0
@stdout = global i32* null
define void @tee(i32** nocapture %0, i32* nocapture %1) {
%3 = load i32, i32* @stdin
%4 = tail call signext i8 @fgetc(i32 %3)
%5 = load i8, i8* @EOF
%6 = icmp eq i8 %4, %5
br i1 %6, label %33, label %12
7: ; preds = %28, %12
%8 = load i32, i32* @stdin
%9 = tail call signext i8 @fgetc(i32 %8)
%10 = load i8, i8* @EOF
%11 = icmp eq i8 %9, %10
br i1 %11, label %33, label %12
12: ; preds = %2, %7
%13 = phi i8 [ %9, %7 ], [ %4, %2 ]
%14 = load i32*, i32** @stdout
%15 = sext i8 %13 to i32
%16 = tail call i32 @fputc(i32 %15, i32* %14)
%17 = load i32, i32* %1
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %7
19: ; preds = %12, %28
%20 = phi i32 [ %29, %28 ], [ %17, %12 ]
%21 = phi i64 [ %30, %28 ], [ 0, %12 ]
%22 = getelementptr inbounds i32*, i32** %0, i64 %21
%23 = load i32*, i32** %22
%24 = icmp eq i32* %23, null
br i1 %24, label %28, label %25
25: ; preds = %19
%26 = tail call i32 @fputc(i32 %15, i32* %23)
%27 = load i32, i32* %1
br label %28
28: ; preds = %19, %25
%29 = phi i32 [ %20, %19 ], [ %27, %25 ]
%30 = add nuw nsw i64 %21, 1
%31 = sext i32 %29 to i64
%32 = icmp slt i64 %30, %31
br i1 %32, label %19, label %7
33: ; preds = %7, %2
ret void
}