#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*/ fgetwd(char *);
int /*<<< orphan*/ scompare(char *, char *);
int /*<<< orphan*/ sconcat(char *, char *);
int /*<<< orphan*/ scopy(char *, char *, int);
int sfindc(char *, char);
int sfindlc(char *, char);
int slength(char *);
int /*<<< orphan*/ strunc(char *, int);
void fexpand(char *dest, char *src) {
  char buffer[512];
  int ind = 0;
  int nextslash;
  int sl;
  int len = slength(src);
  nextslash = sfindc(src, '/');
  if (nextslash != 0) {
    fgetwd(dest);
  } else {
    dest[0] = '/';
    dest[1] = '\0';
    ind = 1;
  }
  while (ind < len) {
    nextslash = sfindc(src + ind, '/');
    if (nextslash < 0)
      nextslash = len - ind;
    scopy(buffer, src + ind, nextslash);
    if (!scompare(buffer, ".")) {
    } else if (!scompare(buffer, "..")) {
      strunc(dest, slength(dest) - 1);
      sl = sfindlc(dest, '/');
      if (sl < 0) {
        dest[0] = '/';
        dest[1] = '\0';
      } else {
        strunc(dest, sl + 1);
      }
    } else {
      sconcat(dest, buffer);
      sconcat(dest, "/");
    }
    ind += nextslash + 1;
  }
  dest[slength(dest) - 1] = '\0';
}


