#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 */
char *allocateMemory(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ stringEndsWith(char *, char const *);
int strlen(char const *);
void removeSuffixFromString(char **string, const char *suffix) {
  if (!stringEndsWith(*string, suffix)) {
    return;
  }
  int stringLength = strlen(*string);
  int sufixLength = strlen(suffix);
  int resultingStringLength = stringLength - sufixLength;
  char *resultingString = allocateMemory(resultingStringLength + 1);
  memcpy(resultingString, *string, resultingStringLength);
  resultingString[resultingStringLength] = '\0';
  *string = resultingString;
}


x86 assembly (clang, -O0):
<removeSuffixFromString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <stringEndsWith@plt>
cmp    $0x0,%eax
jne    116e <removeSuffixFromString+0x2e>
jmp    11cb <removeSuffixFromString+0x8b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1050 <allocateMemory@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<removeSuffixFromString>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rdi
call   1060 <stringEndsWith@plt>
test   %eax,%eax
je     118e <removeSuffixFromString+0x4e>
mov    (%r15),%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebx
lea    0x1(%rbx),%edi
call   1050 <allocateMemory@plt>
mov    %rax,%r14
mov    (%r15),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1040 <memcpy@plt>
movslq %ebx,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r14,(%r15)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @removeSuffixFromString(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = tail call i32 @stringEndsWith(i8* %3, i8* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = load i8*, i8** %0
%8 = tail call i32 @strlen(i8* %7)
%9 = tail call i32 @strlen(i8* %1)
%10 = sub nsw i32 %8, %9
%11 = add nsw i32 %10, 1
%12 = tail call i8* @allocateMemory(i32 %11)
%13 = load i8*, i8** %0
%14 = tail call i32 @memcpy(i8* %12, i8* %13, i32 %10)
%15 = sext i32 %10 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
store i8 0, i8* %16
store i8* %12, i8** %0
br label %17
17: ; preds = %2, %6
ret void
}