#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 cuftpd_trim_lineend(char *cp) {
  if (cp && strlen(cp) > 0) {
    char *cp2 = &cp[strlen(cp) - 1];
    while (*cp2 == '\r' || *cp2 == '\n')
      if (--cp2 < cp)
        break;
    cp2[1] = '\0';
  }
}


x86 assembly (clang, -O0):
<cuftpd_trim_lineend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ba <cuftpd_trim_lineend+0xaa>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jle    11ba <cuftpd_trim_lineend+0xaa>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0xd,%ecx
mov    %al,-0x19(%rbp)
je     1182 <cuftpd_trim_lineend+0x72>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1192 <cuftpd_trim_lineend+0x82>
jmp    11b2 <cuftpd_trim_lineend+0xa2>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
cmp    -0x8(%rbp),%rax
jae    11ad <cuftpd_trim_lineend+0x9d>
jmp    11b2 <cuftpd_trim_lineend+0xa2>
jmp    115d <cuftpd_trim_lineend+0x4d>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cuftpd_trim_lineend>:
push   %rbx
test   %rdi,%rdi
je     115a <cuftpd_trim_lineend+0x4a>
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    115a <cuftpd_trim_lineend+0x4a>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
jmp    1149 <cuftpd_trim_lineend+0x39>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jb     1156 <cuftpd_trim_lineend+0x46>
movzbl (%rax),%ecx
cmp    $0xd,%cl
je     1140 <cuftpd_trim_lineend+0x30>
cmp    $0xa,%cl
je     1140 <cuftpd_trim_lineend+0x30>
movb   $0x0,0x1(%rax)
pop    %rbx
ret

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

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