#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 */
size_t count_lines(char *filebuf) {
  size_t i;
  size_t lines = 0;
  for (i = 0; filebuf[i + 1] != '\0'; i++)
    if (filebuf[i] == '\n')
      lines++;
  return ++lines;
}


x86 assembly (clang, -O0):
<count_lines>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl 0x1(%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1165 <count_lines+0x65>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    114f <count_lines+0x4f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1154 <count_lines+0x54>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1118 <count_lines+0x18>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_lines>:
cmpb   $0x0,0x1(%rdi)
je     112a <count_lines+0x2a>
add    $0x2,%rdi
xor    %eax,%eax
nopl   0x0(%rax)
xor    %ecx,%ecx
cmpb   $0xa,-0x2(%rdi)
sete   %cl
add    %rcx,%rax
cmpb   $0x0,(%rdi)
lea    0x1(%rdi),%rdi
jne    1110 <count_lines+0x10>
add    $0x1,%rax
ret
mov    $0x1,%eax
ret

LLVM IR (-O0):
define i64 @count_lines(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* %4
store i64 0, i64* %3
br label %5
5: ; preds = %24, %1
%6 = load i8*, i8** %2
%7 = load i64, i64* %3
%8 = add i64 %7, 1
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %27
13: ; preds = %5
%14 = load i8*, i8** %2
%15 = load i64, i64* %3
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i64, i64* %4
%22 = add i64 %21, 1
store i64 %22, i64* %4
br label %23
23: ; preds = %20, %13
br label %24
24: ; preds = %23
%25 = load i64, i64* %3
%26 = add i64 %25, 1
store i64 %26, i64* %3
br label %5
27: ; preds = %5
%28 = load i64, i64* %4
%29 = add i64 %28, 1
store i64 %29, i64* %4
ret i64 %29
}

LLVM IR (-O2):
define i64 @count_lines(i8* nocapture %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = load i8, i8* %2
%4 = icmp eq i8 %3, 0
br i1 %4, label %20, label %5
5: ; preds = %1, %5
%6 = phi i64 [ %14, %5 ], [ 1, %1 ]
%7 = phi i64 [ %13, %5 ], [ 0, %1 ]
%8 = phi i64 [ %6, %5 ], [ 0, %1 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 10
%12 = zext i1 %11 to i64
%13 = add i64 %7, %12
%14 = add i64 %6, 1
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %5
18: ; preds = %5
%19 = add i64 %13, 1
br label %20
20: ; preds = %18, %1
%21 = phi i64 [ 1, %1 ], [ %19, %18 ]
ret i64 %21
}