#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 /*<<< orphan*/ isspace(char);
int strlen(char *);
char *strcrop(char *string) {
  char *last;
  if (string) {
    last = string + strlen(string);
    while (last > string) {
      if (!isspace(*(last - 1)))
        break;
      last--;
    }
    *last = 0;
  }
  return (string);
}


x86 assembly (clang, -O0):
<strcrop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1199 <strcrop+0x79>
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
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    1192 <strcrop+0x72>
mov    -0x10(%rbp),%rax
movsbl -0x1(%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
jne    1181 <strcrop+0x61>
jmp    1192 <strcrop+0x72>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1158 <strcrop+0x38>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcrop>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
test   %rdi,%rdi
je     115c <strcrop+0x3c>
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%r15
add    %r14,%r15
nopl   0x0(%rax,%rax,1)
mov    %r15,%rbx
cmp    %r14,%r15
jbe    1159 <strcrop+0x39>
lea    -0x1(%rbx),%r15
movsbl -0x1(%rbx),%edi
call   1040 <isspace@plt>
test   %eax,%eax
jne    1140 <strcrop+0x20>
movb   $0x0,(%rbx)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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