#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 strlen(char *);
char *trim_left(char *);
char *trim_left_right(char *cp) {
  char *q;
  char c;
  cp = trim_left(cp);
  q = cp + strlen(cp);
  while (cp < q) {
    c = *(--q);
    if (c != ' ' && c != '\t') {
      *(++q) = '\0';
      break;
    }
  }
  return cp;
}


x86 assembly (clang, -O0):
<trim_left_right>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <trim_left@plt>
mov    %rax,-0x8(%rbp)
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
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11b4 <trim_left_right+0x94>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
mov    -0x1(%rax),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x20,%eax
je     11af <trim_left_right+0x8f>
movsbl -0x11(%rbp),%eax
cmp    $0x9,%eax
je     11af <trim_left_right+0x8f>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,0x1(%rax)
jmp    11b4 <trim_left_right+0x94>
jmp    115a <trim_left_right+0x3a>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_left_right>:
push   %rbx
call   1040 <trim_left@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    115a <trim_left_right+0x3a>
mov    %eax,%eax
add    %rbx,%rax
jmp    1149 <trim_left_right+0x29>
nopl   0x0(%rax)
add    $0xffffffffffffffff,%rax
cmp    %rax,%rbx
jae    115a <trim_left_right+0x3a>
movzbl -0x1(%rax),%ecx
cmp    $0x20,%cl
je     1140 <trim_left_right+0x20>
cmp    $0x9,%cl
je     1140 <trim_left_right+0x20>
movb   $0x0,(%rax)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @trim_left_right(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @trim_left(i8* %5)
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
store i8* %11, i8** %3
br label %12
12: ; preds = %30, %1
%13 = load i8*, i8** %2
%14 = load i8*, i8** %3
%15 = icmp ult i8* %13, %14
br i1 %15, label %16, label %31
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 -1
store i8* %18, i8** %3
%19 = load i8, i8* %18
store i8 %19, i8* %4
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 32
br i1 %22, label %23, label %30
23: ; preds = %16
%24 = load i8, i8* %4
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 9
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %3
store i8 0, i8* %29
br label %31
30: ; preds = %23, %16
br label %12
31: ; preds = %27, %12
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
define i8* @trim_left_right(i8* %0) {
%2 = tail call i8* @trim_left(i8* %0)
%3 = tail call i32 @strlen(i8* %2)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %15
5: ; preds = %1
%6 = zext i32 %3 to i64
%7 = getelementptr inbounds i8, i8* %2, i64 %6
br label %8
8: ; preds = %5, %12
%9 = phi i8* [ %10, %12 ], [ %7, %5 ]
%10 = getelementptr inbounds i8, i8* %9, i64 -1
%11 = load i8, i8* %10
switch i8 %11, label %14 [
i8 32, label %12
i8 9, label %12
]
12: ; preds = %8, %8
%13 = icmp ult i8* %2, %10
br i1 %13, label %8, label %15
14: ; preds = %8
store i8 0, i8* %9
br label %15
15: ; preds = %12, %1, %14
ret i8* %2
}