#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);
scalar_t__ strchr(char *, char);
int strlen(char *);
int strspn(char *, char *);
char *conf_trim(char *s) {
  int i;
  char *p;
  if (!s)
    return s;
  i = strspn(s, " \t\n\r");
  memmove(s, s + i, strlen(s + i) + 1);
  p = s + strlen(s) - 1;
  while ((p >= s) && strchr(" \t\n\r", *p))
    *p-- = '\0';
  return s;
}


x86 assembly (clang, -O0):
<conf_trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <conf_trim+0x24>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1234 <conf_trim+0xf4>
mov    -0x10(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1050 <strspn@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1060 <memmove@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x39(%rbp)
jb     1205 <conf_trim+0xc5>
mov    -0x20(%rbp),%rax
lea    0xe0d(%rip),%rdi
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1215 <conf_trim+0xd5>
jmp    122c <conf_trim+0xec>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
jmp    11d5 <conf_trim+0x95>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conf_trim>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
test   %rdi,%rdi
je     11bc <conf_trim+0x7c>
lea    0xeac(%rip),%rsi
mov    %r15,%rdi
call   1050 <strspn@plt>
movslq %eax,%r14
add    %r15,%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <memmove@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
lea    (%r15,%rax,1),%rbx
add    $0xffffffffffffffff,%rbx
cmp    %r15,%rbx
jb     11bc <conf_trim+0x7c>
lea    0xe6a(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
movsbl (%rbx),%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     11bc <conf_trim+0x7c>
movb   $0x0,(%rbx)
add    $0xffffffffffffffff,%rbx
cmp    %r15,%rbx
jae    11a0 <conf_trim+0x60>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c" \09\0A\0D\00"
define i8* @conf_trim(i8* returned %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %23, 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 i32 @strlen(i8* %6)
%8 = add nsw i32 %7, 1
%9 = tail call i32 @memmove(i8* %0, i8* %6, i32 %8)
%10 = tail call i32 @strlen(i8* %0)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = getelementptr inbounds i8, i8* %12, i64 -1
%14 = icmp ult i8* %13, %0
br i1 %14, label %23, label %15
15: ; preds = %3, %20
%16 = phi i8* [ %21, %20 ], [ %13, %3 ]
%17 = load i8, i8* %16
%18 = tail call i64 @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %15
store i8 0, i8* %16
%21 = getelementptr inbounds i8, i8* %16, i64 -1
%22 = icmp ult i8* %21, %0
br i1 %22, label %23, label %15
23: ; preds = %20, %15, %3, %1
ret i8* %0
}