#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*/ isgraph(int);
char *strchr(char *, char);
int strlen(char *);
void chop(char *str) {
  char *p;
  if ((p = strchr(str, '#')))
    *p = '\0';
  for (p = str + strlen(str) - 1; p >= str && !isgraph((int)*p); p--)
    *p = '\0';
}


x86 assembly (clang, -O0):
<chop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     115f <chop+0x2f>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
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),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x19(%rbp)
jb     11ae <chop+0x7e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isgraph@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11be <chop+0x8e>
jmp    11d6 <chop+0xa6>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1184 <chop+0x54>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chop>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x23,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1149 <chop+0x19>
movb   $0x0,(%rax)
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
lea    (%r14,%rax,1),%rbx
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jb     1178 <chop+0x48>
movsbl (%rbx),%edi
call   1050 <isgraph@plt>
test   %eax,%eax
jne    1178 <chop+0x48>
movb   $0x0,(%rbx)
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jae    1160 <chop+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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