#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;

/* Variables and functions */
int /*<<< orphan*/ _IONBF;
scalar_t__ feof(int /*<<< orphan*/);
size_t fread(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
void *t2_fun(void *arg) {
  char buf[1];
  setvbuf(stdin, NULL, _IONBF, 0);
  setvbuf(stdout, NULL, _IONBF, 0);
  for (;;) {
    size_t read = fread(buf, 1, sizeof(buf), stdin);
    if (read) {
      fwrite(buf, 1, read, stdout);
    }
    if (feof(stdin)) {
      return NULL;
    }
  }
}


x86 assembly (clang, -O0):
<t2_fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
mov    0x2e84(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1050 <setvbuf@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1050 <setvbuf@plt>
lea    -0x9(%rbp),%rdi
mov    0x2e57(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c9 <t2_fun+0x89>
lea    -0x9(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2e13(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     11e9 <t2_fun+0xa9>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    1186 <t2_fun+0x46>

x86 assembly (clang, -O2):
<t2_fun>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e98(%rip),%r14
mov    (%r14),%edi
mov    0x2e86(%rip),%rbx
mov    (%rbx),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1050 <setvbuf@plt>
mov    0x2e64(%rip),%r15
mov    (%r15),%edi
mov    (%rbx),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1050 <setvbuf@plt>
lea    0xf(%rsp),%rbx
jmp    119d <t2_fun+0x5d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14),%edi
call   1040 <feof@plt>
test   %rax,%rax
jne    11cc <t2_fun+0x8c>
mov    (%r14),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
test   %rax,%rax
je     1190 <t2_fun+0x50>
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
call   1060 <fwrite@plt>
jmp    1190 <t2_fun+0x50>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@_IONBF = global i32 0
@stdout = global i32 0
define i8* @t2_fun(i8* %0) {
%2 = alloca i8*
%3 = alloca [1 x i8]
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i32, i32* @stdin
%6 = load i32, i32* @_IONBF
%7 = call i32 @setvbuf(i32 %5, i32* null, i32 %6, i32 0)
%8 = load i32, i32* @stdout
%9 = load i32, i32* @_IONBF
%10 = call i32 @setvbuf(i32 %8, i32* null, i32 %9, i32 0)
br label %11
11: ; preds = %27, %1
%12 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i64 @fread(i8* %12, i32 1, i32 1, i32 %13)
store i64 %14, i64* %4
%15 = load i64, i64* %4
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%19 = load i64, i64* %4
%20 = load i32, i32* @stdout
%21 = call i32 @fwrite(i8* %18, i32 1, i64 %19, i32 %20)
br label %22
22: ; preds = %17, %11
%23 = load i32, i32* @stdin
%24 = call i64 @feof(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
ret i8* null
27: ; preds = %22
br label %11
}

LLVM IR (-O2):
@stdin = global i32 0
@_IONBF = global i32 0
@stdout = global i32 0
define noalias i8* @t2_fun(i8* nocapture readnone %0) {
%2 = alloca [1 x i8]
%3 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @stdin
%5 = load i32, i32* @_IONBF
%6 = tail call i32 @setvbuf(i32 %4, i32* null, i32 %5, i32 0)
%7 = load i32, i32* @stdout
%8 = load i32, i32* @_IONBF
%9 = tail call i32 @setvbuf(i32 %7, i32* null, i32 %8, i32 0)
br label %10
10: ; preds = %17, %1
%11 = load i32, i32* @stdin
%12 = call i64 @fread(i8* %3, i32 1, i32 1, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = load i32, i32* @stdout
%16 = call i32 @fwrite(i8* %3, i32 1, i64 %12, i32 %15)
br label %17
17: ; preds = %14, %10
%18 = load i32, i32* @stdin
%19 = call i64 @feof(i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %10, label %21
21: ; preds = %17
ret i8* null
}