#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*/ assert(int);
scalar_t__ isspace(unsigned char);
scalar_t__ strlen(char *);
void rtrim(char *s) {
  char *p;
  assert(s != NULL);
  if (*s == '\0') {
    return;
  }
  p = s + strlen(s) - 1;
  assert(strlen(s) > 0);
  while (p >= s && isspace((unsigned char)*p)) {
    *p-- = '\0';
  }
}


x86 assembly (clang, -O0):
<rtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1163 <rtrim+0x33>
jmp    11f0 <rtrim+0xc0>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x19(%rbp)
jb     11c9 <rtrim+0x99>
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11d9 <rtrim+0xa9>
jmp    11f0 <rtrim+0xc0>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
jmp    11a0 <rtrim+0x70>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtrim>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1050 <assert@plt>
cmpb   $0x0,(%r15)
je     1199 <rtrim+0x69>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r14
xor    %edi,%edi
test   %rax,%rax
setg   %dil
call   1050 <assert@plt>
lea    (%r15,%r14,1),%rbx
add    $0xffffffffffffffff,%rbx
cmp    %r15,%rbx
jb     1199 <rtrim+0x69>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1199 <rtrim+0x69>
movb   $0x0,(%rbx)
add    $0xffffffffffffffff,%rbx
cmp    %r15,%rbx
jae    1180 <rtrim+0x50>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @rtrim(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
br label %38
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = load i8*, i8** %2
%16 = call i64 @strlen(i8* %15)
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = getelementptr inbounds i8, i8* %17, i64 -1
store i8* %18, i8** %3
%19 = load i8*, i8** %2
%20 = call i64 @strlen(i8* %19)
%21 = icmp sgt i64 %20, 0
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
br label %24
24: ; preds = %35, %13
%25 = load i8*, i8** %3
%26 = load i8*, i8** %2
%27 = icmp uge i8* %25, %26
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i8*, i8** %3
%30 = load i8, i8* %29
%31 = call i64 @isspace(i8 zeroext %30)
%32 = icmp ne i64 %31, 0
br label %33
33: ; preds = %28, %24
%34 = phi i1 [ false, %24 ], [ %32, %28 ]
br i1 %34, label %35, label %38
35: ; preds = %33
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i32 -1
store i8* %37, i8** %3
store i8 0, i8* %36
br label %24
38: ; preds = %12, %33
ret void
}

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