#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 /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
void strtrmcrlf(char *dst, char *src) {
  size_t ln;
  strcpy(dst, src);
  ln = strlen(dst);
  if (*(dst + (ln - 1)) == '\r' || *(dst + (ln - 1)) == '\n')
    *(dst + (ln - 1)) = '\0';
  if (*(dst + (ln - 2)) == '\r' || *(dst + (ln - 2)) == '\n')
    *(dst + (ln - 2)) = '\0';
}


x86 assembly (clang, -O0):
<strtrmcrlf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
je     117c <strtrmcrlf+0x5c>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    118c <strtrmcrlf+0x6c>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x2,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
je     11be <strtrmcrlf+0x9e>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x2,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11ce <strtrmcrlf+0xae>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x2,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtrmcrlf>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    -0x1(%rax,%rbx,1),%cl
cmp    $0xd,%cl
je     113f <strtrmcrlf+0x1f>
cmp    $0xa,%cl
jne    1144 <strtrmcrlf+0x24>
movb   $0x0,-0x1(%rbx,%rax,1)
mov    -0x2(%rax,%rbx,1),%cl
cmp    $0xd,%cl
je     1152 <strtrmcrlf+0x32>
cmp    $0xa,%cl
jne    1157 <strtrmcrlf+0x37>
movb   $0x0,-0x2(%rbx,%rax,1)
pop    %rbx
ret

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

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