#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 *isaac_trim_blanks(char *str) {
  char *work = str;
  if (work) {
    work += strlen(work) - 1;
    while ((work >= str) && *work < 33)
      *(work--) = '\0';
  }
  return str;
}


x86 assembly (clang, -O0):
<isaac_trim_blanks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119a <isaac_trim_blanks+0x8a>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x11(%rbp)
jb     116e <isaac_trim_blanks+0x5e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x21,%eax
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    117e <isaac_trim_blanks+0x6e>
jmp    1195 <isaac_trim_blanks+0x85>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
jmp    114b <isaac_trim_blanks+0x3b>
jmp    119a <isaac_trim_blanks+0x8a>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isaac_trim_blanks>:
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
je     1141 <isaac_trim_blanks+0x31>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1141 <isaac_trim_blanks+0x31>
add    $0xffffffff,%eax
add    %rbx,%rax
nopl   0x0(%rax,%rax,1)
cmpb   $0x20,(%rax)
jg     1141 <isaac_trim_blanks+0x31>
movb   $0x0,(%rax)
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jae    1130 <isaac_trim_blanks+0x20>
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @isaac_trim_blanks(i8* returned %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp slt i32 %4, 1
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = add nsw i32 %4, -1
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
br label %10
10: ; preds = %6, %14
%11 = phi i8* [ %15, %14 ], [ %9, %6 ]
%12 = load i8, i8* %11
%13 = icmp slt i8 %12, 33
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = getelementptr inbounds i8, i8* %11, i64 -1
store i8 0, i8* %11
%16 = icmp ult i8* %15, %0
br i1 %16, label %17, label %10
17: ; preds = %14, %10, %3, %1
ret i8* %0
}