#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*/ strchr(char *, char);
size_t strlen(char *);
void StrTrim(char *cmd) {
  register char *ch;
  if (!cmd)
    return;
  for (ch = &cmd[strlen(cmd)]; ch >= cmd; ch--)
    if (*ch && !strchr(" \r\n", *ch))
      break;
  if (ch < cmd || *ch)
    ch[1] = 0;
}


x86 assembly (clang, -O0):
<StrTrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    113c <StrTrim+0x1c>
jmp    11d6 <StrTrim+0xb6>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     11b0 <StrTrim+0x90>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     119a <StrTrim+0x7a>
mov    -0x10(%rbp),%rax
lea    0xe7c(%rip),%rdi
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%eax
jne    119a <StrTrim+0x7a>
jmp    11b0 <StrTrim+0x90>
jmp    119f <StrTrim+0x7f>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    115b <StrTrim+0x3b>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     11ce <StrTrim+0xae>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d6 <StrTrim+0xb6>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StrTrim>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1178 <StrTrim+0x58>
mov    %rdi,%r15
call   1030 <strlen@plt>
lea    (%r15,%rax,1),%rbx
test   %rax,%rax
js     1174 <StrTrim+0x54>
lea    0xebe(%rip),%r14
jmp    1159 <StrTrim+0x39>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffffffffffff,%rbx
cmp    %r15,%rbx
jb     1174 <StrTrim+0x54>
movzbl (%rbx),%eax
test   %al,%al
je     1150 <StrTrim+0x30>
movsbl %al,%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
test   %eax,%eax
jne    1150 <StrTrim+0x30>
cmpb   $0x0,(%rbx)
je     1178 <StrTrim+0x58>
movb   $0x0,0x1(%rbx)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c" \0D\0A\00"
define void @StrTrim(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 %7, label %6
6: ; preds = %1
br label %43
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* %9)
%11 = getelementptr inbounds i8, i8* %8, i64 %10
store i8* %11, i8** %3
br label %12
12: ; preds = %28, %7
%13 = load i8*, i8** %3
%14 = load i8*, i8** %2
%15 = icmp uge i8* %13, %14
br i1 %15, label %16, label %31
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = call i32 @strchr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %21
br label %31
27: ; preds = %21, %16
br label %28
28: ; preds = %27
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i32 -1
store i8* %30, i8** %3
br label %12
31: ; preds = %26, %12
%32 = load i8*, i8** %3
%33 = load i8*, i8** %2
%34 = icmp ult i8* %32, %33
br i1 %34, label %40, label %35
35: ; preds = %31
%36 = load i8*, i8** %3
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %35, %31
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 1
store i8 0, i8* %42
br label %43
43: ; preds = %6, %40, %35
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c" \0D\0A\00"
define void @StrTrim(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %23, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* %0)
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = icmp slt i64 %4, 0
br i1 %6, label %20, label %7
7: ; preds = %3, %14
%8 = phi i8* [ %15, %14 ], [ %5, %3 ]
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = tail call i32 @strchr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %9)
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %7, %11
%15 = getelementptr inbounds i8, i8* %8, i64 -1
%16 = icmp ult i8* %15, %0
br i1 %16, label %20, label %7
17: ; preds = %11
%18 = load i8, i8* %8
%19 = icmp eq i8 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %14, %3, %17
%21 = phi i8* [ %8, %17 ], [ %5, %3 ], [ %15, %14 ]
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8 0, i8* %22
br label %23
23: ; preds = %17, %20, %1
ret void
}