#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__ iswhitespace(char);
int strlen(char *);
char *str_eatwhitespace(char *str) {
  char *p, *ret = str;
  while (iswhitespace(*ret))
    ret++;
  p = ret + strlen(ret) - 1;
  while (iswhitespace(*p))
    *p-- = 0;
  return (ret);
}


x86 assembly (clang, -O0):
<str_eatwhitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <iswhitespace@plt>
cmp    $0x0,%rax
je     115b <str_eatwhitespace+0x3b>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1134 <str_eatwhitespace+0x14>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <iswhitespace@plt>
cmp    $0x0,%rax
je     11ad <str_eatwhitespace+0x8d>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
jmp    1180 <str_eatwhitespace+0x60>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_eatwhitespace>:
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   1030 <iswhitespace@plt>
test   %rax,%rax
jne    1130 <str_eatwhitespace+0x10>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%r14
movsbl -0x1(%rbx,%r14,1),%edi
call   1030 <iswhitespace@plt>
test   %rax,%rax
je     117a <str_eatwhitespace+0x5a>
nopl   (%rax)
movb   $0x0,-0x1(%rbx,%r14,1)
movsbl -0x2(%rbx,%r14,1),%edi
call   1030 <iswhitespace@plt>
add    $0xffffffffffffffff,%r14
test   %rax,%rax
jne    1160 <str_eatwhitespace+0x40>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @str_eatwhitespace(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** %4
br label %6
6: ; preds = %11, %1
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = call i64 @iswhitespace(i8 signext %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %4
br label %6
14: ; preds = %6
%15 = load i8*, i8** %4
%16 = load i8*, i8** %4
%17 = call i32 @strlen(i8* %16)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 -1
store i8* %20, i8** %3
br label %21
21: ; preds = %26, %14
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = call i64 @iswhitespace(i8 signext %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i32 -1
store i8* %28, i8** %3
store i8 0, i8* %27
br label %21
29: ; preds = %21
%30 = load i8*, i8** %4
ret i8* %30
}

LLVM IR (-O2):
define i8* @str_eatwhitespace(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 @iswhitespace(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 i32 @strlen(i8* %3)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %3, i64 %10
%12 = getelementptr inbounds i8, i8* %11, i64 -1
%13 = load i8, i8* %12
%14 = tail call i64 @iswhitespace(i8 signext %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %8, %16
%17 = phi i8* [ %18, %16 ], [ %12, %8 ]
store i8 0, i8* %17
%18 = getelementptr inbounds i8, i8* %17, i64 -1
%19 = load i8, i8* %18
%20 = tail call i64 @iswhitespace(i8 signext %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %16
22: ; preds = %16, %8
ret i8* %3
}