#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 strlen(char *);
size_t console_findLineEnd(char *str) {
  int len;
  int i;
  char val;
  len = strlen(str);
  i = 0;
  while (i < len) {
    val = *str;
    if ((val == '\n') || (val == '\r') || (val == '\x1b')) {
      break;
    }
    str++;
    i++;
  }
  return (i);
}


x86 assembly (clang, -O0):
<console_findLineEnd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118a <console_findLineEnd+0x7a>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
je     116b <console_findLineEnd+0x5b>
movsbl -0x11(%rbp),%eax
cmp    $0xd,%eax
je     116b <console_findLineEnd+0x5b>
movsbl -0x11(%rbp),%eax
cmp    $0x1b,%eax
jne    1170 <console_findLineEnd+0x60>
jmp    118a <console_findLineEnd+0x7a>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112f <console_findLineEnd+0x1f>
movslq -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<console_findLineEnd>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    114c <console_findLineEnd+0x3c>
mov    %eax,%eax
xor    %ecx,%ecx
mov    $0x8002400,%edx
jmp    1138 <console_findLineEnd+0x28>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rcx
cmp    %ecx,%eax
je     114e <console_findLineEnd+0x3e>
movzbl (%rbx,%rcx,1),%esi
cmp    $0x1b,%rsi
ja     1130 <console_findLineEnd+0x20>
bt     %rsi,%rdx
jae    1130 <console_findLineEnd+0x20>
mov    %ecx,%eax
jmp    114e <console_findLineEnd+0x3e>
xor    %eax,%eax
mov    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i64 @console_findLineEnd(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %12
4: ; preds = %1, %8
%5 = phi i8* [ %9, %8 ], [ %0, %1 ]
%6 = phi i32 [ %10, %8 ], [ 0, %1 ]
%7 = load i8, i8* %5
switch i8 %7, label %8 [
i8 27, label %12
i8 13, label %12
i8 10, label %12
]
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %5, i64 1
%10 = add nuw nsw i32 %6, 1
%11 = icmp eq i32 %10, %2
br i1 %11, label %12, label %4
12: ; preds = %8, %4, %4, %4, %1
%13 = phi i32 [ 0, %1 ], [ %6, %4 ], [ %6, %4 ], [ %6, %4 ], [ %2, %8 ]
%14 = zext i32 %13 to i64
ret i64 %14
}