#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*/ isSpace(unsigned char);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, unsigned short);
int /*<<< orphan*/ memset(unsigned char *, int, unsigned short);
unsigned char trimSpace(unsigned char *s, unsigned short len) {
  unsigned char *p = s;
  unsigned char buf[256];
  unsigned short i = 0, j = 0;
  for (i = 0, j = 0; i < len; p++, i++) {
    if (!isSpace(*p)) {
      buf[j] = *p;
      j++;
    }
  }
  memset(s, 0x00, len);
  memcpy(s, buf, j + 1);
  return 0x00;
}


x86 assembly (clang, -O0):
<trimSpace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movw   $0x0,-0x122(%rbp)
movw   $0x0,-0x124(%rbp)
movw   $0x0,-0x122(%rbp)
movw   $0x0,-0x124(%rbp)
movzwl -0x122(%rbp),%eax
movzwl -0xa(%rbp),%ecx
cmp    %ecx,%eax
jge    11e8 <trimSpace+0xb8>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1050 <isSpace@plt>
cmp    $0x0,%eax
jne    11c0 <trimSpace+0x90>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
movzwl -0x124(%rbp),%eax
mov    %cl,-0x120(%rbp,%rax,1)
mov    -0x124(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x124(%rbp)
jmp    11c5 <trimSpace+0x95>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x122(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x122(%rbp)
jmp    1172 <trimSpace+0x42>
mov    -0x8(%rbp),%rdi
mov    -0xa(%rbp),%ax
movzwl %ax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x8(%rbp),%rdi
lea    -0x120(%rbp),%rsi
movzwl -0x124(%rbp),%eax
add    $0x1,%eax
movzwl %ax,%edx
call   1040 <memcpy@plt>
xor    %eax,%eax
movzbl %al,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trimSpace>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r15
movzwl %si,%r14d
test   %esi,%esi
je     117a <trimSpace+0x4a>
xor    %ebx,%ebx
xor    %r12d,%r12d
jmp    115a <trimSpace+0x2a>
add    $0x1,%rbx
cmp    %bx,%r14w
je     117d <trimSpace+0x4d>
movzbl (%r15,%rbx,1),%edi
call   1050 <isSpace@plt>
test   %eax,%eax
jne    1150 <trimSpace+0x20>
movzbl (%r15,%rbx,1),%eax
movzwl %r12w,%ecx
mov    %al,(%rsp,%rcx,1)
add    $0x1,%r12d
jmp    1150 <trimSpace+0x20>
xor    %r12d,%r12d
mov    %r15,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1030 <memset@plt>
add    $0x1,%r12d
movzwl %r12w,%edx
mov    %rsp,%rsi
mov    %r15,%rdi
call   1040 <memcpy@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define zeroext i8 @trimSpace(i8* %0, i16 zeroext %1) {
%3 = alloca i8*
%4 = alloca i16
%5 = alloca i8*
%6 = alloca [256 x i8]
%7 = alloca i16
%8 = alloca i16
store i8* %0, i8** %3
store i16 %1, i16* %4
%9 = load i8*, i8** %3
store i8* %9, i8** %5
store i16 0, i16* %7
store i16 0, i16* %8
store i16 0, i16* %7
store i16 0, i16* %8
br label %10
10: ; preds = %30, %2
%11 = load i16, i16* %7
%12 = zext i16 %11 to i32
%13 = load i16, i16* %4
%14 = zext i16 %13 to i32
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %35
16: ; preds = %10
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = call i32 @isSpace(i8 zeroext %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = load i8, i8* %22
%24 = load i16, i16* %8
%25 = zext i16 %24 to i64
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %25
store i8 %23, i8* %26
%27 = load i16, i16* %8
%28 = add i16 %27, 1
store i16 %28, i16* %8
br label %29
29: ; preds = %21, %16
br label %30
30: ; preds = %29
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %5
%33 = load i16, i16* %7
%34 = add i16 %33, 1
store i16 %34, i16* %7
br label %10
35: ; preds = %10
%36 = load i8*, i8** %3
%37 = load i16, i16* %4
%38 = call i32 @memset(i8* %36, i32 0, i16 zeroext %37)
%39 = load i8*, i8** %3
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%41 = load i16, i16* %8
%42 = zext i16 %41 to i32
%43 = add nsw i32 %42, 1
%44 = trunc i32 %43 to i16
%45 = call i32 @memcpy(i8* %39, i8* %40, i16 zeroext %44)
ret i8 0
}

LLVM IR (-O2):
define zeroext i8 @trimSpace(i8* %0, i16 zeroext %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp eq i16 %1, 0
br i1 %5, label %23, label %6
6: ; preds = %2, %18
%7 = phi i16 [ %19, %18 ], [ 0, %2 ]
%8 = phi i16 [ %21, %18 ], [ 0, %2 ]
%9 = phi i8* [ %20, %18 ], [ %0, %2 ]
%10 = load i8, i8* %9
%11 = tail call i32 @isSpace(i8 zeroext %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %6
%14 = load i8, i8* %9
%15 = zext i16 %7 to i64
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %15
store i8 %14, i8* %16
%17 = add i16 %7, 1
br label %18
18: ; preds = %6, %13
%19 = phi i16 [ %7, %6 ], [ %17, %13 ]
%20 = getelementptr inbounds i8, i8* %9, i64 1
%21 = add nuw i16 %8, 1
%22 = icmp eq i16 %21, %1
br i1 %22, label %23, label %6
23: ; preds = %18, %2
%24 = phi i16 [ 0, %2 ], [ %19, %18 ]
%25 = tail call i32 @memset(i8* %0, i32 0, i16 zeroext %1)
%26 = add i16 %24, 1
%27 = call i32 @memcpy(i8* %0, i8* %4, i16 zeroext %26)
ret i8 0
}