#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*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, char const *);
int /*<<< orphan*/ puts(char const *);
int /*<<< orphan*/ stdout;
char *strchr(char const *, char);
char *utflength(char const);
void shorten(const char *path) {
  const char *p = NULL;
  while (*path == '/') {
    fputc('/', stdout);
    ++path;
  }
  while ((p = strchr(path, '/'))) {
    if (*path == '.') {
      fputc('.', stdout);
      ++path;
    }
    printf("%.*s/", utflength(*path), path);
    path = p + 1;
  }
  puts(path);
}


x86 assembly (clang, -O0):
<shorten>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1198 <shorten+0x48>
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
mov    $0x2f,%edi
call   1060 <fputc@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1164 <shorten+0x14>
jmp    119d <shorten+0x4d>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1218 <shorten+0xc8>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11e8 <shorten+0x98>
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
mov    $0x2e,%edi
call   1060 <fputc@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1070 <utflength@plt>
mov    %rax,%rsi
mov    -0x8(%rbp),%rdx
lea    0xdfe(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    119d <shorten+0x4d>
mov    -0x8(%rbp),%rdi
call   1030 <puts@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shorten>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%bpl
cmp    $0x2f,%bpl
jne    118b <shorten+0x3b>
mov    0x2e75(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    (%r14),%esi
mov    $0x2f,%edi
call   1060 <fputc@plt>
movzbl 0x1(%rbx),%ebp
add    $0x1,%rbx
cmp    $0x2f,%bpl
je     1170 <shorten+0x20>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1214 <shorten+0xc4>
mov    %rax,%r15
mov    0x2e39(%rip),%r12
lea    0xe52(%rip),%r14
cmp    $0x2e,%bpl
jne    11d6 <shorten+0x86>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12),%esi
mov    $0x2e,%edi
call   1060 <fputc@plt>
mov    0x1(%rbx),%bpl
add    $0x1,%rbx
movsbl %bpl,%edi
call   1070 <utflength@plt>
mov    %r14,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1050 <printf@plt>
mov    %r15,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1214 <shorten+0xc4>
mov    %rax,%r15
movzbl (%rbx),%ebp
cmp    $0x2e,%bpl
je     11c0 <shorten+0x70>
jmp    11d6 <shorten+0x86>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [6 x i8] c"%.*s/\00"
define void @shorten(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
br label %4
4: ; preds = %9, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 47
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = load i32, i32* @stdout
%11 = call i32 @fputc(i8 signext 47, i32 %10)
%12 = load i8*, i8** %2
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %2
br label %4
14: ; preds = %4
br label %15
15: ; preds = %29, %14
%16 = load i8*, i8** %2
%17 = call i8* @strchr(i8* %16, i8 signext 47)
store i8* %17, i8** %3
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %37
19: ; preds = %15
%20 = load i8*, i8** %2
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 46
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i32, i32* @stdout
%26 = call i32 @fputc(i8 signext 46, i32 %25)
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %2
br label %29
29: ; preds = %24, %19
%30 = load i8*, i8** %2
%31 = load i8, i8* %30
%32 = call i8* @utflength(i8 signext %31)
%33 = load i8*, i8** %2
%34 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %32, i8* %33)
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i64 1
store i8* %36, i8** %2
br label %15
37: ; preds = %15
%38 = load i8*, i8** %2
%39 = call i32 @puts(i8* %38)
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [6 x i8] c"%.*s/\00"
define void @shorten(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 47
br i1 %3, label %9, label %4
4: ; preds = %9, %1
%5 = phi i8 [ %2, %1 ], [ %14, %9 ]
%6 = phi i8* [ %0, %1 ], [ %13, %9 ]
%7 = tail call i8* @strchr(i8* %6, i8 signext 47)
%8 = icmp eq i8* %7, null
br i1 %8, label %36, label %16
9: ; preds = %1, %9
%10 = phi i8* [ %13, %9 ], [ %0, %1 ]
%11 = load i32, i32* @stdout
%12 = tail call i32 @fputc(i8 signext 47, i32 %11)
%13 = getelementptr inbounds i8, i8* %10, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 47
br i1 %15, label %9, label %4
16: ; preds = %4, %34
%17 = phi i8 [ %35, %34 ], [ %5, %4 ]
%18 = phi i8* [ %32, %34 ], [ %7, %4 ]
%19 = phi i8* [ %31, %34 ], [ %6, %4 ]
%20 = icmp eq i8 %17, 46
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i32, i32* @stdout
%23 = tail call i32 @fputc(i8 signext 46, i32 %22)
%24 = getelementptr inbounds i8, i8* %19, i64 1
%25 = load i8, i8* %24
br label %26
26: ; preds = %21, %16
%27 = phi i8 [ %25, %21 ], [ %17, %16 ]
%28 = phi i8* [ %24, %21 ], [ %19, %16 ]
%29 = tail call i8* @utflength(i8 signext %27)
%30 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %29, i8* %28)
%31 = getelementptr inbounds i8, i8* %18, i64 1
%32 = tail call i8* @strchr(i8* %31, i8 signext 47)
%33 = icmp eq i8* %32, null
br i1 %33, label %36, label %34
34: ; preds = %26
%35 = load i8, i8* %31
br label %16
36: ; preds = %26, %4
%37 = phi i8* [ %6, %4 ], [ %31, %26 ]
%38 = tail call i32 @puts(i8* %37)
ret void
}