#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 IsWhiteSpace(char);
int strlen(char *);
int StringTrimWhiteSpace(char *s) {
  int i;
  int length = strlen(s);
  for (i = length - 1; 1 == IsWhiteSpace(s[i]); i--) {
    length--;
  }
  s[length] = '\0';
  return length;
}


x86 assembly (clang, -O0):
<StringTrimWhiteSpace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <IsWhiteSpace@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    1178 <StringTrimWhiteSpace+0x58>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1141 <StringTrimWhiteSpace+0x21>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StringTrimWhiteSpace>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
cltq
lea    0x1(%rax),%r15d
lea    (%rax,%r14,1),%rbp
add    $0xffffffffffffffff,%rbp
shl    $0x20,%rax
movabs $0x100000000,%rbx
add    %rax,%rbx
movabs $0xffffffff00000000,%r12
ff ff ff
nopl   0x0(%rax)
add    %r12,%rbx
movsbl 0x0(%rbp),%edi
call   1040 <IsWhiteSpace@plt>
add    $0xffffffff,%r15d
add    $0xffffffffffffffff,%rbp
cmp    $0x1,%eax
je     1160 <StringTrimWhiteSpace+0x40>
sar    $0x20,%rbx
movb   $0x0,(%r14,%rbx,1)
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @StringTrimWhiteSpace(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = sub nsw i32 %7, 1
store i32 %8, i32* %3
br label %9
9: ; preds = %20, %1
%10 = load i8*, i8** %2
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = call i32 @IsWhiteSpace(i8 signext %14)
%16 = icmp eq i32 1, %15
br i1 %16, label %17, label %23
17: ; preds = %9
%18 = load i32, i32* %4
%19 = add nsw i32 %18, -1
store i32 %19, i32* %4
br label %20
20: ; preds = %17
%21 = load i32, i32* %3
%22 = add nsw i32 %21, -1
store i32 %22, i32* %3
br label %9
23: ; preds = %9
%24 = load i8*, i8** %2
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 0, i8* %27
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
define i32 @StringTrimWhiteSpace(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
br label %4
4: ; preds = %4, %1
%5 = phi i64 [ %6, %4 ], [ %3, %1 ]
%6 = add i64 %5, -1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = tail call i32 @IsWhiteSpace(i8 signext %8)
%10 = icmp eq i32 %9, 1
br i1 %10, label %4, label %11
11: ; preds = %4
%12 = trunc i64 %5 to i32
%13 = shl i64 %5, 32
%14 = ashr exact i64 %13, 32
%15 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 0, i8* %15
ret i32 %12
}