#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 *);
char *ClearEOL(char *pszBuffer) {
  int iSize = strlen(pszBuffer);
  for (; iSize > 0 &&
         (pszBuffer[iSize - 1] == '\r' || pszBuffer[iSize - 1] == '\n');
       iSize--)
    ;
  pszBuffer[iSize] = '\0';
  return pszBuffer;
}


x86 assembly (clang, -O0):
<ClearEOL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0xd(%rbp)
jle    1176 <ClearEOL+0x66>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0xd,%ecx
mov    %al,-0xe(%rbp)
je     1170 <ClearEOL+0x60>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
sete   %al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1186 <ClearEOL+0x76>
jmp    1199 <ClearEOL+0x89>
jmp    118b <ClearEOL+0x7b>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1128 <ClearEOL+0x18>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ClearEOL>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    1155 <ClearEOL+0x45>
mov    %eax,%eax
jmp    113d <ClearEOL+0x2d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x1(%rcx),%rdx
mov    %rcx,%rax
cmp    $0x1,%rdx
jbe    1153 <ClearEOL+0x43>
lea    -0x1(%rax),%rcx
mov    %ecx,%edx
movzbl (%rbx,%rdx,1),%edx
cmp    $0xd,%dl
je     1130 <ClearEOL+0x20>
cmp    $0xa,%dl
je     1130 <ClearEOL+0x20>
jmp    1155 <ClearEOL+0x45>
xor    %eax,%eax
cltq
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @ClearEOL(i8* returned %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %16
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %12
%7 = phi i64 [ %5, %4 ], [ %8, %12 ]
%8 = add nsw i64 %7, -1
%9 = and i64 %8, 4294967295
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
switch i8 %11, label %14 [
i8 13, label %12
i8 10, label %12
]
12: ; preds = %6, %6
%13 = icmp ugt i64 %7, 1
br i1 %13, label %6, label %16
14: ; preds = %6
%15 = trunc i64 %7 to i32
br label %16
16: ; preds = %12, %14, %1
%17 = phi i32 [ %2, %1 ], [ %15, %14 ], [ 0, %12 ]
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 0, i8* %19
ret i8* %0
}