#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 strlen(char *);
char *strtrim_right(register char *p, register char c) {
  register char *end;
  register int len;
  len = strlen(p);
  while (*p && len) {
    end = p + len - 1;
    if (c == *end)
      *end = 0;
    else
      break;
    len = strlen(p);
  }
  return p;
}


x86 assembly (clang, -O0):
<strtrim_right>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     114d <strtrim_right+0x3d>
cmpl   $0x0,-0x1c(%rbp)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    115d <strtrim_right+0x4d>
jmp    11a5 <strtrim_right+0x95>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
movsbl -0x9(%rbp),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    118f <strtrim_right+0x7f>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    1194 <strtrim_right+0x84>
jmp    11a5 <strtrim_right+0x95>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
jmp    112e <strtrim_right+0x1e>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtrim_right>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
nopl   0x0(%rax,%rax,1)
call   1030 <strlen@plt>
cmpb   $0x0,(%rbx)
je     1141 <strtrim_right+0x31>
test   %eax,%eax
je     1141 <strtrim_right+0x31>
cltq
cmp    %bpl,-0x1(%rbx,%rax,1)
jne    1141 <strtrim_right+0x31>
movb   $0x0,-0x1(%rbx,%rax,1)
mov    %rbx,%rdi
jmp    1120 <strtrim_right+0x10>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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