#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);
char *nasm_zap_spaces_rev(char *p) {
  if (p)
    while (*p && isspace((unsigned char)(*p)))
      *p-- = 0x0;
  return p;
}


x86 assembly (clang, -O0):
<nasm_zap_spaces_rev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1183 <nasm_zap_spaces_rev+0x73>
jmp    112c <nasm_zap_spaces_rev+0x1c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x9(%rbp)
je     1157 <nasm_zap_spaces_rev+0x47>
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    1167 <nasm_zap_spaces_rev+0x57>
jmp    117e <nasm_zap_spaces_rev+0x6e>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x0,(%rax)
jmp    112c <nasm_zap_spaces_rev+0x1c>
jmp    1183 <nasm_zap_spaces_rev+0x73>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nasm_zap_spaces_rev>:
push   %rbx
test   %rdi,%rdi
je     1146 <nasm_zap_spaces_rev+0x36>
mov    %rdi,%rbx
mov    (%rdi),%cl
test   %cl,%cl
je     1141 <nasm_zap_spaces_rev+0x31>
nop
movzbl %cl,%edi
call   1030 <isspace@plt>
test   %rax,%rax
je     1141 <nasm_zap_spaces_rev+0x31>
lea    -0x1(%rbx),%rax
movb   $0x0,(%rbx)
movzbl -0x1(%rbx),%ecx
mov    %rax,%rbx
test   %cl,%cl
jne    1120 <nasm_zap_spaces_rev+0x10>
pop    %rbx
ret
mov    %rbx,%rax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

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

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