#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 strlen(char *);
char *strim(char *s) {
  char *e = s + strlen(s);
  while (e > s && isspace(e[-1]))
    --e;
  *e = 0;
  while (isspace(*s))
    ++s;
  return s;
}


x86 assembly (clang, -O0):
<strim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x19(%rbp)
jbe    1177 <strim+0x57>
mov    -0x10(%rbp),%rax
movsbl -0x1(%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1187 <strim+0x67>
jmp    1198 <strim+0x78>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    114d <strim+0x2d>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11c6 <strim+0xa6>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    119f <strim+0x7f>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strim>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %eax,%r15
add    %rbx,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%r14
cmp    %rbx,%r15
jbe    115b <strim+0x3b>
lea    -0x1(%r14),%r15
movsbl -0x1(%r14),%edi
call   1040 <isspace@plt>
test   %rax,%rax
jne    1140 <strim+0x20>
movb   $0x0,(%r14)
add    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1040 <isspace@plt>
test   %rax,%rax
jne    1170 <strim+0x50>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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