x86 assembly (clang, -O0):
<fexpand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x214(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <slength@plt>
mov    %eax,-0x220(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <sfindc@plt>
mov    %eax,-0x218(%rbp)
cmpl   $0x0,-0x218(%rbp)
je     11db <fexpand+0x5b>
mov    -0x8(%rbp),%rdi
call   1090 <fgetwd@plt>
jmp    11f4 <fexpand+0x74>
mov    -0x8(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0x1(%rax)
movl   $0x1,-0x214(%rbp)
jmp    11f9 <fexpand+0x79>
mov    -0x214(%rbp),%eax
cmp    -0x220(%rbp),%eax
jge    1355 <fexpand+0x1d5>
mov    -0x10(%rbp),%rdi
movslq -0x214(%rbp),%rax
add    %rax,%rdi
mov    $0x2f,%esi
call   1070 <sfindc@plt>
mov    %eax,-0x218(%rbp)
cmpl   $0x0,-0x218(%rbp)
jge    1248 <fexpand+0xc8>
mov    -0x220(%rbp),%eax
sub    -0x214(%rbp),%eax
mov    %eax,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x214(%rbp),%rax
add    %rax,%rsi
mov    -0x218(%rbp),%edx
call   1040 <scopy@plt>
lea    -0x210(%rbp),%rdi
lea    0xd8b(%rip),%rsi
call   1030 <scompare@plt>
cmp    $0x0,%eax
jne    1289 <fexpand+0x109>
jmp    133b <fexpand+0x1bb>
lea    -0x210(%rbp),%rdi
lea    0xd69(%rip),%rsi
call   1030 <scompare@plt>
cmp    $0x0,%eax
jne    1316 <fexpand+0x196>
mov    -0x8(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    -0x8(%rbp),%rdi
call   10a0 <slength@plt>
mov    -0x228(%rbp),%rdi
mov    %eax,%esi
sub    $0x1,%esi
call   1080 <strunc@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <sfindlc@plt>
mov    %eax,-0x21c(%rbp)
cmpl   $0x0,-0x21c(%rbp)
jge    12ff <fexpand+0x17f>
mov    -0x8(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    1311 <fexpand+0x191>
mov    -0x8(%rbp),%rdi
mov    -0x21c(%rbp),%esi
add    $0x1,%esi
call   1080 <strunc@plt>
jmp    1336 <fexpand+0x1b6>
mov    -0x8(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   1050 <sconcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xcd2(%rip),%rsi
call   1050 <sconcat@plt>
jmp    133b <fexpand+0x1bb>
mov    -0x218(%rbp),%eax
add    $0x1,%eax
add    -0x214(%rbp),%eax
mov    %eax,-0x214(%rbp)
jmp    11f9 <fexpand+0x79>
mov    -0x8(%rbp),%rax
mov    %rax,-0x230(%rbp)
mov    -0x8(%rbp),%rdi
call   10a0 <slength@plt>
mov    %eax,%ecx
mov    -0x230(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fexpand>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   10a0 <slength@plt>
mov    %eax,0xc(%rsp)
mov    %rbx,0x18(%rsp)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1070 <sfindc@plt>
test   %eax,%eax
mov    %r14,0x10(%rsp)
je     11cb <fexpand+0x4b>
mov    %r14,%rdi
call   1090 <fgetwd@plt>
xor    %r14d,%r14d
jmp    11d7 <fexpand+0x57>
movw   $0x2f,(%r14)
mov    $0x1,%r14d
mov    0xc(%rsp),%ebx
cmp    %r14d,%ebx
jle    12cd <fexpand+0x14d>
lea    0x20(%rsp),%rbp
jmp    1223 <fexpand+0xa3>
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <sconcat@plt>
mov    %rbx,%rdi
mov    0xc(%rsp),%ebx
lea    0xdf5(%rip),%rsi
call   1050 <sconcat@plt>
add    %r13d,%r14d
add    $0x1,%r14d
cmp    %r14d,%ebx
jle    12cd <fexpand+0x14d>
movslq %r14d,%r15
mov    0x18(%rsp),%rax
lea    (%rax,%r15,1),%r12
mov    %r12,%rdi
mov    $0x2f,%esi
call   1070 <sfindc@plt>
mov    %ebx,%r13d
sub    %r15d,%r13d
test   %eax,%eax
cmovns %eax,%r13d
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
call   1040 <scopy@plt>
mov    %rbp,%rdi
lea    0xda1(%rip),%rsi
call   1030 <scompare@plt>
test   %eax,%eax
je     1213 <fexpand+0x93>
mov    %rbp,%rdi
lea    0xd8d(%rip),%rsi
call   1030 <scompare@plt>
test   %eax,%eax
jne    11f0 <fexpand+0x70>
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <slength@plt>
lea    -0x1(%rax),%esi
mov    %rbx,%rdi
call   1080 <strunc@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1060 <sfindlc@plt>
test   %eax,%eax
js     12bf <fexpand+0x13f>
add    $0x1,%eax
mov    %rbx,%rdi
mov    %eax,%esi
call   1080 <strunc@plt>
mov    0xc(%rsp),%ebx
jmp    1213 <fexpand+0x93>
movw   $0x2f,(%rbx)
mov    0xc(%rsp),%ebx
jmp    1213 <fexpand+0x93>
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <slength@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c"/\00"
define void @fexpand(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [512 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
%10 = load i8*, i8** %4
%11 = call i32 @slength(i8* %10)
store i32 %11, i32* %9
%12 = load i8*, i8** %4
%13 = call i32 @sfindc(i8* %12, i8 signext 47)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = call i32 @fgetwd(i8* %17)
br label %24
19: ; preds = %2
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 47, i8* %21
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8 0, i8* %23
store i32 1, i32* %6
br label %24
24: ; preds = %19, %16
br label %25
25: ; preds = %85, %24
%26 = load i32, i32* %6
%27 = load i32, i32* %9
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %90
29: ; preds = %25
%30 = load i8*, i8** %4
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = call i32 @sfindc(i8* %33, i8 signext 47)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %29
%38 = load i32, i32* %9
%39 = load i32, i32* %6
%40 = sub nsw i32 %38, %39
store i32 %40, i32* %7
br label %41
41: ; preds = %37, %29
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%43 = load i8*, i8** %4
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i32, i32* %7
%48 = call i32 @scopy(i8* %42, i8* %46, i32 %47)
%49 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%50 = call i32 @scompare(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%51 = icmp ne i32 %50, 0
br i1 %51, label %53, label %52
52: ; preds = %41
br label %85
53: ; preds = %41
%54 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%55 = call i32 @scompare(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%56 = icmp ne i32 %55, 0
br i1 %56, label %78, label %57
57: ; preds = %53
%58 = load i8*, i8** %3
%59 = load i8*, i8** %3
%60 = call i32 @slength(i8* %59)
%61 = sub nsw i32 %60, 1
%62 = call i32 @strunc(i8* %58, i32 %61)
%63 = load i8*, i8** %3
%64 = call i32 @sfindlc(i8* %63, i8 signext 47)
store i32 %64, i32* %8
%65 = load i32, i32* %8
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %57
%68 = load i8*, i8** %3
%69 = getelementptr inbounds i8, i8* %68, i64 0
store i8 47, i8* %69
%70 = load i8*, i8** %3
%71 = getelementptr inbounds i8, i8* %70, i64 1
store i8 0, i8* %71
br label %77
72: ; preds = %57
%73 = load i8*, i8** %3
%74 = load i32, i32* %8
%75 = add nsw i32 %74, 1
%76 = call i32 @strunc(i8* %73, i32 %75)
br label %77
77: ; preds = %72, %67
br label %84
78: ; preds = %53
%79 = load i8*, i8** %3
%80 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%81 = call i32 @sconcat(i8* %79, i8* %80)
%82 = load i8*, i8** %3
%83 = call i32 @sconcat(i8* %82, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %84
84: ; preds = %78, %77
br label %85
85: ; preds = %84, %52
%86 = load i32, i32* %7
%87 = add nsw i32 %86, 1
%88 = load i32, i32* %6
%89 = add nsw i32 %88, %87
store i32 %89, i32* %6
br label %25
90: ; preds = %25
%91 = load i8*, i8** %3
%92 = load i8*, i8** %3
%93 = call i32 @slength(i8* %92)
%94 = sub nsw i32 %93, 1
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8, i8* %91, i64 %95
store i8 0, i8* %96
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c"/\00"
define void @fexpand(i8* %0, i8* %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @slength(i8* %1)
%6 = tail call i32 @sfindc(i8* %1, i8 signext 47)
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @fgetwd(i8* %0)
br label %12
10: ; preds = %2
store i8 47, i8* %0
%11 = getelementptr inbounds i8, i8* %0, i64 1
store i8 0, i8* %11
br label %12
12: ; preds = %10, %8
%13 = phi i32 [ 0, %8 ], [ 1, %10 ]
%14 = icmp sgt i32 %5, %13
br i1 %14, label %15, label %48
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %0, i64 1
br label %17
17: ; preds = %15, %44
%18 = phi i32 [ %13, %15 ], [ %46, %44 ]
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %1, i64 %19
%21 = call i32 @sfindc(i8* %20, i8 signext 47)
%22 = icmp slt i32 %21, 0
%23 = sub nsw i32 %5, %18
%24 = select i1 %22, i32 %23, i32 %21
%25 = call i32 @scopy(i8* %4, i8* %20, i32 %24)
%26 = call i32 @scompare(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i32 %26, 0
br i1 %27, label %44, label %28
28: ; preds = %17
%29 = call i32 @scompare(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %41
31: ; preds = %28
%32 = call i32 @slength(i8* %0)
%33 = add nsw i32 %32, -1
%34 = call i32 @strunc(i8* %0, i32 %33)
%35 = call i32 @sfindlc(i8* %0, i8 signext 47)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %31
store i8 47, i8* %0
store i8 0, i8* %16
br label %44
38: ; preds = %31
%39 = add nuw nsw i32 %35, 1
%40 = call i32 @strunc(i8* %0, i32 %39)
br label %44
41: ; preds = %28
%42 = call i32 @sconcat(i8* %0, i8* %4)
%43 = call i32 @sconcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %44
44: ; preds = %41, %38, %37, %17
%45 = add nsw i32 %18, 1
%46 = add i32 %45, %24
%47 = icmp sgt i32 %5, %46
br i1 %47, label %17, label %48
48: ; preds = %44, %12
%49 = call i32 @slength(i8* %0)
%50 = add nsw i32 %49, -1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %0, i64 %51
store i8 0, i8* %52
ret void
}