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

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int arc, char **argv) {
  printf("Going to read from stdin...\n");
  char line[8000];
  char buffer[1];
  int nbytes = 0;
  while ((nbytes = read(0, buffer, 1)) > 0) {
    write(1, buffer, 1);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x1f58(%rbp)
lea    -0x1f51(%rbp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x1f58(%rbp)
cmp    $0x0,%eax
jle    11a9 <main+0x69>
lea    -0x1f51(%rbp),%rsi
mov    $0x1,%edx
mov    %edx,%edi
call   1030 <write@plt>
jmp    116f <main+0x2f>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
lea    0xf(%rsp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    1195 <main+0x55>
lea    0xf(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %eax,%eax
jg     1170 <main+0x30>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"Going to read from stdin...\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [8000 x i8]
%7 = alloca [1 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
br label %10
10: ; preds = %14, %2
%11 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%12 = call i32 @read(i32 0, i8* %11, i32 1)
store i32 %12, i32* %8
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%16 = call i32 @write(i32 1, i8* %15, i32 1)
br label %10
17: ; preds = %10
%18 = load i32, i32* @EXIT_SUCCESS
%19 = call i32 @exit(i32 %18)
unreachable
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@str = [28 x i8] c"Going to read from stdin...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1 x i8]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%5 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%6 = call i32 @read(i32 0, i8* %5, i32 1)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2, %8
%9 = call i32 @write(i32 1, i8* %5, i32 1)
%10 = call i32 @read(i32 0, i8* %5, i32 1)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %8, label %12
12: ; preds = %8, %2
%13 = load i32, i32* @EXIT_SUCCESS
%14 = tail call i32 @exit(i32 %13)
unreachable
}