#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 *memchr(char const *, char, int);
int scan_line_end(const char *s, int size) {
  char *match;
  match = memchr(s, '\r', size - 1);
  if (!match)
    return 0;
  if (match[1] == '\n')
    return match - s + 2;
  return 0;
}


x86 assembly (clang, -O0):
<scan_line_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
mov    $0xd,%esi
call   1030 <memchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    114e <scan_line_end+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    117d <scan_line_end+0x6d>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0xa,%eax
jne    1176 <scan_line_end+0x66>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x2,%rax
mov    %eax,-0x4(%rbp)
jmp    117d <scan_line_end+0x6d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_line_end>:
push   %rbx
mov    %rdi,%rbx
lea    -0x1(%rsi),%edx
mov    $0xd,%esi
call   1030 <memchr@plt>
xor    %ecx,%ecx
test   %rax,%rax
je     1135 <scan_line_end+0x25>
cmpb   $0xa,0x1(%rax)
jne    1135 <scan_line_end+0x25>
sub    %ebx,%eax
add    $0x2,%eax
mov    %eax,%ecx
mov    %ecx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @scan_line_end(i8* %0, i32 %1) {
%3 = add nsw i32 %1, -1
%4 = tail call i8* @memchr(i8* %0, i8 signext 13, i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %4, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 10
br i1 %9, label %10, label %16
10: ; preds = %6
%11 = ptrtoint i8* %4 to i64
%12 = ptrtoint i8* %0 to i64
%13 = sub i64 %11, %12
%14 = trunc i64 %13 to i32
%15 = add i32 %14, 2
br label %16
16: ; preds = %6, %2, %10
%17 = phi i32 [ %15, %10 ], [ 0, %2 ], [ 0, %6 ]
ret i32 %17
}