#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 */
scalar_t__ isspace(unsigned char);
int strlen(char *);
void remove_space(char **pval) {
  unsigned char *p = (unsigned char *)*pval;
  while (isspace(*p))
    p++;
  *pval = (char *)p;
  p = p + strlen(*pval) - 1;
  while (isspace(*p))
    *p-- = 0;
}


x86 assembly (clang, -O0):
<remove_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     115e <remove_space+0x3e>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1137 <remove_space+0x17>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11be <remove_space+0x9e>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
jmp    1191 <remove_space+0x71>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_space>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rbx
add    $0xffffffffffffffff,%rbx
xchg   %ax,%ax
movzbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1040 <isspace@plt>
test   %rax,%rax
jne    1130 <remove_space+0x10>
mov    %rbx,(%r14)
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%r14
movzbl -0x1(%rbx,%r14,1),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     117a <remove_space+0x5a>
movb   $0x0,-0x1(%rbx,%r14,1)
movzbl -0x2(%rbx,%r14,1),%edi
call   1040 <isspace@plt>
add    $0xffffffffffffffff,%r14
test   %rax,%rax
jne    1160 <remove_space+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @remove_space(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
store i8** %0, i8*** %2
%4 = load i8**, i8*** %2
%5 = load i8*, i8** %4
store i8* %5, i8** %3
br label %6
6: ; preds = %11, %1
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = call i64 @isspace(i8 zeroext %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %3
br label %6
14: ; preds = %6
%15 = load i8*, i8** %3
%16 = load i8**, i8*** %2
store i8* %15, i8** %16
%17 = load i8*, i8** %3
%18 = load i8**, i8*** %2
%19 = load i8*, i8** %18
%20 = call i32 @strlen(i8* %19)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %17, i64 %21
%23 = getelementptr inbounds i8, i8* %22, i64 -1
store i8* %23, i8** %3
br label %24
24: ; preds = %29, %14
%25 = load i8*, i8** %3
%26 = load i8, i8* %25
%27 = call i64 @isspace(i8 zeroext %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i32 -1
store i8* %31, i8** %3
store i8 0, i8* %30
br label %24
32: ; preds = %24
ret void
}

LLVM IR (-O2):
define void @remove_space(i8** nocapture %0) {
%2 = load i8*, i8** %0
br label %3
3: ; preds = %3, %1
%4 = phi i8* [ %2, %1 ], [ %8, %3 ]
%5 = load i8, i8* %4
%6 = tail call i64 @isspace(i8 zeroext %5)
%7 = icmp eq i64 %6, 0
%8 = getelementptr inbounds i8, i8* %4, i64 1
br i1 %7, label %9, label %3
9: ; preds = %3
store i8* %4, i8** %0
%10 = tail call i32 @strlen(i8* %4)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %4, i64 %11
%13 = getelementptr inbounds i8, i8* %12, i64 -1
%14 = load i8, i8* %13
%15 = tail call i64 @isspace(i8 zeroext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %9, %17
%18 = phi i8* [ %19, %17 ], [ %13, %9 ]
store i8 0, i8* %18
%19 = getelementptr inbounds i8, i8* %18, i64 -1
%20 = load i8, i8* %19
%21 = tail call i64 @isspace(i8 zeroext %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %17
23: ; preds = %17, %9
ret void
}