#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__ is_slash(char);
int /*<<< orphan*/ remove_prefix(char *, size_t);
char *strchr(char *, char);
char *unix_path(int /*<<< orphan*/);
char *menu_path(char *path) {
  size_t remove = 0;
  char *colon = strchr(path, ':');
  if (colon)
    remove += (colon - path) + 1;
  while (is_slash(path[remove]) && is_slash(path[remove + 1]))
    ++remove;
  return unix_path(remove_prefix(path, remove));
}


x86 assembly (clang, -O0):
<menu_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1188 <menu_path+0x48>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    118d <menu_path+0x4d>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <is_slash@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     11cc <menu_path+0x8c>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl 0x1(%rax,%rcx,1),%edi
call   1060 <is_slash@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11dc <menu_path+0x9c>
jmp    11ed <menu_path+0xad>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    118d <menu_path+0x4d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <remove_prefix@plt>
mov    %eax,%edi
call   1030 <unix_path@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<menu_path>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,%r15
sub    %r14,%r15
add    $0x1,%r15
test   %rax,%rax
cmove  %rax,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rbx
movsbl (%r14,%r15,1),%edi
call   1060 <is_slash@plt>
test   %rax,%rax
je     1196 <menu_path+0x56>
lea    0x1(%rbx),%r15
movsbl 0x1(%r14,%rbx,1),%edi
call   1060 <is_slash@plt>
test   %rax,%rax
jne    1170 <menu_path+0x30>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <remove_prefix@plt>
mov    %eax,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <unix_path@plt>

LLVM IR (-O0):
define i8* @menu_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
store i64 0, i64* %3
%5 = load i8*, i8** %2
%6 = call i8* @strchr(i8* %5, i8 signext 58)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %18
9: ; preds = %1
%10 = load i8*, i8** %4
%11 = load i8*, i8** %2
%12 = ptrtoint i8* %10 to i64
%13 = ptrtoint i8* %11 to i64
%14 = sub i64 %12, %13
%15 = add nsw i64 %14, 1
%16 = load i64, i64* %3
%17 = add i64 %16, %15
store i64 %17, i64* %3
br label %18
18: ; preds = %9, %1
br label %19
19: ; preds = %36, %18
%20 = load i8*, i8** %2
%21 = load i64, i64* %3
%22 = getelementptr inbounds i8, i8* %20, i64 %21
%23 = load i8, i8* %22
%24 = call i64 @is_slash(i8 signext %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %19
%27 = load i8*, i8** %2
%28 = load i64, i64* %3
%29 = add i64 %28, 1
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = call i64 @is_slash(i8 signext %31)
%33 = icmp ne i64 %32, 0
br label %34
34: ; preds = %26, %19
%35 = phi i1 [ false, %19 ], [ %33, %26 ]
br i1 %35, label %36, label %39
36: ; preds = %34
%37 = load i64, i64* %3
%38 = add i64 %37, 1
store i64 %38, i64* %3
br label %19
39: ; preds = %34
%40 = load i8*, i8** %2
%41 = load i64, i64* %3
%42 = call i32 @remove_prefix(i8* %40, i64 %41)
%43 = call i8* @unix_path(i32 %42)
ret i8* %43
}

LLVM IR (-O2):
define i8* @menu_path(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%3 = icmp eq i8* %2, null
%4 = ptrtoint i8* %2 to i64
%5 = ptrtoint i8* %0 to i64
%6 = sub i64 1, %5
%7 = add i64 %6, %4
%8 = select i1 %3, i64 0, i64 %7
br label %9
9: ; preds = %15, %1
%10 = phi i64 [ %8, %1 ], [ %16, %15 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = tail call i64 @is_slash(i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %9
%16 = add i64 %10, 1
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = tail call i64 @is_slash(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %9
21: ; preds = %9, %15
%22 = tail call i32 @remove_prefix(i8* %0, i64 %10)
%23 = tail call i8* @unix_path(i32 %22)
ret i8* %23
}