#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 */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, scalar_t__);
int read(int /*<<< orphan*/, void *, int);
int /*<<< orphan*/ write(int, void *, int);
int main(int argc, char *argv[]) {
  char buff;
  int status;
  while (1) {
    status = read(0, (void *)&buff, 1);
    if (-1 == status) {
      if (errno != EINTR) {
        printf("errno = %d\n", errno);
        exit(1);
      }
      continue;
    } else if (0 == status) {
      exit(1);
    }
    write(1, (void *)&buff, 1);
    write(2, (void *)&buff, 1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
mov    $0xffffffff,%eax
cmp    -0x18(%rbp),%eax
jne    11b6 <main+0x76>
mov    0x2e62(%rip),%rax
mov    (%rax),%rax
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%rax
je     11b1 <main+0x71>
mov    0x2e48(%rip),%rax
mov    (%rax),%rsi
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1156 <main+0x16>
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
jne    11cb <main+0x8b>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    11d0 <main+0x90>
mov    $0x1,%edx
lea    -0x11(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
mov    $0x2,%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1156 <main+0x16>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xf(%rsp),%rbx
mov    0x2e8b(%rip),%r14
mov    0x2e7c(%rip),%r15
jmp    1168 <main+0x28>
xchg   %ax,%ax
mov    (%r14),%rsi
cmp    (%r15),%rsi
jne    11a6 <main+0x66>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     1160 <main+0x20>
test   %eax,%eax
je     11b2 <main+0x72>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1168 <main+0x28>
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@.str = [12 x i8] c"errno = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %2, %20, %27
%9 = call i32 @read(i32 0, i8* %6, i32 1)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp eq i32 -1, %10
br i1 %11, label %12, label %21
12: ; preds = %8
%13 = load i64, i64* @errno
%14 = load i64, i64* @EINTR
%15 = icmp ne i64 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i64, i64* @errno
%18 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %12
br label %8
21: ; preds = %8
%22 = load i32, i32* %7
%23 = icmp eq i32 0, %22
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %21
br label %27
27: ; preds = %26
%28 = call i32 @write(i32 1, i8* %6, i32 1)
%29 = call i32 @write(i32 2, i8* %6, i32 1)
br label %8
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@.str = [12 x i8] c"errno = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
br label %4
4: ; preds = %18, %2
%5 = call i32 @read(i32 0, i8* %3, i32 1)
switch i32 %5, label %15 [
i32 -1, label %6
i32 0, label %13
]
6: ; preds = %4
%7 = load i64, i64* @errno
%8 = load i64, i64* @EINTR
%9 = icmp eq i64 %7, %8
br i1 %9, label %18, label %10
10: ; preds = %6
%11 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %7)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %4
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %4
%16 = call i32 @write(i32 1, i8* %3, i32 1)
%17 = call i32 @write(i32 2, i8* %3, i32 1)
br label %18
18: ; preds = %15, %6
br label %4
}