#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 */
typedef scalar_t__ ino_t;

/* Variables and functions */
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ exit(int);
char *find_name_byino(scalar_t__);
int /*<<< orphan*/ fprintf(char *, char *, ...);
scalar_t__ get_ino_byname(char *);
int /*<<< orphan*/ stderr;
char *stdout;
int main(int argc, char *argv[]) {
  char *dir_stack[256];
  unsigned current_depth = 0;
  for (;;) {
    ino_t current_ino = get_ino_byname(".");
    ino_t parent_ino = get_ino_byname("..");
    if (current_ino == parent_ino) {
      break;
    }
    chdir("..");
    dir_stack[current_depth++] = find_name_byino(current_ino);
    if (current_depth >= 256) {
      fprintf(stderr, "Directory trrr is too deep. \n");
      exit(-1);
    }
  }
  int i = current_depth - 1;
  for (i = current_depth - 1; i >= 0; i--) {
    fprintf(stdout, "/%s", dir_stack[i]);
  }
  fprintf("stdout", "%s\n", current_depth == 0 ? "/" : "");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x814(%rbp)
lea    0xe87(%rip),%rdi
call   1060 <get_ino_byname@plt>
mov    %rax,-0x820(%rbp)
lea    0xe73(%rip),%rdi
call   1060 <get_ino_byname@plt>
mov    %rax,-0x828(%rbp)
mov    -0x820(%rbp),%rax
cmp    -0x828(%rbp),%rax
jne    11b2 <main+0x62>
jmp    121f <main+0xcf>
lea    0xe47(%rip),%rdi
call   1030 <chdir@plt>
mov    -0x820(%rbp),%rdi
call   1040 <find_name_byino@plt>
mov    %rax,%rcx
mov    -0x814(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x814(%rbp)
mov    %eax,%eax
mov    %rcx,-0x810(%rbp,%rax,8)
ff
cmpl   $0x100,-0x814(%rbp)
jb     121a <main+0xca>
mov    0x2de1(%rip),%rax
movslq (%rax),%rdi
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    1173 <main+0x23>
mov    -0x814(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x82c(%rbp)
mov    -0x814(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x82c(%rbp)
cmpl   $0x0,-0x82c(%rbp)
jl     1285 <main+0x135>
mov    0x2d87(%rip),%rax
mov    (%rax),%rdi
movslq -0x82c(%rbp),%rax
mov    -0x810(%rbp,%rax,8),%rdx
ff
lea    0xdb7(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x82c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x82c(%rbp)
jmp    123d <main+0xed>
mov    -0x814(%rbp),%ecx
lea    0xd8e(%rip),%rdx
lea    0xd97(%rip),%rax
cmp    $0x0,%ecx
cmove  %rax,%rdx
lea    0xd7e(%rip),%rdi
lea    0xd7e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800,%rsp
xor    %r12d,%r12d
lea    0xe88(%rip),%r14
lea    0xe80(%rip),%r15
mov    %r14,%rdi
call   1060 <get_ino_byname@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1060 <get_ino_byname@plt>
cmp    %rax,%rbx
je     11e3 <main+0x83>
mov    %r15,%rdi
call   1030 <chdir@plt>
mov    %rbx,%rdi
call   1040 <find_name_byino@plt>
mov    %rax,(%rsp,%r12,8)
add    $0x1,%r12
cmp    $0x100,%r12d
jb     1180 <main+0x20>
mov    0x2e20(%rip),%rax
movslq (%rax),%rcx
lea    0xe39(%rip),%rdi
mov    $0x1d,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    -0x1(%r12),%rax
test   %eax,%eax
js     1229 <main+0xc9>
mov    %eax,%eax
lea    (%rsp,%rax,8),%rbx
mov    0x2ddf(%rip),%r15
lea    0xe21(%rip),%r14
mov    %r12d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%rdi
mov    (%rbx),%rdx
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0xfffffffffffffff8,%rbx
add    $0xffffffff,%ebp
jg     1210 <main+0xb0>
test   %r12d,%r12d
lea    0xdfd(%rip),%rax
lea    0xde6(%rip),%rdx
cmove  %rax,%rdx
lea    0xde0(%rip),%rdi
lea    0xde0(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"Directory trrr is too deep. \0A\00"
@stdout = global i8* null
@.str.3 = [4 x i8] c"/%s\00"
@.str.4 = [7 x i8] c"stdout\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [2 x i8] c"/\00"
@.str.7 = [1 x i8] zeroinitializer
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8*]
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %11
11: ; preds = %34, %2
%12 = call i64 @get_ino_byname(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i64 %12, i64* %8
%13 = call i64 @get_ino_byname(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i64 %13, i64* %9
%14 = load i64, i64* %8
%15 = load i64, i64* %9
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %11
br label %35
18: ; preds = %11
%19 = call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = load i64, i64* %8
%21 = call i8* @find_name_byino(i64 %20)
%22 = load i32, i32* %7
%23 = add i32 %22, 1
store i32 %23, i32* %7
%24 = zext i32 %22 to i64
%25 = getelementptr inbounds [256 x i8*], [256 x i8*]* %6, i64 0, i64 %24
store i8* %21, i8** %25
%26 = load i32, i32* %7
%27 = icmp uge i32 %26, 256
br i1 %27, label %28, label %34
28: ; preds = %18
%29 = load i32, i32* @stderr
%30 = sext i32 %29 to i64
%31 = inttoptr i64 %30 to i8*
%32 = call i32 (i8*, i8*, ...) @fprintf(i8* %31, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %18
br label %11
35: ; preds = %17
%36 = load i32, i32* %7
%37 = sub i32 %36, 1
store i32 %37, i32* %10
%38 = load i32, i32* %7
%39 = sub i32 %38, 1
store i32 %39, i32* %10
br label %40
40: ; preds = %50, %35
%41 = load i32, i32* %10
%42 = icmp sge i32 %41, 0
br i1 %42, label %43, label %53
43: ; preds = %40
%44 = load i8*, i8** @stdout
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [256 x i8*], [256 x i8*]* %6, i64 0, i64 %46
%48 = load i8*, i8** %47
%49 = call i32 (i8*, i8*, ...) @fprintf(i8* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %43
%51 = load i32, i32* %10
%52 = add nsw i32 %51, -1
store i32 %52, i32* %10
br label %40
53: ; preds = %40
%54 = load i32, i32* %7
%55 = icmp eq i32 %54, 0
%56 = zext i1 %55 to i64
%57 = select i1 %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0)
%58 = call i32 (i8*, i8*, ...) @fprintf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %57)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"Directory trrr is too deep. \0A\00"
@stdout = global i8* null
@.str.3 = [4 x i8] c"/%s\00"
@.str.4 = [7 x i8] c"stdout\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [2 x i8] c"/\00"
@.str.7 = [1 x i8] zeroinitializer
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8*]
%4 = bitcast [256 x i8*]* %3 to i8*
br label %5
5: ; preds = %10, %2
%6 = phi i32 [ 0, %2 ], [ %13, %10 ]
%7 = tail call i64 @get_ino_byname(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = tail call i64 @get_ino_byname(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %7, %8
br i1 %9, label %23, label %10
10: ; preds = %5
%11 = tail call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i8* @find_name_byino(i64 %7)
%13 = add i32 %6, 1
%14 = zext i32 %6 to i64
%15 = getelementptr inbounds [256 x i8*], [256 x i8*]* %3, i64 0, i64 %14
store i8* %12, i8** %15
%16 = icmp ugt i32 %13, 255
br i1 %16, label %17, label %5
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i8*
%21 = tail call i64 @fwrite(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 29, i64 1, i8* %20)
%22 = tail call i32 @exit(i32 -1)
unreachable
23: ; preds = %5
%24 = add i32 %6, -1
%25 = icmp sgt i32 %24, -1
br i1 %25, label %26, label %35
26: ; preds = %23, %26
%27 = phi i32 [ %33, %26 ], [ %24, %23 ]
%28 = load i8*, i8** @stdout
%29 = zext i32 %27 to i64
%30 = getelementptr inbounds [256 x i8*], [256 x i8*]* %3, i64 0, i64 %29
%31 = load i8*, i8** %30
%32 = tail call i32 (i8*, i8*, ...) @fprintf(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = add nsw i32 %27, -1
%34 = icmp sgt i32 %27, 0
br i1 %34, label %26, label %35
35: ; preds = %26, %23
%36 = icmp eq i32 %6, 0
%37 = select i1 %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0)
%38 = tail call i32 (i8*, i8*, ...) @fprintf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %37)
ret i32 0
}