#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*/ memset(char *, int, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *SPC_RTrim(char *line) {
  char CRLF[3] = {0};
  int len = strlen(line);
  char *end;
  if (len <= 1) {
    return line;
  }
  end = line + len - 1;
  if (*end == '\r') {
    strcpy(CRLF, "\r\0\0");
  } else if (*end == '\n') {
    end--;
    if (*end == '\r') {
      if (len == 2) {
        return line;
      }
      strcpy(CRLF, "\r\n\0");
    } else {
      strcpy(CRLF, "\n\0\0");
    }
  } else {
    memset(CRLF, 0x00, 3);
  }
  end--;
  while (end != line) {
    if (*end == ' ' || *end == '\t') {
      *end = '\0';
      end--;
    } else {
      break;
    }
  }
  strcat(line, CRLF);
  return line;
}


x86 assembly (clang, -O0):
<SPC_RTrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x13(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jg     117f <SPC_RTrim+0x3f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12aa <SPC_RTrim+0x16a>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    11b7 <SPC_RTrim+0x77>
lea    -0x13(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1239 <SPC_RTrim+0xf9>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1224 <SPC_RTrim+0xe4>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    120f <SPC_RTrim+0xcf>
cmpl   $0x2,-0x18(%rbp)
jne    11fa <SPC_RTrim+0xba>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12aa <SPC_RTrim+0x16a>
lea    -0x13(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1030 <strcpy@plt>
jmp    121f <SPC_RTrim+0xdf>
lea    -0x13(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1234 <SPC_RTrim+0xf4>
lea    -0x13(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1050 <memset@plt>
jmp    1239 <SPC_RTrim+0xf9>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1295 <SPC_RTrim+0x155>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     1273 <SPC_RTrim+0x133>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
jne    128b <SPC_RTrim+0x14b>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1290 <SPC_RTrim+0x150>
jmp    1295 <SPC_RTrim+0x155>
jmp    1245 <SPC_RTrim+0x105>
mov    -0x10(%rbp),%rdi
lea    -0x13(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SPC_RTrim>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
movb   $0x0,0xe(%rsp)
movw   $0x0,0xc(%rsp)
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     1204 <SPC_RTrim+0xc4>
mov    %eax,%ecx
lea    (%r14,%rcx,1),%rbx
add    $0xffffffffffffffff,%rbx
mov    -0x1(%r14,%rcx,1),%cl
cmp    $0xa,%cl
je     1192 <SPC_RTrim+0x52>
cmp    $0xd,%cl
jne    11aa <SPC_RTrim+0x6a>
lea    0xe7a(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1030 <strcpy@plt>
jmp    11e3 <SPC_RTrim+0xa3>
lea    -0x1(%rbx),%r15
cmpb   $0xd,-0x1(%rbx)
jne    11bd <SPC_RTrim+0x7d>
cmp    $0x2,%eax
je     1204 <SPC_RTrim+0xc4>
lea    0xe5c(%rip),%rsi
jmp    11c4 <SPC_RTrim+0x84>
lea    0xc(%rsp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1050 <memset@plt>
jmp    11e3 <SPC_RTrim+0xa3>
lea    0xe44(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1030 <strcpy@plt>
mov    %r15,%rbx
jmp    11e3 <SPC_RTrim+0xa3>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x0,(%rbx)
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
je     11f7 <SPC_RTrim+0xb7>
movzbl (%rbx),%eax
cmp    $0x20,%al
je     11e0 <SPC_RTrim+0xa0>
cmp    $0x9,%al
je     11e0 <SPC_RTrim+0xa0>
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
call   1060 <strcat@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"\0D\00\00\00"
@.str.1 = [4 x i8] c"\0D\0A\00\00"
@.str.2 = [4 x i8] c"\0A\00\00\00"
define i8* @SPC_RTrim(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [3 x i8]
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
%7 = bitcast [3 x i8]* %4 to i8*
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp sle i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = load i8*, i8** %3
store i8* %13, i8** %2
br label %83
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = getelementptr inbounds i8, i8* %18, i64 -1
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 13
br i1 %23, label %24, label %27
24: ; preds = %14
%25 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%26 = call i32 @strcpy(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %55
27: ; preds = %14
%28 = load i8*, i8** %6
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 10
br i1 %31, label %32, label %51
32: ; preds = %27
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i32 -1
store i8* %34, i8** %6
%35 = load i8*, i8** %6
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 13
br i1 %38, label %39, label %47
39: ; preds = %32
%40 = load i32, i32* %5
%41 = icmp eq i32 %40, 2
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = load i8*, i8** %3
store i8* %43, i8** %2
br label %83
44: ; preds = %39
%45 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%46 = call i32 @strcpy(i8* %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %50
47: ; preds = %32
%48 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%49 = call i32 @strcpy(i8* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %47, %44
br label %54
51: ; preds = %27
%52 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%53 = call i32 @memset(i8* %52, i32 0, i32 3)
br label %54
54: ; preds = %51, %50
br label %55
55: ; preds = %54, %24
%56 = load i8*, i8** %6
%57 = getelementptr inbounds i8, i8* %56, i32 -1
store i8* %57, i8** %6
br label %58
58: ; preds = %77, %55
%59 = load i8*, i8** %6
%60 = load i8*, i8** %3
%61 = icmp ne i8* %59, %60
br i1 %61, label %62, label %78
62: ; preds = %58
%63 = load i8*, i8** %6
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 32
br i1 %66, label %72, label %67
67: ; preds = %62
%68 = load i8*, i8** %6
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 9
br i1 %71, label %72, label %76
72: ; preds = %67, %62
%73 = load i8*, i8** %6
store i8 0, i8* %73
%74 = load i8*, i8** %6
%75 = getelementptr inbounds i8, i8* %74, i32 -1
store i8* %75, i8** %6
br label %77
76: ; preds = %67
br label %78
77: ; preds = %72
br label %58
78: ; preds = %76, %58
%79 = load i8*, i8** %3
%80 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%81 = call i32 @strcat(i8* %79, i8* %80)
%82 = load i8*, i8** %3
store i8* %82, i8** %2
br label %83
83: ; preds = %78, %42, %12
%84 = load i8*, i8** %2
ret i8* %84
}

LLVM IR (-O2):
@.str = [4 x i8] c"\0D\00\00\00"
@.str.1 = [4 x i8] c"\0D\0A\00\00"
@.str.2 = [4 x i8] c"\0A\00\00\00"
define i8* @SPC_RTrim(i8* returned %0) {
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp slt i32 %4, 2
br i1 %5, label %37, label %6
6: ; preds = %1
%7 = zext i32 %4 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 -1
%10 = load i8, i8* %9
switch i8 %10, label %23 [
i8 13, label %11
i8 10, label %13
]
11: ; preds = %6
%12 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %25
13: ; preds = %6
%14 = getelementptr inbounds i8, i8* %9, i64 -1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 13
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = icmp eq i32 %4, 2
br i1 %18, label %37, label %19
19: ; preds = %17
%20 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %25
21: ; preds = %13
%22 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %25
23: ; preds = %6
%24 = call i32 @memset(i8* %3, i32 0, i32 3)
br label %25
25: ; preds = %23, %21, %19, %11
%26 = phi i8* [ %9, %11 ], [ %14, %19 ], [ %14, %21 ], [ %9, %23 ]
%27 = getelementptr inbounds i8, i8* %26, i64 -1
%28 = icmp eq i8* %27, %0
br i1 %28, label %35, label %29
29: ; preds = %25, %32
%30 = phi i8* [ %33, %32 ], [ %27, %25 ]
%31 = load i8, i8* %30
switch i8 %31, label %35 [
i8 32, label %32
i8 9, label %32
]
32: ; preds = %29, %29
store i8 0, i8* %30
%33 = getelementptr inbounds i8, i8* %30, i64 -1
%34 = icmp eq i8* %33, %0
br i1 %34, label %35, label %29
35: ; preds = %32, %29, %25
%36 = call i32 @strcat(i8* %0, i8* %3)
br label %37
37: ; preds = %17, %1, %35
ret i8* %0
}