#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 eol_detect_simple(const char *text, const size_t len) {
  int status = 0;
  int result = 1;
  int ch;
  const char *text_p = text, *text_endp = text_p + len;
  if (text == NULL) {
    return -0;
  }
  while (text_p != text_endp) {
    ch = *text_p;
    switch (status) {
    case 0:
      if (ch == 13) {
        result = 3;
        status = 1;
      } else if (ch == 10) {
        result = 1;
        status = 2;
      }
      break;
    case 1:
      if (ch == 10) {
        result = 2;
        status = 2;
      } else {
        status = 2;
      }
      break;
    case 2:
      goto done;
      break;
    }
    text_p++;
  }
done:
  return result;
}


x86 assembly (clang, -O0):
<eol_detect_simple>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1145 <eol_detect_simple+0x45>
movl   $0x0,-0x4(%rbp)
jmp    1220 <eol_detect_simple+0x120>
jmp    114a <eol_detect_simple+0x4a>
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
je     1215 <eol_detect_simple+0x115>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
test   %eax,%eax
je     1197 <eol_detect_simple+0x97>
jmp    1175 <eol_detect_simple+0x75>
mov    -0x3c(%rbp),%eax
sub    $0x1,%eax
je     11d6 <eol_detect_simple+0xd6>
jmp    1186 <eol_detect_simple+0x86>
mov    -0x3c(%rbp),%eax
sub    $0x2,%eax
je     11ff <eol_detect_simple+0xff>
jmp    1204 <eol_detect_simple+0x104>
cmpl   $0xd,-0x24(%rbp)
jne    11b4 <eol_detect_simple+0xb4>
movl   $0x3,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
jmp    11d1 <eol_detect_simple+0xd1>
cmpl   $0xa,-0x24(%rbp)
jne    11cc <eol_detect_simple+0xcc>
movl   $0x1,-0x20(%rbp)
movl   $0x2,-0x1c(%rbp)
jmp    11d1 <eol_detect_simple+0xd1>
jmp    1204 <eol_detect_simple+0x104>
cmpl   $0xa,-0x24(%rbp)
jne    11f3 <eol_detect_simple+0xf3>
movl   $0x2,-0x20(%rbp)
movl   $0x2,-0x1c(%rbp)
jmp    11fa <eol_detect_simple+0xfa>
movl   $0x2,-0x1c(%rbp)
jmp    1204 <eol_detect_simple+0x104>
jmp    121a <eol_detect_simple+0x11a>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    114a <eol_detect_simple+0x4a>
jmp    121a <eol_detect_simple+0x11a>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<eol_detect_simple>:
test   %rdi,%rdi
je     117a <eol_detect_simple+0x7a>
mov    $0x1,%eax
test   %rsi,%rsi
je     1179 <eol_detect_simple+0x79>
xor    %ecx,%ecx
xor    %r8d,%r8d
jmp    1136 <eol_detect_simple+0x36>
cs nopw 0x0(%rax,%rax,1)
cmp    $0xa,%dl
mov    $0x2,%r8d
cmove  %r8d,%eax
add    $0x1,%rcx
cmp    %rcx,%rsi
je     1179 <eol_detect_simple+0x79>
movzbl (%rdi,%rcx,1),%edx
test   %r8d,%r8d
je     1150 <eol_detect_simple+0x50>
cmp    $0x1,%r8d
je     1120 <eol_detect_simple+0x20>
cmp    $0x2,%r8d
jne    112d <eol_detect_simple+0x2d>
jmp    1179 <eol_detect_simple+0x79>
nopl   (%rax)
cmp    $0xd,%dl
je     1167 <eol_detect_simple+0x67>
cmp    $0xa,%dl
jne    1174 <eol_detect_simple+0x74>
mov    $0x2,%r8d
mov    $0x1,%eax
jmp    112d <eol_detect_simple+0x2d>
mov    $0x1,%r8d
mov    $0x3,%eax
jmp    112d <eol_detect_simple+0x2d>
xor    %r8d,%r8d
jmp    112d <eol_detect_simple+0x2d>
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @eol_detect_simple(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 0, i32* %6
store i32 1, i32* %7
%11 = load i8*, i8** %4
store i8* %11, i8** %9
%12 = load i8*, i8** %9
%13 = load i64, i64* %5
%14 = getelementptr inbounds i8, i8* %12, i64 %13
store i8* %14, i8** %10
%15 = load i8*, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 0, i32* %3
br label %51
18: ; preds = %2
br label %19
19: ; preds = %45, %18
%20 = load i8*, i8** %9
%21 = load i8*, i8** %10
%22 = icmp ne i8* %20, %21
br i1 %22, label %23, label %48
23: ; preds = %19
%24 = load i8*, i8** %9
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
store i32 %26, i32* %8
%27 = load i32, i32* %6
switch i32 %27, label %45 [
i32 0, label %28
i32 1, label %38
i32 2, label %44
]
28: ; preds = %23
%29 = load i32, i32* %8
%30 = icmp eq i32 %29, 13
br i1 %30, label %31, label %32
31: ; preds = %28
store i32 3, i32* %7
store i32 1, i32* %6
br label %37
32: ; preds = %28
%33 = load i32, i32* %8
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %36
35: ; preds = %32
store i32 1, i32* %7
store i32 2, i32* %6
br label %36
36: ; preds = %35, %32
br label %37
37: ; preds = %36, %31
br label %45
38: ; preds = %23
%39 = load i32, i32* %8
%40 = icmp eq i32 %39, 10
br i1 %40, label %41, label %42
41: ; preds = %38
store i32 2, i32* %7
store i32 2, i32* %6
br label %43
42: ; preds = %38
store i32 2, i32* %6
br label %43
43: ; preds = %42, %41
br label %45
44: ; preds = %23
br label %49
45: ; preds = %23, %43, %37
%46 = load i8*, i8** %9
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %9
br label %19
48: ; preds = %19
br label %49
49: ; preds = %48, %44
%50 = load i32, i32* %7
store i32 %50, i32* %3
br label %51
51: ; preds = %49, %17
%52 = load i32, i32* %3
ret i32 %52
}

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