#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);
scalar_t__ s3d_strendswith(char *, char const *);
int strlen(char const *);
char *s3d_strrtrim(char *s, const char *suffix) {
  int s_len = strlen(s);
  int suff_len = strlen(suffix);
  while (s3d_strendswith(s, suffix)) {
    assert(s_len >= 0);
    s[s_len - suff_len] = 0;
    s_len -= suff_len;
  }
  return s;
}


x86 assembly (clang, -O0):
<s3d_strrtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <s3d_strendswith@plt>
cmp    $0x0,%rax
je     11a1 <s3d_strrtrim+0x71>
cmpl   $0x0,-0x14(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    -0x18(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1158 <s3d_strrtrim+0x28>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s3d_strrtrim>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <s3d_strendswith@plt>
test   %rax,%rax
je     1198 <s3d_strrtrim+0x68>
mov    %ebp,%ebx
sub    %r12d,%ebx
not    %ebp
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
shr    $0x1f,%edi
call   1050 <assert@plt>
movslq %ebx,%rbx
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <s3d_strendswith@plt>
sub    %r12d,%ebx
add    %r12d,%ebp
test   %rax,%rax
jne    1170 <s3d_strrtrim+0x40>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @s3d_strrtrim(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%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* %5
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %6
br label %11
11: ; preds = %16, %2
%12 = load i8*, i8** %3
%13 = load i8*, i8** %4
%14 = call i64 @s3d_strendswith(i8* %12, i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %30
16: ; preds = %11
%17 = load i32, i32* %5
%18 = icmp sge i32 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i8*, i8** %3
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = sub nsw i32 %22, %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %21, i64 %25
store i8 0, i8* %26
%27 = load i32, i32* %6
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, %27
store i32 %29, i32* %5
br label %11
30: ; preds = %11
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
define i8* @s3d_strrtrim(i8* returned %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = tail call i64 @s3d_strendswith(i8* %0, i8* %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %2, %7
%8 = phi i32 [ %12, %7 ], [ %3, %2 ]
%9 = xor i32 %8, -1
%10 = lshr i32 %9, 31
%11 = tail call i32 @assert(i32 %10)
%12 = sub nsw i32 %8, %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 0, i8* %14
%15 = tail call i64 @s3d_strendswith(i8* %0, i8* %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %7
17: ; preds = %7, %2
ret i8* %0
}