#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*/ err(int, char *);
int read(int /*<<< orphan*/, char *, int);
int main(void) {
  char ch = 0;
  int r;
  while (ch != 'q') {
    r = read(STDIN_FILENO, &ch, 1);
    if (r < 0) {
      err(1, "stdin");
    }
    if (r == 0) {
      break;
    }
  }
  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     1189 <main+0x69>
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1175 <main+0x55>
mov    $0x1,%edi
lea    0xe90(%rip),%rsi
call   1040 <err@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1184 <main+0x64>
jmp    1189 <main+0x69>
jmp    1133 <main+0x13>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movb   $0x0,0x7(%rsp)
mov    0x2ead(%rip),%r15
lea    0x7(%rsp),%rbx
lea    0xec1(%rip),%r14
nop
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1163 <main+0x43>
mov    $0x1,%edi
mov    %r14,%rsi
call   1040 <err@plt>
test   %ebp,%ebp
je     116e <main+0x4e>
cmpb   $0x71,0x7(%rsp)
jne    1140 <main+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@.str = [6 x i8] c"stdin\00"
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 %20
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 ([6 x i8], [6 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 %20
19: ; preds = %15
br label %4
20: ; preds = %18, %4
ret i32 0
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@.str = [6 x i8] c"stdin\00"
define i32 @main() {
%1 = alloca i8
store i8 0, i8* %1
br label %2
2: ; preds = %0, %8
%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 ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = icmp ne i32 %4, 0
%10 = load i8, i8* %1
%11 = icmp ne i8 %10, 113
%12 = select i1 %9, i1 %11, i1 false
br i1 %12, label %2, label %13
13: ; preds = %8
ret i32 0
}