#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 */
scalar_t__ memcmp(char *, char const *, int);
int strlen(char const *);
int getLeftEolLength(const char *s) {
  int i, pos = 0;
  for (i = 0; i < strlen(s); i++) {
    if (memcmp("\r", s + i, 1) == 0 || memcmp("\n", s + i, 1) == 0 ||
        memcmp(" ", s + i, 1) == 0) {
      pos++;
    } else {
      return pos;
    }
  }
  return pos;
}


x86 assembly (clang, -O0):
<getLeftEolLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11f4 <getLeftEolLength+0xd4>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
lea    0xe98(%rip),%rdi
mov    $0x1,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     11c8 <getLeftEolLength+0xa8>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
lea    0xe74(%rip),%rdi
mov    $0x1,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     11c8 <getLeftEolLength+0xa8>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
lea    0xe50(%rip),%rdi
mov    $0x1,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11d6 <getLeftEolLength+0xb6>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11e1 <getLeftEolLength+0xc1>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fa <getLeftEolLength+0xda>
jmp    11e6 <getLeftEolLength+0xc6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113a <getLeftEolLength+0x1a>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLeftEolLength>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
xor    %ebx,%ebx
test   %eax,%eax
jle    11a6 <getLeftEolLength+0x86>
lea    0xec0(%rip),%r15
lea    0xebb(%rip),%r12
lea    0xeb6(%rip),%r13
jmp    1163 <getLeftEolLength+0x43>
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11a6 <getLeftEolLength+0x86>
lea    (%r14,%rbx,1),%rbp
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     1150 <getLeftEolLength+0x30>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     1150 <getLeftEolLength+0x30>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     1150 <getLeftEolLength+0x30>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"\0D\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [2 x i8] c" \00"
define i32 @getLeftEolLength(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %23
4: ; preds = %1, %15
%5 = phi i64 [ %16, %15 ], [ 0, %1 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = tail call i64 @memcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %6, i32 1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %4
%10 = tail call i64 @memcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %6, i32 1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i64 @memcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %6, i32 1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12, %9, %4
%16 = add nuw nsw i64 %5, 1
%17 = tail call i32 @strlen(i8* %0)
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %4, label %20
20: ; preds = %15, %12
%21 = phi i64 [ %5, %12 ], [ %16, %15 ]
%22 = trunc i64 %21 to i32
br label %23
23: ; preds = %20, %1
%24 = phi i32 [ 0, %1 ], [ %22, %20 ]
ret i32 %24
}