#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);
void remove_trailing(char s[]) {
  char *end;
  end = s;
  while (*s) {
    if (!isspace(*s))
      end += s - end;
    ++s;
  }
  if (!isspace(*end))
    ++end;
  *end = '\0';
}


x86 assembly (clang, -O0):
<remove_trailing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     116a <remove_trailing+0x5a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%eax
jne    1159 <remove_trailing+0x49>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1124 <remove_trailing+0x14>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%eax
jne    118b <remove_trailing+0x7b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_trailing>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%al
test   %al,%al
je     115e <remove_trailing+0x4e>
lea    0x1(%rbx),%r14
xor    %r15d,%r15d
mov    %rbx,%r12
nopl   0x0(%rax)
mov    %rbx,%r13
movsbl %al,%edi
call   1030 <isspace@plt>
mov    %r12,%rbx
sub    %r13,%rbx
test   %eax,%eax
cmovne %r15,%rbx
add    %r13,%rbx
movzbl (%r14),%eax
add    $0x1,%r14
add    $0x1,%r12
test   %al,%al
jne    1130 <remove_trailing+0x20>
mov    (%rbx),%al
jmp    1160 <remove_trailing+0x50>
xor    %eax,%eax
movsbl %al,%edi
call   1030 <isspace@plt>
cmp    $0x1,%eax
adc    $0x0,%rbx
movb   $0x0,(%rbx)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @remove_trailing(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 = %22, %1
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %5
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = call i32 @isspace(i8 signext %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %9
%15 = load i8*, i8** %2
%16 = load i8*, i8** %3
%17 = ptrtoint i8* %15 to i64
%18 = ptrtoint i8* %16 to i64
%19 = sub i64 %17, %18
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 %19
store i8* %21, i8** %3
br label %22
22: ; preds = %14, %9
%23 = load i8*, i8** %2
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %2
br label %5
25: ; preds = %5
%26 = load i8*, i8** %3
%27 = load i8, i8* %26
%28 = call i32 @isspace(i8 signext %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %25
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %3
br label %33
33: ; preds = %30, %25
%34 = load i8*, i8** %3
store i8 0, i8* %34
ret void
}

LLVM IR (-O2):
define void @remove_trailing(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %20, label %4
4: ; preds = %1, %4
%5 = phi i8 [ %16, %4 ], [ %2, %1 ]
%6 = phi i8* [ %14, %4 ], [ %0, %1 ]
%7 = phi i8* [ %15, %4 ], [ %0, %1 ]
%8 = tail call i32 @isspace(i8 signext %5)
%9 = icmp eq i32 %8, 0
%10 = ptrtoint i8* %7 to i64
%11 = ptrtoint i8* %6 to i64
%12 = sub i64 %10, %11
%13 = select i1 %9, i64 %12, i64 0
%14 = getelementptr i8, i8* %6, i64 %13
%15 = getelementptr inbounds i8, i8* %7, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %4
18: ; preds = %4
%19 = load i8, i8* %14
br label %20
20: ; preds = %18, %1
%21 = phi i8 [ 0, %1 ], [ %19, %18 ]
%22 = phi i8* [ %0, %1 ], [ %14, %18 ]
%23 = tail call i32 @isspace(i8 signext %21)
%24 = icmp eq i32 %23, 0
%25 = zext i1 %24 to i64
%26 = getelementptr i8, i8* %22, i64 %25
store i8 0, i8* %26
ret void
}