#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*/ hidequoted(char *, char *);
scalar_t__ isspace(char);
int /*<<< orphan*/ showquoted(char *, char *);
char *strchr(char *, char);
int strlen(char *);
void remtail(char *str) {
  char *tail;
  char quoted[256];
  hidequoted(str, quoted);
  tail = strchr(str, '#');
  if (tail != NULL)
    *tail = '\0';
  if (strlen(str) > 0) {
    tail = str + strlen(str) - 1;
    if (isspace(*tail)) {
      do {
        tail--;
      } while (isspace(*tail) && tail >= str);
      *(tail + 1) = '\0';
    }
  }
  showquoted(str, quoted);
}


x86 assembly (clang, -O0):
<remtail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1070 <hidequoted@plt>
mov    -0x8(%rbp),%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1193 <remtail+0x43>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jle    1244 <remtail+0xf4>
mov    -0x8(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x118(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     123f <remtail+0xef>
jmp    11eb <remtail+0x9b>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x119(%rbp)
je     1229 <remtail+0xd9>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
setae  %al
mov    %al,-0x119(%rbp)
mov    -0x119(%rbp),%al
test   $0x1,%al
jne    11eb <remtail+0x9b>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    1244 <remtail+0xf4>
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1060 <showquoted@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remtail>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%r15
mov    %rsp,%rsi
call   1070 <hidequoted@plt>
mov    %r15,%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     117c <remtail+0x2c>
movb   $0x0,(%rax)
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11cd <remtail+0x7d>
mov    %r15,%rdi
call   1030 <strlen@plt>
movslq %eax,%r14
movsbl -0x1(%r15,%r14,1),%edi
call   1050 <isspace@plt>
test   %rax,%rax
je     11cd <remtail+0x7d>
lea    (%r14,%r15,1),%rcx
add    $0xfffffffffffffffe,%rcx
nopl   0x0(%rax,%rax,1)
mov    %rcx,%rbx
movsbl (%rcx),%edi
call   1050 <isspace@plt>
lea    -0x1(%rbx),%rcx
cmp    %r15,%rbx
jb     11c9 <remtail+0x79>
test   %rax,%rax
jne    11b0 <remtail+0x60>
movb   $0x0,0x2(%rcx)
mov    %rsp,%rsi
mov    %r15,%rdi
call   1060 <showquoted@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @remtail(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [256 x i8]
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = call i32 @hidequoted(i8* %5, i8* %6)
%8 = load i8*, i8** %2
%9 = call i8* @strchr(i8* %8, i8 signext 35)
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = load i8*, i8** %3
store i8 0, i8* %13
br label %14
14: ; preds = %12, %1
%15 = load i8*, i8** %2
%16 = call i32 @strlen(i8* %15)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %48
18: ; preds = %14
%19 = load i8*, i8** %2
%20 = load i8*, i8** %2
%21 = call i32 @strlen(i8* %20)
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = getelementptr inbounds i8, i8* %23, i64 -1
store i8* %24, i8** %3
%25 = load i8*, i8** %3
%26 = load i8, i8* %25
%27 = call i64 @isspace(i8 signext %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %47
29: ; preds = %18
br label %30
30: ; preds = %42, %29
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i32 -1
store i8* %32, i8** %3
br label %33
33: ; preds = %30
%34 = load i8*, i8** %3
%35 = load i8, i8* %34
%36 = call i64 @isspace(i8 signext %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = load i8*, i8** %3
%40 = load i8*, i8** %2
%41 = icmp uge i8* %39, %40
br label %42
42: ; preds = %38, %33
%43 = phi i1 [ false, %33 ], [ %41, %38 ]
br i1 %43, label %30, label %44
44: ; preds = %42
%45 = load i8*, i8** %3
%46 = getelementptr inbounds i8, i8* %45, i64 1
store i8 0, i8* %46
br label %47
47: ; preds = %44, %18
br label %48
48: ; preds = %47, %14
%49 = load i8*, i8** %2
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%51 = call i32 @showquoted(i8* %49, i8* %50)
ret void
}

LLVM IR (-O2):
define void @remtail(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @hidequoted(i8* %0, i8* %3)
%5 = call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 35)
%6 = icmp eq i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store i8 0, i8* %5
br label %8
8: ; preds = %7, %1
%9 = call i32 @strlen(i8* %0)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = call i32 @strlen(i8* %0)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = getelementptr inbounds i8, i8* %14, i64 -1
%16 = load i8, i8* %15
%17 = call i64 @isspace(i8 signext %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %11, %19
%20 = phi i8* [ %21, %19 ], [ %15, %11 ]
%21 = getelementptr inbounds i8, i8* %20, i64 -1
%22 = load i8, i8* %21
%23 = call i64 @isspace(i8 signext %22)
%24 = icmp ne i64 %23, 0
%25 = icmp uge i8* %21, %0
%26 = and i1 %25, %24
br i1 %26, label %19, label %27
27: ; preds = %19
store i8 0, i8* %20
br label %28
28: ; preds = %11, %27, %8
%29 = call i32 @showquoted(i8* %0, i8* %3)
ret void
}