#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 *);
void trim(char *s) {
  char *c = s + strlen(s) - 1;
  while (isspace(*c) && c > s) {
    *c = '\0';
    --c;
  }
  if (c == s && isspace(*c))
    *c = '\0';
  return;
}


x86 assembly (clang, -O0):
<trim>:
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
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     117d <trim+0x5d>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
seta   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    118d <trim+0x6d>
jmp    11a5 <trim+0x85>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1151 <trim+0x31>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    11d0 <trim+0xb0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11d0 <trim+0xb0>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
cltq
lea    (%r14,%rax,1),%rbx
add    $0xffffffffffffffff,%rbx
movsbl -0x1(%r14,%rax,1),%edi
nopl   0x0(%rax)
call   1040 <isspace@plt>
cmp    %r14,%rbx
jbe    115c <trim+0x3c>
test   %rax,%rax
je     115c <trim+0x3c>
movb   $0x0,(%rbx)
movsbl -0x1(%rbx),%edi
add    $0xffffffffffffffff,%rbx
jmp    1140 <trim+0x20>
cmp    %r14,%rbx
jne    1173 <trim+0x53>
movsbl (%r14),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1173 <trim+0x53>
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @trim(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
%9 = getelementptr inbounds i8, i8* %8, i64 -1
store i8* %9, i8** %3
br label %10
10: ; preds = %21, %1
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = call i64 @isspace(i8 signext %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i8*, i8** %2
%18 = icmp ugt i8* %16, %17
br label %19
19: ; preds = %15, %10
%20 = phi i1 [ false, %10 ], [ %18, %15 ]
br i1 %20, label %21, label %25
21: ; preds = %19
%22 = load i8*, i8** %3
store i8 0, i8* %22
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 -1
store i8* %24, i8** %3
br label %10
25: ; preds = %19
%26 = load i8*, i8** %3
%27 = load i8*, i8** %2
%28 = icmp eq i8* %26, %27
br i1 %28, label %29, label %36
29: ; preds = %25
%30 = load i8*, i8** %3
%31 = load i8, i8* %30
%32 = call i64 @isspace(i8 signext %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = load i8*, i8** %3
store i8 0, i8* %35
br label %36
36: ; preds = %34, %29, %25
ret void
}

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