#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*/ gdb_unbuffer_output();
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;
  gdb_unbuffer_output();
  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)
mov    $0x0,%al
call   1060 <gdb_unbuffer_output@plt>
lea    0xe83(%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    11b6 <main+0x56>
lea    0xe77(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret
cmpl   $0x0,-0xc(%rbp)
jne    11d3 <main+0x73>
lea    0xe4a(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    $0x1,%edx
lea    -0x5(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
jmp    11e8 <main+0x88>
jmp    1182 <main+0x22>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1060 <gdb_unbuffer_output@plt>
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
lea    0xf(%rsp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1050 <read@plt>
test   %eax,%eax
js     11c9 <main+0x69>
lea    0xf(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   %eax,%eax
je     11e0 <main+0x80>
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    11a0 <main+0x40>
lea    0xe4b(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe29(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <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 (...) @gdb_unbuffer_output()
%5 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %0, %21
%7 = call i32 @read(i32 0, i8* %2, i32 1)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
ret i32 1
12: ; preds = %6
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %12
%19 = call i32 @write(i32 1, i8* %2, i32 1)
br label %20
20: ; preds = %18
br label %21
21: ; preds = %20
br label %6
}

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 (...) @gdb_unbuffer_output()
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 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 = %14, %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
ret i32 1
8: ; preds = %0, %14
%9 = phi i32 [ %16, %14 ], [ %4, %0 ]
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.3, i64 0, i64 0))
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %8
%15 = call i32 @write(i32 1, i8* %1, i32 1)
%16 = call i32 @read(i32 0, i8* %1, i32 1)
%17 = icmp slt i32 %16, 0
br i1 %17, label %6, label %8
}