#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_str(char *str) {
  char *s = str + strlen(str) - 1;
  while (*s == '\t' || *s == ' ' || *s == '{') {
    *s = '\0';
    s--;
  }
  return str;
}


x86 assembly (clang, -O0):
<trim_str>:
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 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x9,%ecx
mov    %al,-0x19(%rbp)
je     117b <trim_str+0x6b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x19(%rbp)
je     117b <trim_str+0x6b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7b,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    118b <trim_str+0x7b>
jmp    11a3 <trim_str+0x93>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1141 <trim_str+0x31>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_str>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
jmp    1137 <trim_str+0x27>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movb   $0x0,(%rax)
add    $0xffffffffffffffff,%rax
movzbl (%rax),%ecx
cmp    $0x9,%cl
je     1130 <trim_str+0x20>
cmp    $0x7b,%cl
je     1130 <trim_str+0x20>
cmp    $0x20,%cl
je     1130 <trim_str+0x20>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @trim_str(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 @strlen(i8* %5)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %4, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 -1
store i8* %9, i8** %3
br label %10
10: ; preds = %27, %1
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 9
br i1 %14, label %25, label %15
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 32
br i1 %19, label %25, label %20
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 123
br label %25
25: ; preds = %20, %15, %10
%26 = phi i1 [ true, %15 ], [ true, %10 ], [ %24, %20 ]
br i1 %26, label %27, label %31
27: ; preds = %25
%28 = load i8*, i8** %3
store i8 0, i8* %28
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i32 -1
store i8* %30, i8** %3
br label %10
31: ; preds = %25
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
define i8* @trim_str(i8* returned %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
br label %5
5: ; preds = %9, %1
%6 = phi i8* [ %4, %1 ], [ %7, %9 ]
%7 = getelementptr inbounds i8, i8* %6, i64 -1
%8 = load i8, i8* %7
switch i8 %8, label %10 [
i8 9, label %9
i8 32, label %9
i8 123, label %9
]
9: ; preds = %5, %5, %5
store i8 0, i8* %7
br label %5
10: ; preds = %5
ret i8* %0
}