#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*/ memmove(char *, char *, int /*<<< orphan*/);
char *strchr(char *, char);
int /*<<< orphan*/ strlen(char *);
char *_collapse_slashes(char *path) {
  char *s = path;
  while ((s = strchr(s, '/')) && *(s + 1))
    *(s + 1) == '/' ? memmove(s, s + 1, strlen(s)) : s++;
  return path;
}


x86 assembly (clang, -O0):
<_collapse_slashes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,%rcx
mov    %rcx,-0x10(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
je     1179 <_collapse_slashes+0x49>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1189 <_collapse_slashes+0x59>
jmp    11de <_collapse_slashes+0xae>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
jne    11cd <_collapse_slashes+0x9d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1050 <memmove@plt>
cltq
jmp    11d9 <_collapse_slashes+0xa9>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1144 <_collapse_slashes+0x14>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_collapse_slashes>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     118d <_collapse_slashes+0x5d>
mov    %rax,%rbx
jmp    117d <_collapse_slashes+0x4d>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <memmove@plt>
mov    %rbx,%r15
mov    %r15,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     118d <_collapse_slashes+0x5d>
lea    0x1(%rbx),%r15
movzbl 0x1(%rbx),%eax
cmp    $0x2f,%al
je     1150 <_collapse_slashes+0x20>
test   %al,%al
jne    1168 <_collapse_slashes+0x38>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @_collapse_slashes(i8* returned %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, null
br i1 %3, label %15, label %4
4: ; preds = %1, %11
%5 = phi i8* [ %13, %11 ], [ %2, %1 ]
%6 = getelementptr inbounds i8, i8* %5, i64 1
%7 = load i8, i8* %6
switch i8 %7, label %11 [
i8 0, label %15
i8 47, label %8
]
8: ; preds = %4
%9 = tail call i32 @strlen(i8* %5)
%10 = tail call i32 @memmove(i8* %5, i8* %6, i32 %9)
br label %11
11: ; preds = %4, %8
%12 = phi i8* [ %5, %8 ], [ %6, %4 ]
%13 = tail call i8* @strchr(i8* dereferenceable(1) %12, i8 signext 47)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %4
15: ; preds = %11, %4, %1
ret i8* %0
}