#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 *str) {
  char *p;
  if (str) {
    str += strspn(str, " \t\n\r");
    for (p = strchr(str, '\0'); p > str; p--) {
      if (!strchr(" \t\n\r", p[-1]))
        break;
    }
    *p = '\0';
  }
  return str;
}


x86 assembly (clang, -O0):
<strstrip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11b4 <strstrip+0x94>
mov    -0x8(%rbp),%rdi
lea    0xebe(%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    11ad <strstrip+0x8d>
mov    -0x10(%rbp),%rax
lea    0xe81(%rip),%rdi
movsbl -0x1(%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    1197 <strstrip+0x77>
jmp    11ad <strstrip+0x8d>
jmp    119c <strstrip+0x7c>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1166 <strstrip+0x46>
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
test   %rdi,%rdi
je     1192 <strstrip+0x62>
mov    %rdi,%rbx
lea    0xeb9(%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
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rbx
cmp    %r15,%r12
jbe    118d <strstrip+0x5d>
lea    -0x1(%rbx),%r12
movsbl -0x1(%rbx),%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1170 <strstrip+0x40>
movb   $0x0,(%rbx)
jmp    1195 <strstrip+0x65>
xor    %r15d,%r15d
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 = icmp ne i8* %4, null
br i1 %5, label %6, label %31
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = call i32 @strspn(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** %2
%10 = sext i32 %8 to i64
%11 = getelementptr inbounds i8, i8* %9, i64 %10
store i8* %11, i8** %2
%12 = load i8*, i8** %2
%13 = call i8* @strchr(i8* %12, i8 signext 0)
store i8* %13, i8** %3
br label %14
14: ; preds = %26, %6
%15 = load i8*, i8** %3
%16 = load i8*, i8** %2
%17 = icmp ugt i8* %15, %16
br i1 %17, label %18, label %29
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 -1
%21 = load i8, i8* %20
%22 = call i8* @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %21)
%23 = icmp ne i8* %22, null
br i1 %23, label %25, label %24
24: ; preds = %18
br label %29
25: ; preds = %18
br label %26
26: ; preds = %25
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i32 -1
store i8* %28, i8** %3
br label %14
29: ; preds = %24, %14
%30 = load i8*, i8** %3
store i8 0, i8* %30
br label %31
31: ; preds = %29, %1
%32 = load i8*, i8** %2
ret i8* %32
}

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