#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 */
scalar_t__ iscntrl(char);
int strlen(char *);
char *trimr(char *string) {
  int i = strlen(string) - 1;
  while ((i >= 0) &&
         (iscntrl(string[i]) || (string[i] == ' ') || (string[i] == '\t')))
    string[i--] = '\0';
  return string;
}


x86 assembly (clang, -O0):
<trimr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0xd(%rbp)
jl     11a2 <trimr+0x82>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <iscntrl@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0xe(%rbp)
jne    119c <trimr+0x7c>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0xe(%rbp)
je     119c <trimr+0x7c>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    11b2 <trimr+0x92>
jmp    11cd <trimr+0xad>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0xc(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    113b <trimr+0x1b>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trimr>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
test   %eax,%eax
jle    116f <trimr+0x4f>
mov    %eax,%ebx
add    $0x1,%rbx
jmp    114f <trimr+0x2f>
nopl   0x0(%rax)
movb   $0x0,(%r14,%r15,1)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jbe    116f <trimr+0x4f>
lea    -0x2(%rbx),%r15d
movsbl (%r14,%r15,1),%edi
call   1030 <iscntrl@plt>
test   %rax,%rax
jne    1140 <trimr+0x20>
movzbl (%r14,%r15,1),%eax
cmp    $0x20,%al
je     1140 <trimr+0x20>
cmp    $0x9,%al
je     1140 <trimr+0x20>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @trimr(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
%6 = sub nsw i32 %5, 1
store i32 %6, i32* %3
br label %7
7: ; preds = %38, %1
%8 = load i32, i32* %3
%9 = icmp sge i32 %8, 0
br i1 %9, label %10, label %36
10: ; preds = %7
%11 = load i8*, i8** %2
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = call i64 @iscntrl(i8 signext %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %34, label %18
18: ; preds = %10
%19 = load i8*, i8** %2
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 32
br i1 %25, label %34, label %26
26: ; preds = %18
%27 = load i8*, i8** %2
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 9
br label %34
34: ; preds = %26, %18, %10
%35 = phi i1 [ true, %18 ], [ true, %10 ], [ %33, %26 ]
br label %36
36: ; preds = %34, %7
%37 = phi i1 [ false, %7 ], [ %35, %34 ]
br i1 %37, label %38, label %44
38: ; preds = %36
%39 = load i8*, i8** %2
%40 = load i32, i32* %3
%41 = add nsw i32 %40, -1
store i32 %41, i32* %3
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
store i8 0, i8* %43
br label %7
44: ; preds = %36
%45 = load i8*, i8** %2
ret i8* %45
}

LLVM IR (-O2):
define i8* @trimr(i8* returned %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %18
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %16
%7 = phi i64 [ %5, %4 ], [ %8, %16 ]
%8 = add nsw i64 %7, -1
%9 = and i64 %8, 4294967295
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i64 @iscntrl(i8 signext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = load i8, i8* %10
switch i8 %15, label %18 [
i8 32, label %16
i8 9, label %16
]
16: ; preds = %14, %14, %6
store i8 0, i8* %10
%17 = icmp ugt i64 %7, 1
br i1 %17, label %6, label %18
18: ; preds = %16, %14, %1
ret i8* %0
}