#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 scalar_t__ u_int32_t;

/* Variables and functions */
int parse_token(char *, scalar_t__, char *, int /*<<< orphan*/ *);
int parse_line(char *data, u_int32_t datalen) {
  int i;
  if (datalen <= 0)
    return -1;
  if ((i = parse_token(data, datalen, "\n", NULL)) == -1)
    return -1;
  if (i > 1 && data[i - 2] == '\r')
    data[i - 2] = 0;
  return i;
}


x86 assembly (clang, -O0):
<parse_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jg     1137 <parse_line+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a2 <parse_line+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xeba(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <parse_token@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1167 <parse_line+0x57>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a2 <parse_line+0x92>
cmpl   $0x1,-0x1c(%rbp)
jle    119c <parse_line+0x8c>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    119c <parse_line+0x8c>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_line>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rsi,%rsi
jle    1149 <parse_line+0x39>
mov    %rdi,%rbx
lea    0xed9(%rip),%rdx
xor    %ecx,%ecx
call   1030 <parse_token@plt>
cmp    $0xffffffff,%eax
je     1149 <parse_line+0x39>
cmp    $0x2,%eax
jl     1147 <parse_line+0x37>
mov    %eax,%ecx
add    $0xfffffffe,%ecx
cmpb   $0xd,(%rbx,%rcx,1)
jne    1147 <parse_line+0x37>
movb   $0x0,(%rbx,%rcx,1)
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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