#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 str_len(char *);
char *str_trim(char *s) {
  char *t;
  t = s + str_len(s);
  *t-- = '\0';
  while ((*t > 0 && *t < 33) ? 1 : 0)
    *t-- = '\0';
  while ((*s > 0 && *s < 33) ? 1 : 0)
    s++;
  return s;
}


x86 assembly (clang, -O0):
<str_trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <str_len@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
jle    1174 <str_trim+0x64>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x21,%eax
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%dl
xor    %eax,%eax
mov    $0x1,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
cmp    $0x0,%eax
je     11a4 <str_trim+0x94>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
jmp    114f <str_trim+0x3f>
jmp    11a9 <str_trim+0x99>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1a(%rbp)
jle    11ce <str_trim+0xbe>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x21,%eax
setl   %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%dl
xor    %eax,%eax
mov    $0x1,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
cmp    $0x0,%eax
je     11f8 <str_trim+0xe8>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11a9 <str_trim+0x99>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_trim>:
push   %rbx
mov    %rdi,%rbx
call   1030 <str_len@plt>
cltq
movb   $0x0,(%rbx,%rax,1)
mov    -0x1(%rbx,%rax,1),%cl
add    $0xff,%cl
cmp    $0x1f,%cl
ja     1153 <str_trim+0x43>
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,(%rax)
movzbl -0x1(%rax),%ecx
add    $0xffffffffffffffff,%rax
add    $0xff,%cl
cmp    $0x20,%cl
jb     1140 <str_trim+0x30>
add    $0xffffffffffffffff,%rbx
nopw   0x0(%rax,%rax,1)
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
add    $0xff,%al
cmp    $0x20,%al
jb     1160 <str_trim+0x50>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @str_trim(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @str_len(i8* %5)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %4, i64 %7
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i32 -1
store i8* %10, i8** %3
store i8 0, i8* %9
br label %11
11: ; preds = %26, %1
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp slt i32 %19, 33
br label %21
21: ; preds = %16, %11
%22 = phi i1 [ false, %11 ], [ %20, %16 ]
%23 = zext i1 %22 to i64
%24 = select i1 %22, i32 1, i32 0
%25 = icmp ne i32 %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 %11
29: ; preds = %21
br label %30
30: ; preds = %45, %29
%31 = load i8*, i8** %2
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = load i8*, i8** %2
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp slt i32 %38, 33
br label %40
40: ; preds = %35, %30
%41 = phi i1 [ false, %30 ], [ %39, %35 ]
%42 = zext i1 %41 to i64
%43 = select i1 %41, i32 1, i32 0
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i8*, i8** %2
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %2
br label %30
48: ; preds = %40
%49 = load i8*, i8** %2
ret i8* %49
}

LLVM IR (-O2):
define i8* @str_trim(i8* %0) {
%2 = tail call i32 @str_len(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
store i8 0, i8* %4
%5 = getelementptr inbounds i8, i8* %4, i64 -1
%6 = load i8, i8* %5
%7 = add i8 %6, -1
%8 = icmp ult i8 %7, 32
br i1 %8, label %9, label %15
9: ; preds = %1, %9
%10 = phi i8* [ %11, %9 ], [ %5, %1 ]
store i8 0, i8* %10
%11 = getelementptr inbounds i8, i8* %10, i64 -1
%12 = load i8, i8* %11
%13 = add i8 %12, -1
%14 = icmp ult i8 %13, 32
br i1 %14, label %9, label %15
15: ; preds = %9, %1
br label %16
16: ; preds = %15, %16
%17 = phi i8* [ %21, %16 ], [ %0, %15 ]
%18 = load i8, i8* %17
%19 = add i8 %18, -1
%20 = icmp ult i8 %19, 32
%21 = getelementptr inbounds i8, i8* %17, i64 1
br i1 %20, label %16, label %22
22: ; preds = %16
ret i8* %17
}