#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);
char *strchr(char *, char);
char *trim_string(char *cline) {
  char *tmp;
  while (isspace(*cline)) {
    cline++;
  }
  tmp = strchr(cline, '\0') - 1;
  while (tmp >= cline && isspace(*tmp)) {
    *tmp-- = '\0';
  }
  return cline;
}


x86 assembly (clang, -O0):
<trim_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1153 <trim_string+0x33>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    112c <trim_string+0xc>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1030 <strchr@plt>
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x11(%rbp)
jb     118f <trim_string+0x6f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    119f <trim_string+0x7f>
jmp    11b6 <trim_string+0x96>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
jmp    1166 <trim_string+0x46>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_string>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rbx
nopl   0x0(%rax,%rax,1)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1040 <isspace@plt>
test   %rax,%rax
jne    1130 <trim_string+0x10>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%r14
add    $0xffffffffffffffff,%r14
cmp    %rbx,%r14
jb     117b <trim_string+0x5b>
nopw   0x0(%rax,%rax,1)
movsbl (%r14),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     117b <trim_string+0x5b>
movb   $0x0,(%r14)
add    $0xffffffffffffffff,%r14
cmp    %rbx,%r14
jae    1160 <trim_string+0x40>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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