#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("");
        return 1;
      }
    } else if (nbytes == 0) {
      printf("end of file\n");
      exit(0);
    } else
      write(1, &x, 1);
  }
  return 0;
}


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    119f <main+0x4f>
lea    0xe8e(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret
cmpl   $0x0,-0xc(%rbp)
jne    11bc <main+0x6c>
lea    0xe61(%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    11d1 <main+0x81>
jmp    116b <main+0x1b>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
lea    0xf(%rsp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1050 <read@plt>
test   %eax,%eax
js     11a9 <main+0x59>
lea    0xf(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
test   %eax,%eax
je     11c0 <main+0x70>
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
jns    1180 <main+0x30>
lea    0xe6b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe49(%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))
ret i32 1
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
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))
%3 = call i32 @read(i32 0, i8* %1, i32 1)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %13, %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
ret i32 1
7: ; preds = %0, %13
%8 = phi i32 [ %15, %13 ], [ %3, %0 ]
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%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 = %7
%14 = call i32 @write(i32 1, i8* %1, i32 1)
%15 = call i32 @read(i32 0, i8* %1, i32 1)
%16 = icmp slt i32 %15, 0
br i1 %16, label %5, label %7
}