#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 */
scalar_t__ strcmp(char *, char const *);
int strlen(char const *);
char *strstr(char *, char const *);
const char *remove_root(const char *root, char *path) {
  path[strlen(path) - 1] = '\0';
  if (strcmp(path, root) && strstr(path, root) == path) {
    return path + strlen(root) + 1;
  }
  return path;
}


x86 assembly (clang, -O0):
<remove_root>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11b9 <remove_root+0x89>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
cmp    -0x18(%rbp),%rax
jne    11b9 <remove_root+0x89>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11c1 <remove_root+0x91>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_root>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1184 <remove_root+0x54>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1184 <remove_root+0x54>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @remove_root(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = add nsw i32 %3, -1
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %1, i64 %5
store i8 0, i8* %6
%7 = tail call i64 @strcmp(i8* %1, i8* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %2
%10 = tail call i64 bitcast (i32 (i8*)* @strlen to i64 (i8*)*)(i8* %0)
%11 = tail call i32 @strncmp(i8* %1, i8* %0, i64 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = tail call i32 @strlen(i8* %0)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = getelementptr inbounds i8, i8* %16, i64 1
br label %18
18: ; preds = %2, %9, %13
%19 = phi i8* [ %17, %13 ], [ %1, %9 ], [ %1, %2 ]
ret i8* %19
}