#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 */
size_t strlen(char *);
scalar_t__ strncmp(char *, char *, size_t);
void remove_suffix(char *string, char *suffix) {
  size_t len = strlen(string);
  size_t suffix_len = strlen(suffix);
  if (strncmp((string + len - suffix_len), suffix, suffix_len) == 0) {
    string[len - suffix_len] = '\0';
  }
}


x86 assembly (clang, -O0):
<remove_suffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
add    -0x18(%rbp),%rdi
xor    %eax,%eax
sub    -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1182 <remove_suffix+0x62>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_suffix>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
lea    (%r14,%r15,1),%rdi
sub    %rax,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1160 <remove_suffix+0x40>
sub    %rbx,%r15
movb   $0x0,(%r14,%r15,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @remove_suffix(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %5
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %6
%11 = load i8*, i8** %3
%12 = load i64, i64* %5
%13 = getelementptr inbounds i8, i8* %11, i64 %12
%14 = load i64, i64* %6
%15 = sub i64 0, %14
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8*, i8** %4
%18 = load i64, i64* %6
%19 = call i64 @strncmp(i8* %16, i8* %17, i64 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %2
%22 = load i8*, i8** %3
%23 = load i64, i64* %5
%24 = load i64, i64* %6
%25 = sub i64 %23, %24
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8 0, i8* %26
br label %27
27: ; preds = %21, %2
ret void
}

LLVM IR (-O2):
define void @remove_suffix(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = getelementptr inbounds i8, i8* %0, i64 %3
%6 = sub i64 0, %4
%7 = getelementptr inbounds i8, i8* %5, i64 %6
%8 = tail call i64 @strncmp(i8* %7, i8* %1, i64 %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = sub i64 %3, %4
%12 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 0, i8* %12
br label %13
13: ; preds = %10, %2
ret void
}