#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(char *);
size_t strlen(char *);
void _strip_trailing(char *in, char c) {
  char *p;
  size_t len;
  assert(in);
  len = strlen(in);
  p = in + len - 1;
  while (p > in && *p == c)
    *(p--) = 0;
}


x86 assembly (clang, -O0):
<_strip_trailing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x21(%rbp)
jbe    117e <_strip_trailing+0x5e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    118e <_strip_trailing+0x6e>
jmp    11a5 <_strip_trailing+0x85>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
jmp    1158 <_strip_trailing+0x38>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_strip_trailing>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jbe    1161 <_strip_trailing+0x41>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    %bpl,(%rax)
jne    1161 <_strip_trailing+0x41>
movb   $0x0,(%rax)
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
ja     1150 <_strip_trailing+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define void @_strip_trailing(i8* %0, i8 signext %1) {
%3 = tail call i32 @assert(i8* %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = getelementptr inbounds i8, i8* %5, i64 -1
%7 = icmp ugt i8* %6, %0
br i1 %7, label %8, label %15
8: ; preds = %2, %12
%9 = phi i8* [ %13, %12 ], [ %6, %2 ]
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, %1
br i1 %11, label %12, label %15
12: ; preds = %8
store i8 0, i8* %9
%13 = getelementptr inbounds i8, i8* %9, i64 -1
%14 = icmp ugt i8* %13, %0
br i1 %14, label %8, label %15
15: ; preds = %8, %12, %2
ret void
}