#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 */
char EOF;
int /*<<< orphan*/ printf(char *, char);
int read(int, char *, int);
void printBuffer(int fd) {
  int lineCount = 0;
  char single;
  int bytes = 1;
  char user = ' ';
  while (bytes > 0) {
    bytes = read(fd, &single, 1);
    if (single == EOF)
      break;
    if (single == '\n')
      lineCount++;
    printf("%c", single);
    if (lineCount == 19) {
      while (user != '\n') {
        read(0, &user, 1);
      }
      user = ' ';
      lineCount = 0;
    }
  }
}


x86 assembly (clang, -O0):
<printBuffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
movb   $0x20,-0x11(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    11dd <printBuffer+0xbd>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x10(%rbp)
movsbl -0x9(%rbp),%eax
mov    0x2e82(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1176 <printBuffer+0x56>
jmp    11dd <printBuffer+0xbd>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jne    118c <printBuffer+0x6c>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
lea    0xe6d(%rip),%rdi
movsbl -0x9(%rbp),%esi
call   1030 <printf@plt>
cmpl   $0x13,-0x8(%rbp)
jne    11d8 <printBuffer+0xb8>
jmp    11ab <printBuffer+0x8b>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
je     11cd <printBuffer+0xad>
xor    %edi,%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
jmp    11ab <printBuffer+0x8b>
movb   $0x20,-0x11(%rbp)
movl   $0x0,-0x8(%rbp)
jmp    113d <printBuffer+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printBuffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r12d
movb   $0x20,0x6(%rsp)
xor    %r15d,%r15d
lea    0x7(%rsp),%r14
mov    0x2ea6(%rip),%r13
lea    0x6(%rsp),%rbx
jmp    1154 <printBuffer+0x34>
nopl   0x0(%rax)
test   %ebp,%ebp
jle    11b0 <printBuffer+0x90>
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,%ebp
mov    0x7(%rsp),%al
cmp    0x0(%r13),%al
je     11b0 <printBuffer+0x90>
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %ecx,%r15d
movsbl %al,%esi
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
cmp    $0x13,%r15d
jne    1150 <printBuffer+0x30>
nop
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmpb   $0xa,0x6(%rsp)
jne    1190 <printBuffer+0x70>
movb   $0x20,0x6(%rsp)
xor    %r15d,%r15d
jmp    1150 <printBuffer+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i8 0
@.str = [3 x i8] c"%c\00"
define void @printBuffer(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i8
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 1, i32* %5
store i8 32, i8* %6
br label %7
7: ; preds = %39, %1
%8 = load i32, i32* %5
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %40
10: ; preds = %7
%11 = load i32, i32* %2
%12 = call i32 @read(i32 %11, i8* %4, i32 1)
store i32 %12, i32* %5
%13 = load i8, i8* %4
%14 = sext i8 %13 to i32
%15 = load i8, i8* @EOF
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %14, %16
br i1 %17, label %18, label %19
18: ; preds = %10
br label %40
19: ; preds = %10
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %26
26: ; preds = %23, %19
%27 = load i8, i8* %4
%28 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %27)
%29 = load i32, i32* %3
%30 = icmp eq i32 %29, 19
br i1 %30, label %31, label %39
31: ; preds = %26
br label %32
32: ; preds = %36, %31
%33 = load i8, i8* %6
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 10
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @read(i32 0, i8* %6, i32 1)
br label %32
38: ; preds = %32
store i8 32, i8* %6
store i32 0, i32* %3
br label %39
39: ; preds = %38, %26
br label %7
40: ; preds = %18, %7
ret void
}

LLVM IR (-O2):
@EOF = global i8 0
@.str = [3 x i8] c"%c\00"
define void @printBuffer(i32 %0) {
%2 = alloca i8
%3 = alloca i8
store i8 32, i8* %3
br label %4
4: ; preds = %1, %21
%5 = phi i32 [ 0, %1 ], [ %22, %21 ]
%6 = call i32 @read(i32 %0, i8* %2, i32 1)
%7 = load i8, i8* %2
%8 = load i8, i8* @EOF
%9 = icmp eq i8 %7, %8
br i1 %9, label %24, label %10
10: ; preds = %4
%11 = icmp eq i8 %7, 10
%12 = zext i1 %11 to i32
%13 = add nsw i32 %5, %12
%14 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %7)
%15 = icmp eq i32 %13, 19
br i1 %15, label %16, label %21
16: ; preds = %10, %16
%17 = call i32 @read(i32 0, i8* %3, i32 1)
%18 = load i8, i8* %3
%19 = icmp eq i8 %18, 10
br i1 %19, label %20, label %16
20: ; preds = %16
store i8 32, i8* %3
br label %21
21: ; preds = %20, %10
%22 = phi i32 [ 0, %20 ], [ %13, %10 ]
%23 = icmp sgt i32 %6, 0
br i1 %23, label %4, label %24
24: ; preds = %4, %21
ret void
}