#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(char);
int /*<<< orphan*/ memmove(char *, char *, scalar_t__);
char *str_spc_skip(char *);
scalar_t__ strlen(char *);
void str_trim(char *str) {
  char *s = str_spc_skip(str);
  memmove(str, s, strlen(s) + 1);
  for (s = str; *s; s++)
    ;
  while (s > str && isspace(*s))
    s--;
  *s = '\0';
}


x86 assembly (clang, -O0):
<str_trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <str_spc_skip@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1060 <memmove@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b1 <str_trim+0x71>
jmp    11a0 <str_trim+0x60>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    118e <str_trim+0x4e>
jmp    11b6 <str_trim+0x76>
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x21(%rbp)
jbe    11df <str_trim+0x9f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11ef <str_trim+0xaf>
jmp    1200 <str_trim+0xc0>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    11b6 <str_trim+0x76>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_trim>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1030 <str_spc_skip@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <memmove@plt>
lea    -0x1(%r15),%rbx
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    1170 <str_trim+0x30>
cmp    %r15,%rbx
jbe    11b9 <str_trim+0x79>
xor    %edi,%edi
call   1050 <isspace@plt>
test   %rax,%rax
je     11b9 <str_trim+0x79>
add    $0xffffffffffffffff,%rbx
mov    %rbx,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rcx,%rbx
cmp    %r15,%rcx
jbe    11b9 <str_trim+0x79>
movsbl (%rbx),%edi
call   1050 <isspace@plt>
lea    -0x1(%rbx),%rcx
test   %rax,%rax
jne    11a0 <str_trim+0x60>
movb   $0x0,(%rbx)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @str_trim(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i8* @str_spc_skip(i8* %4)
store i8* %5, i8** %3
%6 = load i8*, i8** %2
%7 = load i8*, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 %9, 1
%11 = call i32 @memmove(i8* %6, i8* %7, i64 %10)
%12 = load i8*, i8** %2
store i8* %12, i8** %3
br label %13
13: ; preds = %18, %1
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
br label %18
18: ; preds = %17
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
br label %13
21: ; preds = %13
br label %22
22: ; preds = %33, %21
%23 = load i8*, i8** %3
%24 = load i8*, i8** %2
%25 = icmp ugt i8* %23, %24
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i8*, i8** %3
%28 = load i8, i8* %27
%29 = call i64 @isspace(i8 signext %28)
%30 = icmp ne i64 %29, 0
br label %31
31: ; preds = %26, %22
%32 = phi i1 [ false, %22 ], [ %30, %26 ]
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i32 -1
store i8* %35, i8** %3
br label %22
36: ; preds = %31
%37 = load i8*, i8** %3
store i8 0, i8* %37
ret void
}

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