#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 */
char *strchr(char *, char);
int /*<<< orphan*/ strspn(char *, char *);
char *strstrip(char *s) {
  char *e;
  s += strspn(s, " \t\n\r");
  for (e = strchr(s, 0); e > s; e--)
    if (!strchr(" \t\n\r", e[-1]))
      break;
  *e = 0;
  return s;
}


x86 assembly (clang, -O0):
<strstrip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec9(%rip),%rsi
call   1040 <strspn@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1030 <strchr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    11a2 <strstrip+0x82>
mov    -0x10(%rbp),%rax
lea    0xe8c(%rip),%rdi
movsbl -0x1(%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    118c <strstrip+0x6c>
jmp    11a2 <strstrip+0x82>
jmp    1191 <strstrip+0x71>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    115b <strstrip+0x3b>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstrip>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xebe(%rip),%r14
mov    %r14,%rsi
call   1050 <strspn@plt>
movslq %eax,%r15
add    %rbx,%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
add    %r15,%r12
xchg   %ax,%ax
mov    %r12,%rbx
cmp    %r15,%r12
jbe    117d <strstrip+0x4d>
lea    -0x1(%rbx),%r12
movsbl -0x1(%rbx),%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1160 <strstrip+0x30>
movb   $0x0,(%rbx)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c" \09\0A\0D\00"
define i8* @strstrip(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strspn(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = load i8*, i8** %2
%7 = sext i32 %5 to i64
%8 = getelementptr inbounds i8, i8* %6, i64 %7
store i8* %8, i8** %2
%9 = load i8*, i8** %2
%10 = call i8* @strchr(i8* %9, i8 signext 0)
store i8* %10, i8** %3
br label %11
11: ; preds = %23, %1
%12 = load i8*, i8** %3
%13 = load i8*, i8** %2
%14 = icmp ugt i8* %12, %13
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 -1
%18 = load i8, i8* %17
%19 = call i8* @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %18)
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %15
br label %26
22: ; preds = %15
br label %23
23: ; preds = %22
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 -1
store i8* %25, i8** %3
br label %11
26: ; preds = %21, %11
%27 = load i8*, i8** %3
store i8 0, i8* %27
%28 = load i8*, i8** %2
ret i8* %28
}

LLVM IR (-O2):
@.str = [5 x i8] c" \09\0A\0D\00"
define i8* @strstrip(i8* %0) {
%2 = tail call i32 @strspn(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = tail call i64 @strlen(i8* dereferenceable(1) %4)
%6 = getelementptr i8, i8* %4, i64 %5
br label %7
7: ; preds = %10, %1
%8 = phi i8* [ %6, %1 ], [ %11, %10 ]
%9 = icmp ugt i8* %8, %4
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %8, i64 -1
%12 = load i8, i8* %11
%13 = tail call i8* @strchr(i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %7
15: ; preds = %10, %7
store i8 0, i8* %8
ret i8* %4
}