#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(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  char x;
  int nbytes;
  printf("talk to me baby\n");
  while (1) {
    nbytes = read(0, &x, 1);
    if (nbytes < 0) {
      perror("");
    } else if (nbytes == 0) {
      printf("end of file\n");
      exit(0);
    } else
      write(1, &x, 1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1199 <main+0x49>
lea    0xe8e(%rip),%rdi
call   1060 <perror@plt>
jmp    11cb <main+0x7b>
cmpl   $0x0,-0xc(%rbp)
jne    11b6 <main+0x66>
lea    0xe67(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    $0x1,%edx
lea    -0x5(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
jmp    11cb <main+0x7b>
jmp    116b <main+0x1b>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
lea    0x7(%rsp),%rbx
lea    0xeaf(%rip),%r14
jmp    1180 <main+0x30>
mov    %r14,%rdi
call   1060 <perror@plt>
cs nopw 0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %eax,%eax
js     116e <main+0x1e>
je     11a9 <main+0x59>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
jmp    1180 <main+0x30>
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"talk to me baby\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [13 x i8] c"end of file\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %0, %20
%6 = call i32 @read(i32 0, i8* %2, i32 1)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %20
11: ; preds = %5
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %11
%18 = call i32 @write(i32 1, i8* %2, i32 1)
br label %19
19: ; preds = %17
br label %20
20: ; preds = %19, %9
br label %5
}

LLVM IR (-O2):
@.str.1 = [1 x i8] zeroinitializer
@str = [16 x i8] c"talk to me baby\00"
@str.3 = [12 x i8] c"end of file\00"
define i32 @main() {
%1 = alloca i8
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %3
3: ; preds = %15, %0
%4 = call i32 @read(i32 0, i8* %1, i32 1)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %15
8: ; preds = %3
%9 = icmp eq i32 %4, 0
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.3, i64 0, i64 0))
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %8
%14 = call i32 @write(i32 1, i8* %1, i32 1)
br label %15
15: ; preds = %13, %6
br label %3
}