#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 *);
void trim_crlf(char *s) {
  char *se;
  se = s + strlen(s) - 1;
  while (se >= s) {
    if (*se != '\n' && *se != '\r')
      break;
    se--;
  }
  *(se + 1) = 0;
}


x86 assembly (clang, -O0):
<trim_crlf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     1185 <trim_crlf+0x75>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1174 <trim_crlf+0x64>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
je     1174 <trim_crlf+0x64>
jmp    1185 <trim_crlf+0x75>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1141 <trim_crlf+0x31>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_crlf>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %eax,%rcx
lea    (%rbx,%rcx,1),%rax
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jae    1139 <trim_crlf+0x29>
add    %rcx,%rbx
jmp    114d <trim_crlf+0x3d>
xchg   %ax,%ax
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jb     1146 <trim_crlf+0x36>
movzbl (%rax),%ecx
cmp    $0xd,%cl
je     1130 <trim_crlf+0x20>
cmp    $0xa,%cl
je     1130 <trim_crlf+0x20>
add    $0x1,%rax
mov    %rax,%rbx
movb   $0x0,(%rbx)
pop    %rbx
ret

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

LLVM IR (-O2):
define void @trim_crlf(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = getelementptr inbounds i8, i8* %4, i64 -1
%6 = icmp ult i8* %5, %0
br i1 %6, label %14, label %7
7: ; preds = %1, %11
%8 = phi i8* [ %12, %11 ], [ %5, %1 ]
%9 = phi i8* [ %8, %11 ], [ %4, %1 ]
%10 = load i8, i8* %8
switch i8 %10, label %14 [
i8 10, label %11
i8 13, label %11
]
11: ; preds = %7, %7
%12 = getelementptr inbounds i8, i8* %8, i64 -1
%13 = icmp ult i8* %12, %0
br i1 %13, label %14, label %7
14: ; preds = %11, %7, %1
%15 = phi i8* [ %4, %1 ], [ %9, %7 ], [ %8, %11 ]
store i8 0, i8* %15
ret void
}