#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*/ stringStartsWith(char *, char const *);
int strlen(char const *);
void removePrefixFromString(char **string, const char *prefix) {
  if (!stringStartsWith(*string, prefix)) {
    return;
  }
  int stringLength = strlen(*string);
  int prefixLength = strlen(prefix);
  int resultingStringLength = stringLength - prefixLength;
  char *resultingString = allocateMemory(resultingStringLength + 1);
  memcpy(resultingString, &(*string)[prefixLength], resultingStringLength);
  resultingString[resultingStringLength] = '\0';
  *string = resultingString;
}


x86 assembly (clang, -O0):
<removePrefixFromString>:
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   1050 <stringStartsWith@plt>
cmp    $0x0,%eax
jne    116e <removePrefixFromString+0x2e>
jmp    11d2 <removePrefixFromString+0x92>
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   1060 <allocateMemory@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
movslq -0x18(%rbp),%rax
add    %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):
<removePrefixFromString>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rdi),%rdi
call   1050 <stringStartsWith@plt>
test   %eax,%eax
je     1196 <removePrefixFromString+0x56>
mov    (%r14),%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
sub    %eax,%ebx
lea    0x1(%rbx),%edi
call   1060 <allocateMemory@plt>
mov    %rax,%rbp
movslq %r15d,%rsi
add    (%r14),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1040 <memcpy@plt>
movslq %ebx,%rax
movb   $0x0,0x0(%rbp,%rax,1)
mov    %rbp,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @removePrefixFromString(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 @stringStartsWith(i8* %10, i8* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %2
br label %41
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* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i32, i32* %7
%34 = call i32 @memcpy(i8* %27, i8* %32, i32 %33)
%35 = load i8*, i8** %8
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 0, i8* %38
%39 = load i8*, i8** %8
%40 = load i8**, i8*** %3
store i8* %39, i8** %40
br label %41
41: ; preds = %15, %14
ret void
}

LLVM IR (-O2):
define void @removePrefixFromString(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = tail call i32 @stringStartsWith(i8* %3, i8* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %19, 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 = sext i32 %9 to i64
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = tail call i32 @memcpy(i8* %12, i8* %15, i32 %10)
%17 = sext i32 %10 to i64
%18 = getelementptr inbounds i8, i8* %12, i64 %17
store i8 0, i8* %18
store i8* %12, i8** %0
br label %19
19: ; preds = %2, %6
ret void
}