#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 *rmcrlf(char *s, int slen) {
  int l;
  s[slen - 1] = '\0';
  l = strlen(s) - 1;
  while (l >= 0 && (s[l] == '\r' || s[l] == '\n'))
    s[l--] = '\0';
  return s;
}


x86 assembly (clang, -O0):
<rmcrlf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jl     1183 <rmcrlf+0x73>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0xd,%ecx
mov    %al,-0x12(%rbp)
je     117d <rmcrlf+0x6d>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
sete   %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1193 <rmcrlf+0x83>
jmp    11ae <rmcrlf+0x9e>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0x10(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    113f <rmcrlf+0x2f>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmcrlf>:
push   %rbx
mov    %rdi,%rbx
movslq %esi,%rax
movb   $0x0,-0x1(%rax,%rdi,1)
call   1030 <strlen@plt>
test   %eax,%eax
jle    114f <rmcrlf+0x3f>
mov    %eax,%eax
add    $0x1,%rax
jmp    113e <rmcrlf+0x2e>
nopl   (%rax)
movb   $0x0,(%rbx,%rcx,1)
add    $0xffffffffffffffff,%rax
cmp    $0x1,%rax
jbe    114f <rmcrlf+0x3f>
lea    -0x2(%rax),%ecx
movzbl (%rbx,%rcx,1),%edx
cmp    $0xd,%dl
je     1130 <rmcrlf+0x20>
cmp    $0xa,%dl
je     1130 <rmcrlf+0x20>
mov    %rbx,%rax
pop    %rbx
ret

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

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