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


x86 assembly (clang, -O0):
<_trim_tailling_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1139 <_trim_tailling_space+0x29>
jmp    11aa <_trim_tailling_space+0x9a>
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),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x19(%rbp)
jbe    1181 <_trim_tailling_space+0x71>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1191 <_trim_tailling_space+0x81>
jmp    11a2 <_trim_tailling_space+0x92>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    115e <_trim_tailling_space+0x4e>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_trim_tailling_space>:
push   %rbx
cmpb   $0x0,(%rdi)
je     1145 <_trim_tailling_space+0x35>
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rcx
add    $0xffffffffffffffff,%rcx
nopl   0x0(%rax,%rax,1)
mov    %rcx,%rax
cmp    %rbx,%rcx
jbe    1141 <_trim_tailling_space+0x31>
lea    -0x1(%rax),%rcx
cmpb   $0x20,(%rax)
je     1130 <_trim_tailling_space+0x20>
movb   $0x0,0x1(%rax)
pop    %rbx
ret

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

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