#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 *);
void semanage_rtrim(char *str, char trim_to) {
  int len = 0;
  if (!str)
    return;
  len = strlen(str);
  while (len > 0) {
    if (str[--len] == trim_to) {
      str[len] = '\0';
      return;
    }
  }
}


x86 assembly (clang, -O0):
<semanage_rtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1139 <semanage_rtrim+0x29>
jmp    1185 <semanage_rtrim+0x75>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    1185 <semanage_rtrim+0x75>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    1180 <semanage_rtrim+0x70>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1185 <semanage_rtrim+0x75>
jmp    1145 <semanage_rtrim+0x35>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<semanage_rtrim>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1148 <semanage_rtrim+0x38>
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %eax,%eax
jle    1148 <semanage_rtrim+0x38>
lea    -0x1(%rax),%rcx
cmp    %bpl,-0x1(%rbx,%rax,1)
mov    %rcx,%rax
jne    1130 <semanage_rtrim+0x20>
mov    %ecx,%eax
movb   $0x0,(%rbx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @semanage_rtrim(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
store i8* %0, i8** %3
store i8 %1, i8* %4
store i32 0, i32* %5
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %2
br label %32
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %5
br label %12
12: ; preds = %31, %9
%13 = load i32, i32* %5
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %32
15: ; preds = %12
%16 = load i8*, i8** %3
%17 = load i32, i32* %5
%18 = add nsw i32 %17, -1
store i32 %18, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
%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 i1 %25, label %26, label %31
26: ; preds = %15
%27 = load i8*, i8** %3
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 0, i8* %30
br label %32
31: ; preds = %15
br label %12
32: ; preds = %8, %26, %12
ret void
}

LLVM IR (-O2):
define void @semanage_rtrim(i8* %0, i8 signext %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %19, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %0)
%6 = zext i32 %5 to i64
br label %7
7: ; preds = %11, %4
%8 = phi i64 [ %12, %11 ], [ %6, %4 ]
%9 = trunc i64 %8 to i32
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %7
%12 = add nsw i64 %8, -1
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, %1
br i1 %15, label %16, label %7
16: ; preds = %11
%17 = and i64 %12, 4294967295
%18 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 0, i8* %18
br label %19
19: ; preds = %7, %2, %16
ret void
}