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


x86 assembly (clang, -O0):
<strip_end_whitesp_inplace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1149 <strip_end_whitesp_inplace+0x29>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jne    114e <strip_end_whitesp_inplace+0x2e>
jmp    11c6 <strip_end_whitesp_inplace+0xa6>
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),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     119f <strip_end_whitesp_inplace+0x7f>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
seta   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11af <strip_end_whitesp_inplace+0x8f>
jmp    11c6 <strip_end_whitesp_inplace+0xa6>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
jmp    1173 <strip_end_whitesp_inplace+0x53>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_end_whitesp_inplace>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     118a <strip_end_whitesp_inplace+0x6a>
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
je     118a <strip_end_whitesp_inplace+0x6a>
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbx
lea    (%r14,%rbx,1),%r15
add    $0xffffffffffffffff,%r15
movsbl -0x1(%r14,%rbx,1),%edi
call   1040 <isspace@plt>
cmp    %r14,%r15
jbe    118a <strip_end_whitesp_inplace+0x6a>
test   %rax,%rax
je     118a <strip_end_whitesp_inplace+0x6a>
add    %r14,%rbx
add    $0xfffffffffffffffe,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,0x1(%rbx)
movsbl (%rbx),%edi
call   1040 <isspace@plt>
cmp    %r14,%rbx
jbe    118a <strip_end_whitesp_inplace+0x6a>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    1170 <strip_end_whitesp_inplace+0x50>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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