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

/* Variables and functions */
int EXIT_SUCCESS;
int __fbufsize(int /*<<< orphan*/);
scalar_t__ __flbf(int /*<<< orphan*/);
int /*<<< orphan*/ fileno2FILE(int);
char *fileno2name(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/);
int isatty(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(void) {
  if (isatty(0)) {
    fprintf(stderr, "Hit Ctrl-d to initialise stdin\n");
  } else {
    fprintf(stderr, "Initialising stdin\n");
  }
  char data[4096];
  fread(data, sizeof(data), 1, stdin);
  if (isatty(1)) {
    fprintf(stdout, "Initialising stdout\n");
  } else {
    fprintf(stdout, "Initialising stdout\n");
    fprintf(stderr, "Initialising stdout\n");
  }
  fprintf(stderr, "Initialising stderr\n");
  int i;
  for (i = 0; i < 3; i++) {
    fprintf(stderr, "%6s: tty=%d, lb=%d, size=%d\n", fileno2name(i), isatty(i),
            __flbf(fileno2FILE(i)) ? 1 : 0, __fbufsize(fileno2FILE(i)));
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1030 <isatty@plt>
cmp    $0x0,%eax
je     11ae <main+0x3e>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    11c5 <main+0x55>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    -0x1010(%rbp),%rdi
mov    0x2e15(%rip),%rax
mov    (%rax),%ecx
mov    $0x1000,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
mov    $0x1,%edi
call   1030 <isatty@plt>
cmp    $0x0,%eax
je     1213 <main+0xa3>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1241 <main+0xd1>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x1014(%rbp)
cmpl   $0x3,-0x1014(%rbp)
jge    131b <main+0x1ab>
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x102c(%rbp)
mov    -0x1014(%rbp),%edi
call   1080 <fileno2name@plt>
mov    %rax,-0x1028(%rbp)
mov    -0x1014(%rbp),%edi
call   1030 <isatty@plt>
mov    %eax,-0x101c(%rbp)
mov    -0x1014(%rbp),%edi
call   1050 <fileno2FILE@plt>
mov    %eax,%edi
call   1060 <__flbf@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x1018(%rbp)
mov    -0x1014(%rbp),%edi
call   1050 <fileno2FILE@plt>
mov    %eax,%edi
call   1090 <__fbufsize@plt>
mov    -0x102c(%rbp),%edi
mov    -0x1028(%rbp),%rdx
mov    -0x101c(%rbp),%ecx
mov    -0x1018(%rbp),%r8d
mov    %eax,%r9d
lea    0xd5e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x1014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1014(%rbp)
jmp    1262 <main+0xf2>
mov    0x2ca6(%rip),%rax
mov    (%rax),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
xor    %edi,%edi
call   1030 <isatty@plt>
test   %eax,%eax
mov    0x2e47(%rip),%r13
mov    0x0(%r13),%edi
lea    0xe84(%rip),%rax
lea    0xe5d(%rip),%rsi
cmove  %rax,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
mov    $0x1,%edi
call   1030 <isatty@plt>
test   %eax,%eax
je     11e0 <main+0x70>
mov    0x2df2(%rip),%rax
jmp    11fa <main+0x8a>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r13,%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe34(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x0(%r13),%r15d
xor    %edi,%edi
call   1080 <fileno2name@plt>
mov    %rax,%r12
xor    %edi,%edi
call   1030 <isatty@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   1050 <fileno2FILE@plt>
mov    %eax,%edi
call   1060 <__flbf@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
xor    %edi,%edi
call   1050 <fileno2FILE@plt>
mov    %eax,%edi
call   1090 <__fbufsize@plt>
lea    0xe00(%rip),%r14
mov    %r15d,%edi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %ebp,%ecx
mov    %ebx,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x0(%r13),%r15d
mov    $0x1,%edi
call   1080 <fileno2name@plt>
mov    %rax,%r12
mov    $0x1,%edi
call   1030 <isatty@plt>
mov    %eax,%ebp
mov    $0x1,%edi
call   1050 <fileno2FILE@plt>
mov    %eax,%edi
call   1060 <__flbf@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
mov    $0x1,%edi
call   1050 <fileno2FILE@plt>
mov    %eax,%edi
call   1090 <__fbufsize@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %ebp,%ecx
mov    %ebx,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x0(%r13),%r15d
mov    $0x2,%edi
call   1080 <fileno2name@plt>
mov    %rax,%r12
mov    $0x2,%edi
call   1030 <isatty@plt>
mov    %eax,%ebp
mov    $0x2,%edi
call   1050 <fileno2FILE@plt>
mov    %eax,%edi
call   1060 <__flbf@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
mov    $0x2,%edi
call   1050 <fileno2FILE@plt>
mov    %eax,%edi
call   1090 <__fbufsize@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %ebp,%ecx
mov    %ebx,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2c8d(%rip),%rax
mov    (%rax),%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Hit Ctrl-d to initialise stdin\0A\00"
@.str.1 = [20 x i8] c"Initialising stdin\0A\00"
@stdin = global i32 0
@stdout = global i32 0
@.str.2 = [21 x i8] c"Initialising stdout\0A\00"
@.str.3 = [21 x i8] c"Initialising stderr\0A\00"
@.str.4 = [29 x i8] c"%6s: tty=%d, lb=%d, size=%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [4096 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @isatty(i32 0)
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %12
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %9, %6
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i32 @fread(i8* %13, i32 4096, i32 1, i32 %14)
%16 = call i32 @isatty(i32 1)
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i32, i32* @stdout
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %26
21: ; preds = %12
%22 = load i32, i32* @stdout
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %21, %18
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %29
29: ; preds = %48, %26
%30 = load i32, i32* %3
%31 = icmp slt i32 %30, 3
br i1 %31, label %32, label %51
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = load i32, i32* %3
%35 = call i8* @fileno2name(i32 %34)
%36 = load i32, i32* %3
%37 = call i32 @isatty(i32 %36)
%38 = load i32, i32* %3
%39 = call i32 @fileno2FILE(i32 %38)
%40 = call i64 @__flbf(i32 %39)
%41 = icmp ne i64 %40, 0
%42 = zext i1 %41 to i64
%43 = select i1 %41, i32 1, i32 0
%44 = load i32, i32* %3
%45 = call i32 @fileno2FILE(i32 %44)
%46 = call i32 @__fbufsize(i32 %45)
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %35, i32 %37, i32 %43, i32 %46)
br label %48
48: ; preds = %32
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 1
store i32 %50, i32* %3
br label %29
51: ; preds = %29
%52 = load i32, i32* @EXIT_SUCCESS
ret i32 %52
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Hit Ctrl-d to initialise stdin\0A\00"
@.str.1 = [20 x i8] c"Initialising stdin\0A\00"
@stdin = global i32 0
@stdout = global i32 0
@.str.2 = [21 x i8] c"Initialising stdout\0A\00"
@.str.3 = [21 x i8] c"Initialising stderr\0A\00"
@.str.4 = [29 x i8] c"%6s: tty=%d, lb=%d, size=%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [4096 x i8]
%2 = tail call i32 @isatty(i32 0)
%3 = icmp eq i32 %2, 0
%4 = load i32, i32* @stderr
%5 = select i1 %3, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0)
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* %5)
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fread(i8* %7, i32 4096, i32 1, i32 %8)
%10 = call i32 @isatty(i32 1)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i32, i32* @stdout
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %0, %12
%16 = phi i32* [ @stderr, %12 ], [ @stdout, %0 ]
%17 = load i32, i32* %16
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* @stderr
%22 = call i8* @fileno2name(i32 0)
%23 = call i32 @isatty(i32 0)
%24 = call i32 @fileno2FILE(i32 0)
%25 = call i64 @__flbf(i32 %24)
%26 = icmp ne i64 %25, 0
%27 = zext i1 %26 to i32
%28 = call i32 @fileno2FILE(i32 0)
%29 = call i32 @__fbufsize(i32 %28)
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %22, i32 %23, i32 %27, i32 %29)
%31 = load i32, i32* @stderr
%32 = call i8* @fileno2name(i32 1)
%33 = call i32 @isatty(i32 1)
%34 = call i32 @fileno2FILE(i32 1)
%35 = call i64 @__flbf(i32 %34)
%36 = icmp ne i64 %35, 0
%37 = zext i1 %36 to i32
%38 = call i32 @fileno2FILE(i32 1)
%39 = call i32 @__fbufsize(i32 %38)
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %32, i32 %33, i32 %37, i32 %39)
%41 = load i32, i32* @stderr
%42 = call i8* @fileno2name(i32 2)
%43 = call i32 @isatty(i32 2)
%44 = call i32 @fileno2FILE(i32 2)
%45 = call i64 @__flbf(i32 %44)
%46 = icmp ne i64 %45, 0
%47 = zext i1 %46 to i32
%48 = call i32 @fileno2FILE(i32 2)
%49 = call i32 @__fbufsize(i32 %48)
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %42, i32 %43, i32 %47, i32 %49)
%51 = load i32, i32* @EXIT_SUCCESS
ret i32 %51
}