#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 EOF;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int getchar();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ putchar(int);
int read(int, int *, int);
int /*<<< orphan*/ stdout;
int main(void) {
  int ch, counter = 1, console;
  if ((console = open("/dev/tty", O_RDONLY)) < 0) {
    perror(NULL);
    return 1;
  }
  while ((ch = getchar()) != EOF) {
    if (ch != '\n' || counter++ % 10 != 0) {
      putchar(ch);
      continue;
    }
    printf("\n--[%d] ", counter - 1);
    fflush(stdout);
    if ((read(console, &ch, 1)) == -1) {
      perror(NULL);
      return 1;
    }
    if (ch == 'q') {
      read(console, &ch, 1);
      return 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    0xe6a(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    11bc <main+0x4c>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    128f <main+0x11f>
jmp    11c1 <main+0x51>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e0e(%rip),%rcx
cmp    (%rcx),%eax
je     1288 <main+0x118>
cmpl   $0xa,-0x8(%rbp)
jne    1200 <main+0x90>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     120d <main+0x9d>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
jmp    11c1 <main+0x51>
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
lea    0xdef(%rip),%rdi
call   1040 <printf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x10(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
jne    125c <main+0xec>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    128f <main+0x11f>
cmpl   $0x71,-0x8(%rbp)
jne    1283 <main+0x113>
mov    -0x10(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
movl   $0x0,-0x4(%rbp)
jmp    128f <main+0x11f>
jmp    11c1 <main+0x51>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    0xe75(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1271 <main+0x101>
mov    %eax,%r12d
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %eax,0x4(%rsp)
mov    0x2e31(%rip),%r13
cmp    0x0(%r13),%eax
jne    11c6 <main+0x56>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebx
lea    0x4(%rsp),%r15
xor    %ebp,%ebp
jmp    1201 <main+0x91>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14d,%ebx
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %ebx,%r14d
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %eax,0x4(%rsp)
mov    %r14d,%ebx
cmp    0x0(%r13),%eax
je     11b5 <main+0x45>
cmp    $0xa,%eax
jne    11e3 <main+0x73>
lea    0x1(%rbx),%r14d
imul   $0xcccccccd,%ebx,%ecx
add    $0x19999998,%ecx
ror    %ecx
cmp    $0x19999999,%ecx
jae    11e0 <main+0x70>
lea    0xde2(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     1271 <main+0x101>
cmpl   $0x71,0x4(%rsp)
jne    11ed <main+0x7d>
lea    0x4(%rsp),%rsi
mov    %r12d,%edi
mov    $0x1,%edx
call   1050 <read@plt>
xor    %ebp,%ebp
jmp    11b5 <main+0x45>
xor    %edi,%edi
call   1090 <perror@plt>
mov    $0x1,%ebp
jmp    11b5 <main+0x45>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/tty\00"
@O_RDONLY = global i32 0
@EOF = global i32 0
@.str.1 = [9 x i8] c"\0A--[%d] \00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %3
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %4
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i32* null)
store i32 1, i32* %1
br label %45
10: ; preds = %0
br label %11
11: ; preds = %43, %23, %10
%12 = call i32 (...) @getchar()
store i32 %12, i32* %2
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %44
15: ; preds = %11
%16 = load i32, i32* %2
%17 = icmp ne i32 %16, 10
br i1 %17, label %23, label %18
18: ; preds = %15
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
%21 = srem i32 %19, 10
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18, %15
%24 = load i32, i32* %2
%25 = call i32 @putchar(i32 %24)
br label %11
26: ; preds = %18
%27 = load i32, i32* %3
%28 = sub nsw i32 %27, 1
%29 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = load i32, i32* @stdout
%31 = call i32 @fflush(i32 %30)
%32 = load i32, i32* %4
%33 = call i32 @read(i32 %32, i32* %2, i32 1)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %26
%36 = call i32 @perror(i32* null)
store i32 1, i32* %1
br label %45
37: ; preds = %26
%38 = load i32, i32* %2
%39 = icmp eq i32 %38, 113
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32, i32* %4
%42 = call i32 @read(i32 %41, i32* %2, i32 1)
store i32 0, i32* %1
br label %45
43: ; preds = %37
br label %11
44: ; preds = %11
store i32 0, i32* %1
br label %45
45: ; preds = %44, %40, %35, %8
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/tty\00"
@O_RDONLY = global i32 0
@EOF = global i32 0
@.str.1 = [9 x i8] c"\0A--[%d] \00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %0
%7 = tail call i32 (...) @getchar()
store i32 %7, i32* %1
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %41, label %12
10: ; preds = %0
%11 = tail call i32 @perror(i32* null)
br label %41
12: ; preds = %6, %23
%13 = phi i32 [ %25, %23 ], [ %7, %6 ]
%14 = phi i32 [ %24, %23 ], [ 1, %6 ]
%15 = icmp eq i32 %13, 10
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = add nsw i32 %14, 1
%18 = srem i32 %14, 10
%19 = icmp eq i32 %18, 0
br i1 %19, label %28, label %20
20: ; preds = %16, %12
%21 = phi i32 [ %14, %12 ], [ %17, %16 ]
%22 = tail call i32 @putchar(i32 %13)
br label %23
23: ; preds = %20, %36
%24 = phi i32 [ %21, %20 ], [ %17, %36 ]
%25 = tail call i32 (...) @getchar()
store i32 %25, i32* %1
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %41, label %12
28: ; preds = %16
%29 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%30 = load i32, i32* @stdout
%31 = tail call i32 @fflush(i32 %30)
%32 = call i32 @read(i32 %4, i32* %1, i32 1)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = tail call i32 @perror(i32* null)
br label %41
36: ; preds = %28
%37 = load i32, i32* %1
%38 = icmp eq i32 %37, 113
br i1 %38, label %39, label %23
39: ; preds = %36
%40 = call i32 @read(i32 %4, i32* %1, i32 1)
br label %41
41: ; preds = %23, %6, %39, %34, %10
%42 = phi i32 [ 1, %10 ], [ 1, %34 ], [ 0, %39 ], [ 0, %6 ], [ 0, %23 ]
ret i32 %42
}