#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*/ memcpy(char *, char *, int);
int strlen(char *);
scalar_t__ xmallocd(int, char *);
char *spod_trim(char *c) {
  char *start, *end, *ret;
  start = c;
  end = c + strlen(c);
  while (isspace(*start))
    start++;
  while (isspace(*(end - 1)) && end > start)
    end--;
  ret = (char *)xmallocd(end - start + 1, "spod");
  memcpy(ret, start, end - start);
  ret[end - start] = 0;
  return ret;
}


x86 assembly (clang, -O0):
<spod_trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     119c <spod_trim+0x5c>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1175 <spod_trim+0x35>
jmp    11a1 <spod_trim+0x61>
mov    -0x18(%rbp),%rax
movsbl -0x1(%rax),%edi
call   1040 <isspace@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x29(%rbp)
je     11ce <spod_trim+0x8e>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
seta   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11de <spod_trim+0x9e>
jmp    11ef <spod_trim+0xaf>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11a1 <spod_trim+0x61>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
lea    0xdf9(%rip),%rsi
call   1060 <xmallocd@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spod_trim>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
movslq %eax,%r12
lea    0x2(%r12),%rbx
lea    -0x1(%r15),%r14
nopl   0x0(%rax)
movsbl 0x1(%r14),%edi
add    $0x1,%r14
call   1040 <isspace@plt>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    1160 <spod_trim+0x20>
add    %r12,%r15
nopw   0x0(%rax,%rax,1)
movsbl -0x1(%r15),%edi
call   1040 <isspace@plt>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
je     119f <spod_trim+0x5f>
lea    -0x1(%r15),%rax
cmp    %r14,%r15
mov    %rax,%r15
ja     1180 <spod_trim+0x40>
lea    0x1(%rbx),%edi
lea    0xe57(%rip),%rsi
call   1060 <xmallocd@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"spod\00"
define i8* @spod_trim(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %3
%7 = load i8*, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
store i8* %11, i8** %4
br label %12
12: ; preds = %17, %1
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = call i64 @isspace(i8 signext %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %3
br label %12
20: ; preds = %12
br label %21
21: ; preds = %33, %20
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 -1
%24 = load i8, i8* %23
%25 = call i64 @isspace(i8 signext %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i8*, i8** %4
%29 = load i8*, i8** %3
%30 = icmp ugt i8* %28, %29
br label %31
31: ; preds = %27, %21
%32 = phi i1 [ false, %21 ], [ %30, %27 ]
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i32 -1
store i8* %35, i8** %4
br label %21
36: ; preds = %31
%37 = load i8*, i8** %4
%38 = load i8*, i8** %3
%39 = ptrtoint i8* %37 to i64
%40 = ptrtoint i8* %38 to i64
%41 = sub i64 %39, %40
%42 = add nsw i64 %41, 1
%43 = trunc i64 %42 to i32
%44 = call i64 @xmallocd(i32 %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%45 = inttoptr i64 %44 to i8*
store i8* %45, i8** %5
%46 = load i8*, i8** %5
%47 = load i8*, i8** %3
%48 = load i8*, i8** %4
%49 = load i8*, i8** %3
%50 = ptrtoint i8* %48 to i64
%51 = ptrtoint i8* %49 to i64
%52 = sub i64 %50, %51
%53 = trunc i64 %52 to i32
%54 = call i32 @memcpy(i8* %46, i8* %47, i32 %53)
%55 = load i8*, i8** %5
%56 = load i8*, i8** %4
%57 = load i8*, i8** %3
%58 = ptrtoint i8* %56 to i64
%59 = ptrtoint i8* %57 to i64
%60 = sub i64 %58, %59
%61 = getelementptr inbounds i8, i8* %55, i64 %60
store i8 0, i8* %61
%62 = load i8*, i8** %5
ret i8* %62
}

LLVM IR (-O2):
@.str = [5 x i8] c"spod\00"
define i8* @spod_trim(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
br label %4
4: ; preds = %4, %1
%5 = phi i8* [ %0, %1 ], [ %9, %4 ]
%6 = load i8, i8* %5
%7 = tail call i64 @isspace(i8 signext %6)
%8 = icmp eq i64 %7, 0
%9 = getelementptr inbounds i8, i8* %5, i64 1
br i1 %8, label %10, label %4
10: ; preds = %4
%11 = getelementptr inbounds i8, i8* %0, i64 %3
br label %12
12: ; preds = %10, %12
%13 = phi i8* [ %14, %12 ], [ %11, %10 ]
%14 = getelementptr inbounds i8, i8* %13, i64 -1
%15 = load i8, i8* %14
%16 = tail call i64 @isspace(i8 signext %15)
%17 = icmp ne i64 %16, 0
%18 = icmp ugt i8* %13, %5
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %12, label %20
20: ; preds = %12
%21 = ptrtoint i8* %13 to i64
%22 = ptrtoint i8* %5 to i64
%23 = sub i64 %21, %22
%24 = trunc i64 %23 to i32
%25 = add i32 %24, 1
%26 = tail call i64 @xmallocd(i32 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%27 = inttoptr i64 %26 to i8*
%28 = tail call i32 @memcpy(i8* %27, i8* %5, i32 %24)
%29 = getelementptr inbounds i8, i8* %27, i64 %23
store i8 0, i8* %29
ret i8* %27
}