getpath(filestr) char *filestr;
{
  int n;
  int gpfile;
  char *fulpath;
  struct statb {
    int devn, inum, i[18];
  } x;
  struct entry {
    int jnum;
    char name[16];
  } y;
  if (*filestr == '/') {
    fulpath = filestr;
    return (fulpath);
  }
  fulpath = alloc(1);
  *fulpath = 0;
  setexit();
  if (*fulpath) {
    chdir(fulpath);
    rplstr(&fulpath, dircat("", fulpath));
    rplstr(&fulpath, dircat(fulpath, filestr));
    return (fulpath);
  }
  while (1) {
    stat(".", &x);
    if ((gpfile = open("..", 0)) < 0)
      reset();
    do {
      if ((n = read(gpfile, &y, 16)) < 16)
        reset();
    } while (y.jnum != x.inum);
    close(gpfile);
    if (y.jnum == 1)
      ckroot(y.name, &fulpath);
    rplstr(&fulpath, dircat(y.name, fulpath));
    chdir("..");
  }
}


x86 assembly (clang, -O0):
<getpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11e3 <getpath+0x33>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    1341 <getpath+0x191>
mov    $0x1,%edi
mov    $0x0,%al
call   10a0 <alloc@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    $0x0,%al
call   1090 <setexit@plt>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1262 <getpath+0xb2>
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1040 <chdir@plt>
mov    -0x20(%rbp),%rsi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   10d0 <dircat@plt>
mov    %eax,%esi
lea    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1030 <rplstr@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x0,%al
call   10d0 <dircat@plt>
mov    %eax,%esi
lea    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1030 <rplstr@plt>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    1341 <getpath+0x191>
jmp    1267 <getpath+0xb7>
lea    0xd93(%rip),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x0,%al
call   1080 <stat@plt>
lea    0xd80(%rip),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    129c <getpath+0xec>
mov    $0x0,%al
call   10b0 <reset@plt>
jmp    12a1 <getpath+0xf1>
mov    -0x18(%rbp),%edi
lea    -0x88(%rbp),%rsi
mov    $0x10,%edx
mov    $0x0,%al
call   1070 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x10,%eax
jge    12ca <getpath+0x11a>
mov    $0x0,%al
call   10b0 <reset@plt>
jmp    12cf <getpath+0x11f>
mov    -0x88(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jne    12a1 <getpath+0xf1>
mov    -0x18(%rbp),%edi
mov    $0x0,%al
call   1060 <close@plt>
cmpl   $0x1,-0x88(%rbp)
jne    130b <getpath+0x15b>
lea    -0x88(%rbp),%rdi
add    $0x4,%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1050 <ckroot@plt>
lea    -0x88(%rbp),%rdi
add    $0x4,%rdi
mov    -0x20(%rbp),%rsi
mov    $0x0,%al
call   10d0 <dircat@plt>
mov    %eax,%esi
lea    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1030 <rplstr@plt>
lea    0xccb(%rip),%rdi
mov    $0x0,%al
call   1040 <chdir@plt>
jmp    1267 <getpath+0xb7>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdi,%rbx
cmpb   $0x2f,(%rdi)
je     123a <getpath+0x8a>
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <alloc@plt>
cltq
mov    %rax,0x8(%rsp)
movb   $0x0,(%rax)
xor    %eax,%eax
call   1090 <setexit@plt>
mov    0x8(%rsp),%rbp
cmpb   $0x0,0x0(%rbp)
je     124b <getpath+0x9b>
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <chdir@plt>
lea    0xe03(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   10d0 <dircat@plt>
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <rplstr@plt>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10d0 <dircat@plt>
mov    %rbp,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <rplstr@plt>
mov    0x8(%rsp),%rbx
mov    %ebx,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x14(%rsp),%r12
lea    0x28(%rsp),%r15
lea    0xda4(%rip),%r13
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%rbp
jmp    1295 <getpath+0xe5>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   10d0 <dircat@plt>
mov    %rbp,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <rplstr@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <chdir@plt>
lea    0xd65(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <stat@plt>
mov    %r13,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   10c0 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    12da <getpath+0x12a>
xor    %eax,%eax
call   10b0 <reset@plt>
jmp    12da <getpath+0x12a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x10(%rsp),%eax
cmp    0x2c(%rsp),%eax
je     1300 <getpath+0x150>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x10,%edx
xor    %eax,%eax
call   1070 <read@plt>
cmp    $0xf,%eax
jg     12d0 <getpath+0x120>
xor    %eax,%eax
call   10b0 <reset@plt>
jmp    12d0 <getpath+0x120>
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
xor    %eax,%eax
call   1060 <close@plt>
cmpl   $0x1,0x10(%rsp)
jne    1270 <getpath+0xc0>
mov    %r12,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <ckroot@plt>
jmp    1270 <getpath+0xc0>

LLVM IR (-O0):
%struct.statb = type { i32, i32, [18 x i32] }
%struct.entry = type { i32, [16 x i8] }
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
define i32 @getpath(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.statb
%8 = alloca %struct.entry
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 47
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = load i8*, i8** %3
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = ptrtoint i8* %15 to i32
store i32 %16, i32* %2
br label %76
17: ; preds = %1
%18 = call i32 (i32, ...) bitcast (i32 (...)* @alloc to i32 (i32, ...)*)(i32 1)
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %6
%21 = load i8*, i8** %6
store i8 0, i8* %21
%22 = call i32 (...) @setexit()
%23 = load i8*, i8** %6
%24 = load i8, i8* %23
%25 = icmp ne i8 %24, 0
br i1 %25, label %26, label %38
26: ; preds = %17
%27 = load i8*, i8** %6
%28 = call i32 (i8*, ...) bitcast (i32 (...)* @chdir to i32 (i8*, ...)*)(i8* %27)
%29 = load i8*, i8** %6
%30 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @dircat to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = call i32 (i8**, i32, ...) bitcast (i32 (...)* @rplstr to i32 (i8**, i32, ...)*)(i8** %6, i32 %30)
%32 = load i8*, i8** %6
%33 = load i8*, i8** %3
%34 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @dircat to i32 (i8*, i8*, ...)*)(i8* %32, i8* %33)
%35 = call i32 (i8**, i32, ...) bitcast (i32 (...)* @rplstr to i32 (i8**, i32, ...)*)(i8** %6, i32 %34)
%36 = load i8*, i8** %6
%37 = ptrtoint i8* %36 to i32
store i32 %37, i32* %2
br label %76
38: ; preds = %17
br label %39
39: ; preds = %38, %69
%40 = call i32 (i8*, %struct.statb*, ...) bitcast (i32 (...)* @stat to i32 (i8*, %struct.statb*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %struct.statb* %7)
%41 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 0)
store i32 %41, i32* %5
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 (...) @reset()
br label %45
45: ; preds = %43, %39
br label %46
46: ; preds = %53, %45
%47 = load i32, i32* %5
%48 = call i32 (i32, %struct.entry*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, %struct.entry*, i32, ...)*)(i32 %47, %struct.entry* %8, i32 16)
store i32 %48, i32* %4
%49 = icmp slt i32 %48, 16
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 (...) @reset()
br label %52
52: ; preds = %50, %46
br label %53
53: ; preds = %52
%54 = getelementptr inbounds %struct.entry, %struct.entry* %8, i32 0, i32 0
%55 = load i32, i32* %54
%56 = getelementptr inbounds %struct.statb, %struct.statb* %7, i32 0, i32 1
%57 = load i32, i32* %56
%58 = icmp ne i32 %55, %57
br i1 %58, label %46, label %59
59: ; preds = %53
%60 = load i32, i32* %5
%61 = call i32 (i32, ...) bitcast (i32 (...)* @close to i32 (i32, ...)*)(i32 %60)
%62 = getelementptr inbounds %struct.entry, %struct.entry* %8, i32 0, i32 0
%63 = load i32, i32* %62
%64 = icmp eq i32 %63, 1
br i1 %64, label %65, label %69
65: ; preds = %59
%66 = getelementptr inbounds %struct.entry, %struct.entry* %8, i32 0, i32 1
%67 = getelementptr inbounds [16 x i8], [16 x i8]* %66, i64 0, i64 0
%68 = call i32 (i8*, i8**, ...) bitcast (i32 (...)* @ckroot to i32 (i8*, i8**, ...)*)(i8* %67, i8** %6)
br label %69
69: ; preds = %65, %59
%70 = getelementptr inbounds %struct.entry, %struct.entry* %8, i32 0, i32 1
%71 = getelementptr inbounds [16 x i8], [16 x i8]* %70, i64 0, i64 0
%72 = load i8*, i8** %6
%73 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @dircat to i32 (i8*, i8*, ...)*)(i8* %71, i8* %72)
%74 = call i32 (i8**, i32, ...) bitcast (i32 (...)* @rplstr to i32 (i8**, i32, ...)*)(i8** %6, i32 %73)
%75 = call i32 (i8*, ...) bitcast (i32 (...)* @chdir to i32 (i8*, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %39
76: ; preds = %26, %13
%77 = load i32, i32* %2
ret i32 %77
}

LLVM IR (-O2):
%struct.statb = type { i32, i32, [18 x i32] }
%struct.entry = type { i32, [16 x i8] }
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
define i32 @getpath(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.statb
%4 = alloca %struct.entry
%5 = bitcast i8** %2 to i8*
%6 = bitcast %struct.statb* %3 to i8*
%7 = bitcast %struct.entry* %4 to i8*
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 47
br i1 %9, label %57, label %10
10: ; preds = %1
%11 = tail call i32 (i32, ...) bitcast (i32 (...)* @alloc to i32 (i32, ...)*)(i32 1)
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %2
store i8 0, i8* %13
%14 = tail call i32 (...) @setexit()
%15 = load i8*, i8** %2
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %10
%19 = getelementptr inbounds %struct.entry, %struct.entry* %4, i64 0, i32 0
%20 = getelementptr inbounds %struct.statb, %struct.statb* %3, i64 0, i32 1
%21 = getelementptr inbounds %struct.entry, %struct.entry* %4, i64 0, i32 1, i64 0
br label %30
22: ; preds = %10
%23 = tail call i32 (i8*, ...) bitcast (i32 (...)* @chdir to i32 (i8*, ...)*)(i8* %15)
%24 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @dircat to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %15)
%25 = call i32 (i8**, i32, ...) bitcast (i32 (...)* @rplstr to i32 (i8**, i32, ...)*)(i8** %2, i32 %24)
%26 = load i8*, i8** %2
%27 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @dircat to i32 (i8*, i8*, ...)*)(i8* %26, i8* %0)
%28 = call i32 (i8**, i32, ...) bitcast (i32 (...)* @rplstr to i32 (i8**, i32, ...)*)(i8** %2, i32 %27)
%29 = load i8*, i8** %2
br label %57
30: ; preds = %18, %52
%31 = call i32 (i8*, %struct.statb*, ...) bitcast (i32 (...)* @stat to i32 (i8*, %struct.statb*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %struct.statb* %3)
%32 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 0)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 (...) @reset()
br label %36
36: ; preds = %34, %30
br label %37
37: ; preds = %36, %42
%38 = call i32 (i32, %struct.entry*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, %struct.entry*, i32, ...)*)(i32 %32, %struct.entry* %4, i32 16)
%39 = icmp slt i32 %38, 16
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 (...) @reset()
br label %42
42: ; preds = %37, %40
%43 = load i32, i32* %19
%44 = load i32, i32* %20
%45 = icmp eq i32 %43, %44
br i1 %45, label %46, label %37
46: ; preds = %42
%47 = call i32 (i32, ...) bitcast (i32 (...)* @close to i32 (i32, ...)*)(i32 %32)
%48 = load i32, i32* %19
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 (i8*, i8**, ...) bitcast (i32 (...)* @ckroot to i32 (i8*, i8**, ...)*)(i8* %21, i8** %2)
br label %52
52: ; preds = %50, %46
%53 = load i8*, i8** %2
%54 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @dircat to i32 (i8*, i8*, ...)*)(i8* %21, i8* %53)
%55 = call i32 (i8**, i32, ...) bitcast (i32 (...)* @rplstr to i32 (i8**, i32, ...)*)(i8** %2, i32 %54)
%56 = call i32 (i8*, ...) bitcast (i32 (...)* @chdir to i32 (i8*, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %30
57: ; preds = %1, %22
%58 = phi i8* [ %29, %22 ], [ %0, %1 ]
%59 = ptrtoint i8* %58 to i64
%60 = trunc i64 %59 to i32
ret i32 %60
}