#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 /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *rstrip(char *word) {
  int len = 0;
  int i = 0;
  int badnum = 0;
  char *p = NULL;
  assert(word != NULL);
  len = strlen(word);
  p = word + len;
  for (p = word + len - 1; p >= word; p--) {
    if (strchr(" \t;#", *(p)) > 0) {
      badnum++;
      *p = 0;
    }
  }
  len = strlen(word);
  p = (char *)malloc(len + 1);
  memset(p, 0, len + 1);
  strncpy(p, word, len);
  return p;
}


x86 assembly (clang, -O0):
<rstrip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     121a <rstrip+0xba>
mov    -0x20(%rbp),%rax
lea    0xe1e(%rip),%rdi
movsbl (%rax),%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
jle    1204 <rstrip+0xa4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    1209 <rstrip+0xa9>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11c9 <rstrip+0x69>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rstrip>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rbp
add    $0xffffffffffffffff,%rbp
cmp    %rbx,%rbp
jae    11d2 <rstrip+0x72>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
lea    0x1(%r14),%r15d
mov    %r15d,%edi
call   1080 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1060 <memset@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe27(%rip),%r14
jmp    11e9 <rstrip+0x89>
nopl   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rbp
cmp    %rbx,%rbp
jb     118f <rstrip+0x2f>
movsbl 0x0(%rbp),%esi
mov    %r14,%rdi
call   1050 <strchr@plt>
test   %rax,%rax
jle    11e0 <rstrip+0x80>
movb   $0x0,0x0(%rbp)
jmp    11e0 <rstrip+0x80>

LLVM IR (-O0):
@.str = [5 x i8] c" \09;#\00"
define i8* @rstrip(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i8* null, i8** %6
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i8*, i8** %2
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %3
%13 = load i8*, i8** %2
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
store i8* %16, i8** %6
%17 = load i8*, i8** %2
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = getelementptr inbounds i8, i8* %20, i64 -1
store i8* %21, i8** %6
br label %22
22: ; preds = %36, %1
%23 = load i8*, i8** %6
%24 = load i8*, i8** %2
%25 = icmp uge i8* %23, %24
br i1 %25, label %26, label %39
26: ; preds = %22
%27 = load i8*, i8** %6
%28 = load i8, i8* %27
%29 = call i64 @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %28)
%30 = icmp sgt i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
%34 = load i8*, i8** %6
store i8 0, i8* %34
br label %35
35: ; preds = %31, %26
br label %36
36: ; preds = %35
%37 = load i8*, i8** %6
%38 = getelementptr inbounds i8, i8* %37, i32 -1
store i8* %38, i8** %6
br label %22
39: ; preds = %22
%40 = load i8*, i8** %2
%41 = call i32 @strlen(i8* %40)
store i32 %41, i32* %3
%42 = load i32, i32* %3
%43 = add nsw i32 %42, 1
%44 = call i64 @malloc(i32 %43)
%45 = inttoptr i64 %44 to i8*
store i8* %45, i8** %6
%46 = load i8*, i8** %6
%47 = load i32, i32* %3
%48 = add nsw i32 %47, 1
%49 = call i32 @memset(i8* %46, i32 0, i32 %48)
%50 = load i8*, i8** %6
%51 = load i8*, i8** %2
%52 = load i32, i32* %3
%53 = call i32 @strncpy(i8* %50, i8* %51, i32 %52)
%54 = load i8*, i8** %6
ret i8* %54
}

LLVM IR (-O2):
@.str = [5 x i8] c" \09;#\00"
define i8* @rstrip(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i32 @strlen(i8* %0)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = getelementptr inbounds i8, i8* %7, i64 -1
%9 = icmp ult i8* %8, %0
br i1 %9, label %19, label %10
10: ; preds = %1, %16
%11 = phi i8* [ %17, %16 ], [ %8, %1 ]
%12 = load i8, i8* %11
%13 = tail call i64 @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %12)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10
store i8 0, i8* %11
br label %16
16: ; preds = %10, %15
%17 = getelementptr inbounds i8, i8* %11, i64 -1
%18 = icmp ult i8* %17, %0
br i1 %18, label %19, label %10
19: ; preds = %16, %1
%20 = tail call i32 @strlen(i8* %0)
%21 = add nsw i32 %20, 1
%22 = tail call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
%24 = tail call i32 @memset(i8* %23, i32 0, i32 %21)
%25 = tail call i32 @strncpy(i8* %23, i8* %0, i32 %20)
ret i8* %23
}