#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(char);
int strlen(char *);
void remove_ending_whitespace(char **s) {
  char *p = *s + strlen(*s) - 1;
  while (p > *s && isspace(*p))
    *(p--) = '\0';
}


x86 assembly (clang, -O0):
<remove_ending_whitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%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
mov    -0x8(%rbp),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
mov    %al,-0x19(%rbp)
jbe    1183 <remove_ending_whitespace+0x63>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1193 <remove_ending_whitespace+0x73>
jmp    11aa <remove_ending_whitespace+0x8a>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
jmp    1157 <remove_ending_whitespace+0x37>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_ending_whitespace>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    (%rdi),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
lea    (%r14,%rax,1),%rbx
add    $0xffffffffffffffff,%rbx
cmp    (%r15),%rbx
jbe    1169 <remove_ending_whitespace+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%rbx),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1169 <remove_ending_whitespace+0x49>
movb   $0x0,(%rbx)
add    $0xffffffffffffffff,%rbx
cmp    (%r15),%rbx
ja     1150 <remove_ending_whitespace+0x30>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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