#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(char const *);
scalar_t__ memcmp(char const *, char const *, size_t);
size_t strcspn(char const *, char *);
int /*<<< orphan*/ strspn(char const *, char *);
char *path_startswith(const char *path, const char *prefix) {
  assert(path);
  assert(prefix);
  if ((path[0] == '/') != (prefix[0] == '/'))
    return NULL;
  for (;;) {
    size_t a, b;
    path += strspn(path, "/");
    prefix += strspn(prefix, "/");
    if (*prefix == 0)
      return (char *)path;
    if (*path == 0)
      return NULL;
    a = strcspn(path, "/");
    b = strcspn(prefix, "/");
    if (a != b)
      return NULL;
    if (memcmp(path, prefix, a) != 0)
      return NULL;
    path += a;
    prefix += b;
  }
}


x86 assembly (clang, -O0):
<path_startswith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    $0x2f,%ecx
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
cmp    %ecx,%eax
je     119c <path_startswith+0x5c>
movq   $0x0,-0x8(%rbp)
jmp    12a3 <path_startswith+0x163>
jmp    11a1 <path_startswith+0x61>
mov    -0x10(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1030 <strspn@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1030 <strspn@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11fe <path_startswith+0xbe>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12a3 <path_startswith+0x163>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    121b <path_startswith+0xdb>
movq   $0x0,-0x8(%rbp)
jmp    12a3 <path_startswith+0x163>
mov    -0x10(%rbp),%rdi
lea    0xdda(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdc6(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     125e <path_startswith+0x11e>
movq   $0x0,-0x8(%rbp)
jmp    12a3 <path_startswith+0x163>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     1286 <path_startswith+0x146>
movq   $0x0,-0x8(%rbp)
jmp    12a3 <path_startswith+0x163>
mov    -0x20(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11a1 <path_startswith+0x61>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_startswith>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1060 <assert@plt>
mov    %r14,%rdi
call   1060 <assert@plt>
cmpb   $0x2f,(%r15)
setne  %al
cmpb   $0x2f,(%r14)
sete   %cl
cmp    %cl,%al
je     1216 <path_startswith+0xd6>
lea    0xe88(%rip),%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <strspn@plt>
movslq %eax,%rbx
add    %r15,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <strspn@plt>
cltq
cmpb   $0x0,(%r14,%rax,1)
je     1218 <path_startswith+0xd8>
add    %rax,%r14
lea    0xe59(%rip),%r15
nopw   0x0(%rax,%rax,1)
cmpb   $0x0,(%rbx)
je     1216 <path_startswith+0xd6>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcspn@plt>
mov    %rax,%r12
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcspn@plt>
cmp    %rax,%r12
jne    1216 <path_startswith+0xd6>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <memcmp@plt>
test   %rax,%rax
jne    1216 <path_startswith+0xd6>
add    %r12,%rbx
add    %r12,%r14
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strspn@plt>
cltq
add    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strspn@plt>
cltq
cmpb   $0x0,(%rax,%r14,1)
lea    (%r14,%rax,1),%r14
jne    11b0 <path_startswith+0x70>
jmp    1218 <path_startswith+0xd8>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i8* @path_startswith(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i32 @assert(i8* %8)
%10 = load i8*, i8** %5
%11 = call i32 @assert(i8* %10)
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 47
%17 = zext i1 %16 to i32
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 47
%23 = zext i1 %22 to i32
%24 = icmp ne i32 %17, %23
br i1 %24, label %25, label %26
25: ; preds = %2
store i8* null, i8** %3
br label %73
26: ; preds = %2
br label %27
27: ; preds = %66, %26
%28 = load i8*, i8** %4
%29 = call i32 @strspn(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%30 = load i8*, i8** %4
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8* %32, i8** %4
%33 = load i8*, i8** %5
%34 = call i32 @strspn(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%35 = load i8*, i8** %5
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i8, i8* %35, i64 %36
store i8* %37, i8** %5
%38 = load i8*, i8** %5
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %27
%43 = load i8*, i8** %4
store i8* %43, i8** %3
br label %73
44: ; preds = %27
%45 = load i8*, i8** %4
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %44
store i8* null, i8** %3
br label %73
50: ; preds = %44
%51 = load i8*, i8** %4
%52 = call i64 @strcspn(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i64 %52, i64* %6
%53 = load i8*, i8** %5
%54 = call i64 @strcspn(i8* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i64 %54, i64* %7
%55 = load i64, i64* %6
%56 = load i64, i64* %7
%57 = icmp ne i64 %55, %56
br i1 %57, label %58, label %59
58: ; preds = %50
store i8* null, i8** %3
br label %73
59: ; preds = %50
%60 = load i8*, i8** %4
%61 = load i8*, i8** %5
%62 = load i64, i64* %6
%63 = call i64 @memcmp(i8* %60, i8* %61, i64 %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %59
store i8* null, i8** %3
br label %73
66: ; preds = %59
%67 = load i64, i64* %6
%68 = load i8*, i8** %4
%69 = getelementptr inbounds i8, i8* %68, i64 %67
store i8* %69, i8** %4
%70 = load i64, i64* %7
%71 = load i8*, i8** %5
%72 = getelementptr inbounds i8, i8* %71, i64 %70
store i8* %72, i8** %5
br label %27
73: ; preds = %65, %58, %49, %42, %25
%74 = load i8*, i8** %3
ret i8* %74
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @path_startswith(i8* %0, i8* %1) {
%3 = tail call i32 @assert(i8* %0)
%4 = tail call i32 @assert(i8* %1)
%5 = load i8, i8* %0
%6 = icmp ne i8 %5, 47
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 47
%9 = xor i1 %6, %8
br i1 %9, label %10, label %42
10: ; preds = %2
%11 = tail call i32 @strspn(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = tail call i32 @strspn(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %42, label %19
19: ; preds = %10, %31
%20 = phi i8* [ %39, %31 ], [ %16, %10 ]
%21 = phi i8* [ %36, %31 ], [ %13, %10 ]
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %42, label %24
24: ; preds = %19
%25 = tail call i64 @strcspn(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%26 = tail call i64 @strcspn(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %42
28: ; preds = %24
%29 = tail call i64 @memcmp(i8* %21, i8* %20, i64 %25)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %42
31: ; preds = %28
%32 = getelementptr inbounds i8, i8* %21, i64 %25
%33 = getelementptr inbounds i8, i8* %20, i64 %25
%34 = tail call i32 @strspn(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
%37 = tail call i32 @strspn(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %33, i64 %38
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 0
br i1 %41, label %42, label %19
42: ; preds = %31, %19, %24, %28, %10, %2
%43 = phi i8* [ null, %2 ], [ %13, %10 ], [ %36, %31 ], [ null, %19 ], [ null, %24 ], [ null, %28 ]
ret i8* %43
}