#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);
size_t strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char const *, size_t);
const char *relpath(const char *path, const char *start) {
  size_t startlen = strlen(start);
  assert(start[startlen - 1] != '/');
  if (!strncmp(path, start, startlen)) {
    const char *rel = path + startlen;
    return *rel == '/' ? rel + 1 : rel;
  }
  return path;
}


x86 assembly (clang, -O0):
<relpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11c9 <relpath+0x99>
mov    -0x10(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11b4 <relpath+0x84>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11bc <relpath+0x8c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d1 <relpath+0xa1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<relpath>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
xor    %edi,%edi
cmpb   $0x2f,-0x1(%rax,%rbx,1)
setne  %dil
call   1050 <assert@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    117e <relpath+0x4e>
mov    %r15,%rax
add    %r14,%rax
xor    %ecx,%ecx
cmpb   $0x2f,(%r14,%r15,1)
sete   %cl
add    %rax,%rcx
mov    %rcx,%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @relpath(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %6
%10 = load i8*, i8** %5
%11 = load i64, i64* %6
%12 = sub i64 %11, 1
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 47
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = load i64, i64* %6
%22 = call i32 @strncmp(i8* %19, i8* %20, i64 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %39, label %24
24: ; preds = %2
%25 = load i8*, i8** %4
%26 = load i64, i64* %6
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 47
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i64 1
br label %37
35: ; preds = %24
%36 = load i8*, i8** %7
br label %37
37: ; preds = %35, %32
%38 = phi i8* [ %34, %32 ], [ %36, %35 ]
store i8* %38, i8** %3
br label %41
39: ; preds = %2
%40 = load i8*, i8** %4
store i8* %40, i8** %3
br label %41
41: ; preds = %39, %37
%42 = load i8*, i8** %3
ret i8* %42
}

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