#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*/ printf(char *, int);
scalar_t__ read(int /*<<< orphan*/, char *, int);
int main(void) {
  char ch;
  int i = 0;
  while (read(STDIN_FILENO, &ch, 1) > 0) {
    if (ch == '\n') {
      i++;
    }
  }
  printf("%i\n", ++i);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jle    1172 <main+0x52>
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
jne    116d <main+0x4d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1136 <main+0x16>
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0xc(%rbp)
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2eb0(%rip),%r15
mov    (%r15),%edi
lea    0xf(%rsp),%rsi
mov    $0x1,%ebx
mov    $0x1,%edx
call   1040 <read@plt>
test   %rax,%rax
jle    1184 <main+0x64>
xor    %ebx,%ebx
lea    0xf(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
cmpb   $0xa,0xf(%rsp)
sete   %al
add    %eax,%ebx
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %rax,%rax
jg     1160 <main+0x40>
add    $0x1,%ebx
lea    0xe75(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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