#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*/ strcat(char *, char *);
char *strchr(char const *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
const char *unixify(const char *name) {
  static char piece[512];
  const char *s;
  char *p;
  if (strchr(name, '/') != 0) {
    strcpy(piece, name);
    return piece;
  }
  p = piece;
  *p = 0;
  s = strchr(name, ':');
  if (s != 0) {
    int l = s - name;
    *p++ = '/';
    *p++ = '/';
    strncpy(p, name, l);
    p += l;
  }
  *p++ = '/';
  s = strchr(name, '[');
  if (s != 0) {
    s++;
    switch (*s) {
    case ']':
      strcat(p, "./");
      break;
    case '-':
      strcat(p, "../");
      break;
    case '.':
      strcat(p, "./");
      break;
    default:
      s--;
      break;
    }
    s++;
    while (*s) {
      if (*s == '.')
        *p++ = '/';
      else
        *p++ = *s;
      s++;
      if (*s == ']') {
        s++;
        break;
      }
    }
    if (*s != 0) {
      if (*(p - 1) != '/')
        *p++ = '/';
      strcpy(p, s);
    }
  } else {
    *p++ = 0;
  }
  if (*(p - 1) != '/')
    *p++ = '/';
  *p = 0;
  return piece;
}


x86 assembly (clang, -O0):
<unixify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     1184 <unixify+0x44>
mov    -0x10(%rbp),%rsi
lea    0x2ee1(%rip),%rdi
call   1040 <strcpy@plt>
lea    0x2ed5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13db <unixify+0x29b>
lea    0x2ec5(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1206 <unixify+0xc6>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2f,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2f,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2f,(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x5b,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1394 <unixify+0x254>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x28(%rbp)
sub    $0x2d,%eax
je     1290 <unixify+0x150>
jmp    1259 <unixify+0x119>
mov    -0x28(%rbp),%eax
sub    $0x2e,%eax
je     12a5 <unixify+0x165>
jmp    126a <unixify+0x12a>
mov    -0x28(%rbp),%eax
sub    $0x5d,%eax
jne    12ba <unixify+0x17a>
jmp    127b <unixify+0x13b>
mov    -0x20(%rbp),%rdi
lea    0xd7b(%rip),%rsi
call   1060 <strcat@plt>
jmp    12c6 <unixify+0x186>
mov    -0x20(%rbp),%rdi
lea    0xd65(%rip),%rsi
call   1060 <strcat@plt>
jmp    12c6 <unixify+0x186>
mov    -0x20(%rbp),%rdi
lea    0xd51(%rip),%rsi
call   1060 <strcat@plt>
jmp    12c6 <unixify+0x186>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     134f <unixify+0x20f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1306 <unixify+0x1c6>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2f,(%rax)
jmp    131d <unixify+0x1dd>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5d,%eax
jne    134a <unixify+0x20a>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    134f <unixify+0x20f>
jmp    12d2 <unixify+0x192>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     138f <unixify+0x24f>
mov    -0x20(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
je     1382 <unixify+0x242>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2f,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    13a6 <unixify+0x266>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
je     13c9 <unixify+0x289>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2f,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2c79(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unixify>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     116b <unixify+0x2b>
lea    0x2ef2(%rip),%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
jmp    1272 <unixify+0x132>
movb   $0x0,0x2ede(%rip)
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11b9 <unixify+0x79>
mov    %rax,%r14
sub    %rbx,%r14
movw   $0x2f2f,0x2ebd(%rip)
2f 2f
lea    0x2eb6(%rip),%r15
lea    0x2eb1(%rip),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
movslq %r14d,%rax
lea    (%rax,%r15,1),%r14
add    $0x2,%r14
jmp    11c0 <unixify+0x80>
lea    0x2e90(%rip),%r14
movb   $0x2f,(%r14)
mov    %rbx,%rdi
mov    $0x5b,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     127f <unixify+0x13f>
mov    %rax,%rbx
add    $0x1,%r14
movsbl 0x1(%rax),%eax
lea    0xe15(%rip),%rsi
cmp    $0x5d,%eax
je     1202 <unixify+0xc2>
cmp    $0x2e,%eax
je     1202 <unixify+0xc2>
cmp    $0x2d,%eax
jne    120e <unixify+0xce>
lea    0xdfe(%rip),%rsi
add    $0x1,%rbx
mov    %r14,%rdi
call   1060 <strcat@plt>
mov    0x1(%rbx),%al
add    $0x2,%rbx
jmp    1234 <unixify+0xf4>
nopw   0x0(%rax,%rax,1)
mov    %eax,%ecx
mov    %cl,(%r14)
add    $0x1,%r14
movzbl (%rbx),%eax
add    $0x1,%rbx
cmp    $0x5d,%al
je     1240 <unixify+0x100>
mov    $0x2f,%cl
cmp    $0x2e,%al
je     1222 <unixify+0xe2>
test   %al,%al
jne    1220 <unixify+0xe0>
jmp    125f <unixify+0x11f>
cmpb   $0x0,(%rbx)
je     125f <unixify+0x11f>
cmpb   $0x2f,-0x1(%r14)
je     1254 <unixify+0x114>
movb   $0x2f,(%r14)
add    $0x1,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
cmpb   $0x2f,-0x1(%r14)
je     126e <unixify+0x12e>
movb   $0x2f,(%r14)
add    $0x1,%r14
movb   $0x0,(%r14)
lea    0x2dd7(%rip),%rax
pop    %rbx
pop    %r14
pop    %r15
ret
movb   $0x0,0x1(%r14)
add    $0x2,%r14
cmpb   $0x2f,-0x1(%r14)
jne    1266 <unixify+0x126>
jmp    126e <unixify+0x12e>

LLVM IR (-O0):
@unixify.piece = internal global [512 x i8] zeroinitializer
@.str = [3 x i8] c"./\00"
@.str.1 = [4 x i8] c"../\00"
define i8* @unixify(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @strchr(i8* %7, i8 signext 47)
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @strcpy(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @unixify.piece, i64 0, i64 0), i8* %11)
store i8* getelementptr inbounds ([512 x i8], [512 x i8]* @unixify.piece, i64 0, i64 0), i8** %2
br label %127
13: ; preds = %1
store i8* getelementptr inbounds ([512 x i8], [512 x i8]* @unixify.piece, i64 0, i64 0), i8** %5
%14 = load i8*, i8** %5
store i8 0, i8* %14
%15 = load i8*, i8** %3
%16 = call i8* @strchr(i8* %15, i8 signext 58)
store i8* %16, i8** %4
%17 = load i8*, i8** %4
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %38
19: ; preds = %13
%20 = load i8*, i8** %4
%21 = load i8*, i8** %3
%22 = ptrtoint i8* %20 to i64
%23 = ptrtoint i8* %21 to i64
%24 = sub i64 %22, %23
%25 = trunc i64 %24 to i32
store i32 %25, i32* %6
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %5
store i8 47, i8* %26
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %5
store i8 47, i8* %28
%30 = load i8*, i8** %5
%31 = load i8*, i8** %3
%32 = load i32, i32* %6
%33 = call i32 @strncpy(i8* %30, i8* %31, i32 %32)
%34 = load i32, i32* %6
%35 = load i8*, i8** %5
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i8, i8* %35, i64 %36
store i8* %37, i8** %5
br label %38
38: ; preds = %19, %13
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %5
store i8 47, i8* %39
%41 = load i8*, i8** %3
%42 = call i8* @strchr(i8* %41, i8 signext 91)
store i8* %42, i8** %4
%43 = load i8*, i8** %4
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %113
45: ; preds = %38
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %4
%48 = load i8*, i8** %4
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
switch i32 %50, label %60 [
i32 93, label %51
i32 45, label %54
i32 46, label %57
]
51: ; preds = %45
%52 = load i8*, i8** %5
%53 = call i32 @strcat(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %63
54: ; preds = %45
%55 = load i8*, i8** %5
%56 = call i32 @strcat(i8* %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %63
57: ; preds = %45
%58 = load i8*, i8** %5
%59 = call i32 @strcat(i8* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %63
60: ; preds = %45
%61 = load i8*, i8** %4
%62 = getelementptr inbounds i8, i8* %61, i32 -1
store i8* %62, i8** %4
br label %63
63: ; preds = %60, %57, %54, %51
%64 = load i8*, i8** %4
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %4
br label %66
66: ; preds = %93, %63
%67 = load i8*, i8** %4
%68 = load i8, i8* %67
%69 = icmp ne i8 %68, 0
br i1 %69, label %70, label %94
70: ; preds = %66
%71 = load i8*, i8** %4
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = icmp eq i32 %73, 46
br i1 %74, label %75, label %78
75: ; preds = %70
%76 = load i8*, i8** %5
%77 = getelementptr inbounds i8, i8* %76, i32 1
store i8* %77, i8** %5
store i8 47, i8* %76
br label %83
78: ; preds = %70
%79 = load i8*, i8** %4
%80 = load i8, i8* %79
%81 = load i8*, i8** %5
%82 = getelementptr inbounds i8, i8* %81, i32 1
store i8* %82, i8** %5
store i8 %80, i8* %81
br label %83
83: ; preds = %78, %75
%84 = load i8*, i8** %4
%85 = getelementptr inbounds i8, i8* %84, i32 1
store i8* %85, i8** %4
%86 = load i8*, i8** %4
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = icmp eq i32 %88, 93
br i1 %89, label %90, label %93
90: ; preds = %83
%91 = load i8*, i8** %4
%92 = getelementptr inbounds i8, i8* %91, i32 1
store i8* %92, i8** %4
br label %94
93: ; preds = %83
br label %66
94: ; preds = %90, %66
%95 = load i8*, i8** %4
%96 = load i8, i8* %95
%97 = sext i8 %96 to i32
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %112
99: ; preds = %94
%100 = load i8*, i8** %5
%101 = getelementptr inbounds i8, i8* %100, i64 -1
%102 = load i8, i8* %101
%103 = sext i8 %102 to i32
%104 = icmp ne i32 %103, 47
br i1 %104, label %105, label %108
105: ; preds = %99
%106 = load i8*, i8** %5
%107 = getelementptr inbounds i8, i8* %106, i32 1
store i8* %107, i8** %5
store i8 47, i8* %106
br label %108
108: ; preds = %105, %99
%109 = load i8*, i8** %5
%110 = load i8*, i8** %4
%111 = call i32 @strcpy(i8* %109, i8* %110)
br label %112
112: ; preds = %108, %94
br label %116
113: ; preds = %38
%114 = load i8*, i8** %5
%115 = getelementptr inbounds i8, i8* %114, i32 1
store i8* %115, i8** %5
store i8 0, i8* %114
br label %116
116: ; preds = %113, %112
%117 = load i8*, i8** %5
%118 = getelementptr inbounds i8, i8* %117, i64 -1
%119 = load i8, i8* %118
%120 = sext i8 %119 to i32
%121 = icmp ne i32 %120, 47
br i1 %121, label %122, label %125
122: ; preds = %116
%123 = load i8*, i8** %5
%124 = getelementptr inbounds i8, i8* %123, i32 1
store i8* %124, i8** %5
store i8 47, i8* %123
br label %125
125: ; preds = %122, %116
%126 = load i8*, i8** %5
store i8 0, i8* %126
store i8* getelementptr inbounds ([512 x i8], [512 x i8]* @unixify.piece, i64 0, i64 0), i8** %2
br label %127
127: ; preds = %125, %10
%128 = load i8*, i8** %2
ret i8* %128
}

LLVM IR (-O2):
@unixify.piece = internal global [512 x i8] zeroinitializer
@.str = [3 x i8] c"./\00"
@.str.1 = [4 x i8] c"../\00"
define i8* @unixify(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, null
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @strcpy(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @unixify.piece, i64 0, i64 0), i8* %0)
br label %69
6: ; preds = %1
store i8 0, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @unixify.piece, i64 0, i64 0)
%7 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%8 = icmp eq i8* %7, null
br i1 %8, label %18, label %9
9: ; preds = %6
%10 = ptrtoint i8* %7 to i64
%11 = ptrtoint i8* %0 to i64
%12 = sub i64 %10, %11
%13 = trunc i64 %12 to i32
store i8 47, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @unixify.piece, i64 0, i64 0)
store i8 47, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @unixify.piece, i64 0, i64 1)
%14 = tail call i32 @strncpy(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @unixify.piece, i64 0, i64 2), i8* %0, i32 %13)
%15 = shl i64 %12, 32
%16 = ashr exact i64 %15, 32
%17 = getelementptr inbounds i8, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @unixify.piece, i64 0, i64 2), i64 %16
br label %18
18: ; preds = %9, %6
%19 = phi i8* [ %17, %9 ], [ getelementptr inbounds ([512 x i8], [512 x i8]* @unixify.piece, i64 0, i64 0), %6 ]
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8 47, i8* %19
%21 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 91)
%22 = icmp eq i8* %21, null
br i1 %22, label %58, label %23
23: ; preds = %18
%24 = getelementptr inbounds i8, i8* %21, i64 1
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
switch i32 %26, label %31 [
i32 93, label %28
i32 45, label %27
i32 46, label %28
]
27: ; preds = %23
br label %28
28: ; preds = %23, %23, %27
%29 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %27 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %23 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %23 ]
%30 = tail call i32 @strcat(i8* %20, i8* %29)
br label %31
31: ; preds = %28, %23
%32 = phi i8* [ %21, %23 ], [ %24, %28 ]
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = load i8, i8* %33
br label %35
35: ; preds = %40, %31
%36 = phi i8 [ %44, %40 ], [ %34, %31 ]
%37 = phi i8* [ %43, %40 ], [ %33, %31 ]
%38 = phi i8* [ %42, %40 ], [ %20, %31 ]
switch i8 %36, label %39 [
i8 0, label %60
i8 46, label %40
]
39: ; preds = %35
br label %40
40: ; preds = %35, %39
%41 = phi i8 [ %36, %39 ], [ 47, %35 ]
%42 = getelementptr inbounds i8, i8* %38, i64 1
store i8 %41, i8* %38
%43 = getelementptr inbounds i8, i8* %37, i64 1
%44 = load i8, i8* %43
%45 = icmp eq i8 %44, 93
br i1 %45, label %46, label %35
46: ; preds = %40
%47 = getelementptr inbounds i8, i8* %37, i64 2
%48 = load i8, i8* %47
%49 = icmp eq i8 %48, 0
br i1 %49, label %60, label %50
50: ; preds = %46
%51 = load i8, i8* %38
%52 = icmp eq i8 %51, 47
br i1 %52, label %55, label %53
53: ; preds = %50
%54 = getelementptr inbounds i8, i8* %38, i64 2
store i8 47, i8* %42
br label %55
55: ; preds = %53, %50
%56 = phi i8* [ %54, %53 ], [ %42, %50 ]
%57 = tail call i32 @strcpy(i8* %56, i8* %47)
br label %60
58: ; preds = %18
%59 = getelementptr inbounds i8, i8* %19, i64 2
store i8 0, i8* %20
br label %60
60: ; preds = %35, %46, %55, %58
%61 = phi i8* [ %56, %55 ], [ %42, %46 ], [ %59, %58 ], [ %38, %35 ]
%62 = getelementptr inbounds i8, i8* %61, i64 -1
%63 = load i8, i8* %62
%64 = icmp eq i8 %63, 47
br i1 %64, label %67, label %65
65: ; preds = %60
%66 = getelementptr inbounds i8, i8* %61, i64 1
store i8 47, i8* %61
br label %67
67: ; preds = %65, %60
%68 = phi i8* [ %66, %65 ], [ %61, %60 ]
store i8 0, i8* %68
br label %69
69: ; preds = %67, %4
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @unixify.piece, i64 0, i64 0)
}