char *COM_TrimString(char *str) {
  int i;
  static char buffer[256];
  while (*str <= ' ' && *str > '\0')
    str++;
  for (i = 0; i < 255; i++) {
    if (*str <= ' ')
      break;
    buffer[i] = *str++;
  }
  buffer[i] = '\0';
  return buffer;
}


x86 assembly (clang, -O0):
<COM_TrimString>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0xd(%rbp)
jg     112d <COM_TrimString+0x2d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setg   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    113d <COM_TrimString+0x3d>
jmp    114e <COM_TrimString+0x4e>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1108 <COM_TrimString+0x8>
movl   $0x0,-0xc(%rbp)
cmpl   $0xff,-0xc(%rbp)
jge    11a4 <COM_TrimString+0xa4>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jg     1177 <COM_TrimString+0x77>
jmp    11a4 <COM_TrimString+0xa4>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%dl
movslq -0xc(%rbp),%rcx
lea    0x2e9d(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1155 <COM_TrimString+0x55>
movslq -0xc(%rbp),%rcx
lea    0x2e81(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e76(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<COM_TrimString>:
movzbl (%rdi),%ecx
lea    -0x1(%rcx),%eax
add    $0x1,%rdi
cmp    $0x20,%al
jb     1100 <COM_TrimString>
cmp    $0x21,%cl
jge    1117 <COM_TrimString+0x17>
xor    %ecx,%ecx
jmp    1177 <COM_TrimString+0x77>
mov    $0x2,%eax
lea    0x2f0d(%rip),%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %cl,-0x2(%rax,%rdx,1)
movzbl -0x2(%rdi,%rax,1),%ecx
cmp    $0x21,%cl
jl     116a <COM_TrimString+0x6a>
mov    %cl,-0x1(%rax,%rdx,1)
movzbl -0x1(%rdi,%rax,1),%ecx
cmp    $0x21,%cl
jl     116e <COM_TrimString+0x6e>
mov    %cl,(%rax,%rdx,1)
cmp    $0xfe,%rax
je     1172 <COM_TrimString+0x72>
movzbl (%rdi,%rax,1),%ecx
add    $0x3,%rax
cmp    $0x21,%cl
jge    1130 <COM_TrimString+0x30>
add    $0xfffffffffffffffe,%rax
jmp    116e <COM_TrimString+0x6e>
add    $0xffffffffffffffff,%rax
mov    %eax,%ecx
jmp    1177 <COM_TrimString+0x77>
mov    $0xff,%ecx
lea    0x2eb2(%rip),%rax
movb   $0x0,(%rcx,%rax,1)
ret

LLVM IR (-O0):
@COM_TrimString.buffer = internal global [256 x i8] zeroinitializer
define i8* @COM_TrimString(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
br label %4
4: ; preds = %16, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp sle i32 %7, 32
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp sgt i32 %12, 0
br label %14
14: ; preds = %9, %4
%15 = phi i1 [ false, %4 ], [ %13, %9 ]
br i1 %15, label %16, label %19
16: ; preds = %14
%17 = load i8*, i8** %2
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %2
br label %4
19: ; preds = %14
store i32 0, i32* %3
br label %20
20: ; preds = %36, %19
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 255
br i1 %22, label %23, label %39
23: ; preds = %20
%24 = load i8*, i8** %2
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp sle i32 %26, 32
br i1 %27, label %28, label %29
28: ; preds = %23
br label %39
29: ; preds = %23
%30 = load i8*, i8** %2
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %2
%32 = load i8, i8* %30
%33 = load i32, i32* %3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [256 x i8], [256 x i8]* @COM_TrimString.buffer, i64 0, i64 %34
store i8 %32, i8* %35
br label %36
36: ; preds = %29
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
br label %20
39: ; preds = %28, %20
%40 = load i32, i32* %3
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [256 x i8], [256 x i8]* @COM_TrimString.buffer, i64 0, i64 %41
store i8 0, i8* %42
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @COM_TrimString.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@COM_TrimString.buffer = internal global [256 x i8] zeroinitializer
define i8* @COM_TrimString(i8* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %7, %2 ]
%4 = load i8, i8* %3
%5 = add i8 %4, -1
%6 = icmp ult i8 %5, 32
%7 = getelementptr inbounds i8, i8* %3, i64 1
br i1 %6, label %2, label %8
8: ; preds = %2
%9 = icmp slt i8 %4, 33
br i1 %9, label %36, label %10
10: ; preds = %8, %30
%11 = phi i8* [ %26, %30 ], [ %3, %8 ]
%12 = phi i64 [ %28, %30 ], [ 0, %8 ]
%13 = phi i8 [ %31, %30 ], [ %4, %8 ]
%14 = getelementptr inbounds [256 x i8], [256 x i8]* @COM_TrimString.buffer, i64 0, i64 %12
store i8 %13, i8* %14
%15 = add nuw nsw i64 %12, 1
%16 = getelementptr inbounds i8, i8* %11, i64 1
%17 = load i8, i8* %16
%18 = icmp slt i8 %17, 33
br i1 %18, label %33, label %19
19: ; preds = %10
%20 = getelementptr inbounds [256 x i8], [256 x i8]* @COM_TrimString.buffer, i64 0, i64 %15
store i8 %17, i8* %20
%21 = add nuw nsw i64 %12, 2
%22 = getelementptr inbounds i8, i8* %11, i64 2
%23 = load i8, i8* %22
%24 = icmp slt i8 %23, 33
br i1 %24, label %33, label %25
25: ; preds = %19
%26 = getelementptr inbounds i8, i8* %11, i64 3
%27 = getelementptr inbounds [256 x i8], [256 x i8]* @COM_TrimString.buffer, i64 0, i64 %21
store i8 %23, i8* %27
%28 = add nuw nsw i64 %12, 3
%29 = icmp eq i64 %28, 255
br i1 %29, label %36, label %30
30: ; preds = %25
%31 = load i8, i8* %26
%32 = icmp slt i8 %31, 33
br i1 %32, label %33, label %10
33: ; preds = %30, %19, %10
%34 = phi i64 [ %15, %10 ], [ %21, %19 ], [ %28, %30 ]
%35 = and i64 %34, 4294967295
br label %36
36: ; preds = %25, %33, %8
%37 = phi i64 [ %35, %33 ], [ 0, %8 ], [ 255, %25 ]
%38 = getelementptr inbounds [256 x i8], [256 x i8]* @COM_TrimString.buffer, i64 0, i64 %37
store i8 0, i8* %38
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @COM_TrimString.buffer, i64 0, i64 0)
}