#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__ isspace(unsigned char);
void clean_spc(char *str) {
  char *p;
  p = str;
  while (*p) {
    p++;
  }
  p--;
  while (p >= str && isspace((unsigned char)*p)) {
    *p = '\0';
    p--;
  }
  return;
}


x86 assembly (clang, -O0):
<clean_spc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1142 <clean_spc+0x32>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <clean_spc+0x14>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x11(%rbp)
jb     1177 <clean_spc+0x67>
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1187 <clean_spc+0x77>
jmp    119f <clean_spc+0x8f>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    114e <clean_spc+0x3e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clean_spc>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    -0x2(%rdi),%rbx
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,0x2(%rbx)
lea    0x1(%rbx),%rbx
jne    1120 <clean_spc+0x10>
jmp    1137 <clean_spc+0x27>
nopl   0x0(%rax)
movb   $0x0,(%rbx)
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jb     1149 <clean_spc+0x39>
movzbl (%rbx),%edi
call   1030 <isspace@plt>
test   %rax,%rax
jne    1130 <clean_spc+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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