#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(unsigned char);
unsigned int strlen(char *);
void strip_spaces_end(char *buf) {
  unsigned int i = strlen(buf);
  while (i > 0 && isspace((unsigned char)buf[i - 1]))
    i--;
  buf[i] = '\0';
}


x86 assembly (clang, -O0):
<strip_spaces_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0xd(%rbp)
jbe    1166 <strip_spaces_end+0x46>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1176 <strip_spaces_end+0x56>
jmp    1184 <strip_spaces_end+0x64>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1138 <strip_spaces_end+0x18>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_spaces_end>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%ebx
nop
mov    %rbx,%r15
test   %rbx,%rbx
je     114d <strip_spaces_end+0x2d>
lea    -0x1(%r15),%rbx
mov    %ebx,%eax
movzbl (%r14,%rax,1),%edi
call   1040 <isspace@plt>
test   %rax,%rax
jne    1130 <strip_spaces_end+0x10>
mov    %r15d,%eax
movb   $0x0,(%r14,%rax,1)
pop    %rbx
pop    %r14
pop    %r15
ret

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

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