#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*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ err(int, char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main() {
  char ch = 0;
  int len;
  while (ch != 'q') {
    len = read(STDIN_FILENO, &ch, 1);
    if (len < 0) {
      err(1, "stdin: read");
    }
    if (len == 0) {
      break;
    }
    write(STDOUT_FILENO, &ch, 1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x71,%eax
je     11b0 <main+0x80>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1185 <main+0x55>
mov    $0x1,%edi
lea    0xe80(%rip),%rsi
call   1050 <err@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1194 <main+0x64>
jmp    11b0 <main+0x80>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1143 <main+0x13>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movb   $0x0,0x7(%rsp)
mov    0x2e94(%rip),%r15
lea    0x7(%rsp),%rbx
lea    0xeb0(%rip),%r14
mov    0x2e99(%rip),%r12
jmp    1185 <main+0x55>
nopl   0x0(%rax)
mov    $0x1,%edi
mov    %r14,%rsi
call   1050 <err@plt>
mov    (%r12),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmpb   $0x71,0x7(%rsp)
je     119b <main+0x6b>
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %eax,%eax
js     1160 <main+0x30>
jne    116d <main+0x3d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@.str = [12 x i8] c"stdin: read\00"
@STDOUT_FILENO = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
store i32 0, i32* %1
store i8 0, i8* %2
br label %4
4: ; preds = %19, %0
%5 = load i8, i8* %2
%6 = sext i8 %5 to i32
%7 = icmp ne i32 %6, 113
br i1 %7, label %8, label %22
8: ; preds = %4
%9 = load i32, i32* @STDIN_FILENO
%10 = call i32 @read(i32 %9, i8* %2, i32 1)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15
br label %22
19: ; preds = %15
%20 = load i32, i32* @STDOUT_FILENO
%21 = call i32 @write(i32 %20, i8* %2, i32 1)
br label %4
22: ; preds = %18, %4
ret i32 0
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@.str = [12 x i8] c"stdin: read\00"
@STDOUT_FILENO = global i32 0
define i32 @main() {
%1 = alloca i8
store i8 0, i8* %1
br label %2
2: ; preds = %0, %10
%3 = load i32, i32* @STDIN_FILENO
%4 = call i32 @read(i32 %3, i8* %1, i32 1)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %10
8: ; preds = %2
%9 = icmp eq i32 %4, 0
br i1 %9, label %15, label %10
10: ; preds = %6, %8
%11 = load i32, i32* @STDOUT_FILENO
%12 = call i32 @write(i32 %11, i8* %1, i32 1)
%13 = load i8, i8* %1
%14 = icmp eq i8 %13, 113
br i1 %14, label %15, label %2
15: ; preds = %8, %10
ret i32 0
}