#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 */
typedef int ssize_t;

/* Variables and functions */
ssize_t count_lines(char *input, size_t offset) {
  size_t r = 0;
  for (size_t i = 0; i <= offset; ++i) {
    char c = input[i];
    if (c == 0)
      return -1;
    if (c == '\n' || c == '\r')
      ++r;
  }
  return r + 1;
}


x86 assembly (clang, -O0):
<count_lines>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
ja     118d <count_lines+0x8d>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
cmp    $0x0,%eax
jne    1151 <count_lines+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    1198 <count_lines+0x98>
movsbl -0x29(%rbp),%eax
cmp    $0xa,%eax
je     116b <count_lines+0x6b>
movsbl -0x29(%rbp),%eax
cmp    $0xd,%eax
jne    1177 <count_lines+0x77>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    117c <count_lines+0x7c>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    111c <count_lines+0x1c>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_lines>:
xor    %ecx,%ecx
xor    %eax,%eax
jmp    111d <count_lines+0x1d>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rax
add    $0x1,%rcx
cmp    %rsi,%rcx
ja     1135 <count_lines+0x35>
movzbl (%rdi,%rcx,1),%edx
cmp    $0xa,%dl
je     1110 <count_lines+0x10>
cmp    $0xd,%dl
je     1110 <count_lines+0x10>
test   %dl,%dl
jne    1114 <count_lines+0x14>
mov    $0xffffffff,%eax
ret
add    $0x1,%eax
ret

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

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