#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 */
int /*<<< orphan*/ memmove(char *, char *, int);
int /*<<< orphan*/ *strchr(char *, char);
int strlen(char *);
void strstrip(char *str) {
  char *i;
  if (str == NULL)
    return;
  for (i = str; i[0] != '\0' && strchr(" \n\r\t", i[0]) != NULL; i++)
    ;
  if (i[0] != '\0') {
    memmove(str, i, strlen(i) + 1);
    for (i = str + strlen(str) - 1; strchr(" \n\r\t", i[0]) != NULL; i--)
      ;
    i[1] = '\0';
  } else
    str[0] = '\0';
}


x86 assembly (clang, -O0):
<strstrip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114c <strstrip+0x1c>
jmp    1253 <strstrip+0x123>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     1186 <strstrip+0x56>
mov    -0x10(%rbp),%rax
lea    0xe8c(%rip),%rdi
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1196 <strstrip+0x66>
jmp    11ac <strstrip+0x7c>
jmp    119b <strstrip+0x6b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1154 <strstrip+0x24>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     124c <strstrip+0x11c>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1050 <memmove@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <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
lea    0xde9(%rip),%rdi
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     123f <strstrip+0x10f>
jmp    122e <strstrip+0xfe>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    120c <strstrip+0xdc>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    1253 <strstrip+0x123>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstrip>:
test   %rdi,%rdi
je     11df <strstrip+0xaf>
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    (%rdi),%al
test   %al,%al
je     11d6 <strstrip+0xa6>
lea    0xeae(%rip),%r15
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%esi
mov    %r15,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     117e <strstrip+0x4e>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <strstrip+0x30>
jmp    11d6 <strstrip+0xa6>
cmpb   $0x0,(%rbx)
je     11d6 <strstrip+0xa6>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <memmove@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%r14
add    $0x1,%r14
lea    0xe4f(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl -0x2(%r14),%esi
mov    %rbx,%rdi
call   1040 <strchr@plt>
add    $0xffffffffffffffff,%r14
test   %rax,%rax
jne    11c0 <strstrip+0x90>
movb   $0x0,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

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

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