#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*/ isword(char);
int strlen(char *);
char *trim(char *in) {
  char *trimmed = in;
  for (; !isword(*trimmed) && *trimmed != '\0'; trimmed++) {
  }
  char *end = &in[strlen(in) - 1];
  for (; !isword(*end); end--) {
  }
  if (*end != '\0') {
    *(end + 1) = '\0';
  }
  return trimmed;
}


x86 assembly (clang, -O0):
<trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isword@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
jne    1160 <trim+0x40>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1170 <trim+0x50>
jmp    1186 <trim+0x66>
jmp    1175 <trim+0x55>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1134 <trim+0x14>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isword@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11cb <trim+0xab>
jmp    11e1 <trim+0xc1>
jmp    11d0 <trim+0xb0>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11aa <trim+0x8a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f9 <trim+0xd9>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
movsbl (%rdi),%edi
call   1030 <isword@plt>
mov    %r14,%r15
test   %eax,%eax
jne    1158 <trim+0x38>
mov    %r14,%r15
nopw   0x0(%rax,%rax,1)
cmpb   $0x0,(%r15)
je     1158 <trim+0x38>
movsbl 0x1(%r15),%edi
add    $0x1,%r15
call   1030 <isword@plt>
test   %eax,%eax
je     1140 <trim+0x20>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rax,%r14,1),%rbx
add    $0x1,%rbx
nopw   0x0(%rax,%rax,1)
movsbl -0x2(%rbx),%edi
call   1030 <isword@plt>
add    $0xffffffffffffffff,%rbx
test   %eax,%eax
je     1170 <trim+0x50>
cmpb   $0x0,-0x1(%rbx)
je     118a <trim+0x6a>
movb   $0x0,(%rbx)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @trim(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %3
br label %6
6: ; preds = %19, %1
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = call i32 @isword(i8 signext %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br label %16
16: ; preds = %11, %6
%17 = phi i1 [ false, %6 ], [ %15, %11 ]
br i1 %17, label %18, label %22
18: ; preds = %16
br label %19
19: ; preds = %18
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %3
br label %6
22: ; preds = %16
%23 = load i8*, i8** %2
%24 = load i8*, i8** %2
%25 = call i32 @strlen(i8* %24)
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %23, i64 %27
store i8* %28, i8** %4
br label %29
29: ; preds = %36, %22
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = call i32 @isword(i8 signext %31)
%33 = icmp ne i32 %32, 0
%34 = xor i1 %33, true
br i1 %34, label %35, label %39
35: ; preds = %29
br label %36
36: ; preds = %35
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 -1
store i8* %38, i8** %4
br label %29
39: ; preds = %29
%40 = load i8*, i8** %4
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i64 1
store i8 0, i8* %46
br label %47
47: ; preds = %44, %39
%48 = load i8*, i8** %3
ret i8* %48
}

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