#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ NAME_MAX;
int /*<<< orphan*/ O_RDONLY;
int PATH_MAX;
scalar_t__ S_ISLNK(int /*<<< orphan*/);
int chdir(char *);
int close(int);
int /*<<< orphan*/ errno;
int fchdir(int);
int /*<<< orphan*/ *getcwd(char *, int);
int lstat(char *, struct stat *);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
int readlink(char *, char *, int);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char *, char);
char *strtok_r(char *, char *, char **);
char *_realpath(const char *path, char *resolved_path) {
  if (path == NULL) {
    errno = EINVAL;
    return NULL;
  }
  if (resolved_path == NULL) {
    resolved_path = malloc(PATH_MAX);
    if (resolved_path == NULL) {
      return NULL;
    }
  }
  *resolved_path = '\0';
  if (path[0] != ('/')) {
    if (getcwd(resolved_path, PATH_MAX) == NULL) {
      return NULL;
    }
  }
  struct stat sBuf;
  char *p, *dir, pathdup[PATH_MAX], buf[PATH_MAX], *saveptr;
  int len;
  p = strrchr(resolved_path, ('/'));
  strncpy(pathdup, path, PATH_MAX);
  len = strlen(pathdup);
  if (len > 0 && pathdup[len - 1] != ('/')) {
    pathdup[len] = ('/');
    pathdup[len + 1] = '\0';
  }
  dir = strtok_r(pathdup, ("/"), &saveptr);
  while (dir != NULL) {
    if (strncmp(dir, ".", NAME_MAX)) {
      if (!strncmp(dir, "..", NAME_MAX)) {
        *p = '\0';
        p = strrchr(resolved_path, ('/'));
        if (p == NULL) {
          *p = ('/');
        }
      } else {
        len = strlen(resolved_path);
        resolved_path[len] = ('/');
        resolved_path[len + 1] = '\0';
        strncat(resolved_path, dir, PATH_MAX);
        if (lstat(resolved_path, &sBuf) == -1) {
          return NULL;
        }
        if (S_ISLNK(sBuf.st_mode)) {
          if (readlink(resolved_path, buf, PATH_MAX) == -1) {
            return NULL;
          }
          int fd;
          fd = open(".", O_RDONLY);
          if (fd == -1) {
            return NULL;
          }
          p = strrchr(resolved_path, ('/'));
          *p = '\0';
          if (chdir(resolved_path) == -1) {
            return NULL;
          }
          if (_realpath(buf, resolved_path) == NULL) {
            return NULL;
          }
          if (fchdir(fd) == -1) {
            return NULL;
          }
          if (close(fd) == -1) {
            return NULL;
          }
        }
        p = strrchr(resolved_path, ('/'));
      }
    }
    dir = strtok_r(NULL, ("/"), &saveptr);
  }
  return resolved_path;
}


x86 assembly (clang, -O0):
<_realpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    123a <_realpath+0x3a>
mov    0x2da6(%rip),%rax
mov    (%rax),%ecx
mov    0x2da5(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    15f4 <_realpath+0x3f4>
cmpq   $0x0,-0x18(%rbp)
jne    1274 <_realpath+0x74>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   1100 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    126f <_realpath+0x6f>
movq   $0x0,-0x8(%rbp)
jmp    15f4 <_realpath+0x3f4>
jmp    1274 <_realpath+0x74>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     12b9 <_realpath+0xb9>
mov    -0x18(%rbp),%rdi
mov    0x2d5a(%rip),%rax
mov    (%rax),%esi
call   10b0 <getcwd@plt>
cmp    $0x0,%rax
jne    12b4 <_realpath+0xb4>
movq   $0x0,-0x8(%rbp)
jmp    15f4 <_realpath+0x3f4>
jmp    12b9 <_realpath+0xb9>
mov    0x2d30(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x68(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x40(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   10a0 <strrchr@plt>
mov    -0x68(%rbp),%rdi
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
mov    0x2ccc(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    -0x68(%rbp),%rdi
call   1080 <strlen@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jle    1374 <_realpath+0x174>
mov    -0x68(%rbp),%rax
mov    -0x54(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     1374 <_realpath+0x174>
mov    -0x68(%rbp),%rax
movslq -0x54(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x54(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x68(%rbp),%rdi
lea    0xc81(%rip),%rsi
lea    -0x50(%rbp),%rdx
call   10e0 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     15de <_realpath+0x3de>
mov    -0x30(%rbp),%rdi
mov    0x2c16(%rip),%rax
mov    (%rax),%edx
lea    0xc58(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     15c1 <_realpath+0x3c1>
mov    -0x30(%rbp),%rdi
mov    0x2bf3(%rip),%rax
mov    (%rax),%edx
lea    0xc34(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    140d <_realpath+0x20d>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   10a0 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1408 <_realpath+0x208>
mov    -0x28(%rbp),%rax
movb   $0x2f,(%rax)
jmp    15bc <_realpath+0x3bc>
mov    -0x18(%rbp),%rdi
call   1080 <strlen@plt>
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x54(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x54(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    0x2bab(%rip),%rax
mov    (%rax),%edx
call   10c0 <strncat@plt>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10f0 <lstat@plt>
cmp    $0xffffffff,%eax
jne    1476 <_realpath+0x276>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x58(%rbp)
jmp    15ed <_realpath+0x3ed>
mov    -0x20(%rbp),%edi
call   1050 <S_ISLNK@plt>
cmp    $0x0,%rax
je     15aa <_realpath+0x3aa>
mov    -0x70(%rbp),%rsi
mov    -0x18(%rbp),%rdi
mov    0x2b59(%rip),%rax
mov    (%rax),%edx
call   1070 <readlink@plt>
cmp    $0xffffffff,%eax
jne    14bb <_realpath+0x2bb>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x58(%rbp)
jmp    15ed <_realpath+0x3ed>
mov    0x2b1e(%rip),%rax
mov    (%rax),%esi
lea    0xb38(%rip),%rdi
call   1120 <open@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0xffffffff,-0x5c(%rbp)
jne    14f1 <_realpath+0x2f1>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x58(%rbp)
jmp    15ed <_realpath+0x3ed>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   10a0 <strrchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1090 <chdir@plt>
cmp    $0xffffffff,%eax
jne    1530 <_realpath+0x330>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x58(%rbp)
jmp    15ed <_realpath+0x3ed>
mov    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <_realpath@plt>
cmp    $0x0,%rax
jne    155b <_realpath+0x35b>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x58(%rbp)
jmp    15ed <_realpath+0x3ed>
mov    -0x5c(%rbp),%edi
call   1110 <fchdir@plt>
cmp    $0xffffffff,%eax
jne    1580 <_realpath+0x380>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x58(%rbp)
jmp    15ed <_realpath+0x3ed>
mov    -0x5c(%rbp),%edi
call   10d0 <close@plt>
cmp    $0xffffffff,%eax
jne    15a5 <_realpath+0x3a5>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x58(%rbp)
jmp    15ed <_realpath+0x3ed>
jmp    15aa <_realpath+0x3aa>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   10a0 <strrchr@plt>
mov    %rax,-0x28(%rbp)
jmp    15c1 <_realpath+0x3c1>
xor    %eax,%eax
mov    %eax,%edi
lea    0xa34(%rip),%rsi
lea    -0x50(%rbp),%rdx
call   10e0 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
jmp    138c <_realpath+0x18c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x58(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_realpath>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %rdi,%rdi
je     1443 <_realpath+0x243>
mov    %rsi,%r14
mov    %rdi,%r15
test   %rsi,%rsi
jne    123f <_realpath+0x3f>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1100 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     1455 <_realpath+0x255>
movb   $0x0,(%r14)
cmpb   $0x2f,(%r15)
je     1263 <_realpath+0x63>
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   10b0 <getcwd@plt>
test   %rax,%rax
je     1455 <_realpath+0x255>
mov    %rsp,-0x30(%rbp)
mov    0x2d82(%rip),%rcx
mov    (%rcx),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    (%rcx),%ebx
mov    %rsp,%rcx
mov    %rbx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %r14,%rdi
mov    $0x2f,%esi
call   10a0 <strrchr@plt>
mov    %rax,%r12
mov    %r13,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
mov    %r13,%rdi
call   1080 <strlen@plt>
test   %eax,%eax
jle    12d9 <_realpath+0xd9>
lea    -0x1(%rax),%ecx
cmpb   $0x2f,0x0(%r13,%rcx,1)
je     12d9 <_realpath+0xd9>
mov    %eax,%eax
movw   $0x2f,0x0(%r13,%rax,1)
lea    0xd20(%rip),%rsi
lea    -0x48(%rbp),%rdx
mov    %r13,%rdi
call   10e0 <strtok_r@plt>
test   %rax,%rax
je     143a <_realpath+0x23a>
mov    %rax,%r13
mov    0x2cb9(%rip),%r15
mov    0x2cea(%rip),%rbx
jmp    1343 <_realpath+0x143>
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%r12)
mov    %r14,%rdi
mov    $0x2f,%esi
call   10a0 <strrchr@plt>
mov    %rax,%r12
xor    %edi,%edi
lea    0xcd2(%rip),%rsi
lea    -0x48(%rbp),%rdx
call   10e0 <strtok_r@plt>
mov    %rax,%r13
test   %rax,%rax
je     143a <_realpath+0x23a>
mov    (%r15),%edx
mov    %r13,%rdi
lea    0xcb3(%rip),%rsi
call   1040 <strncmp@plt>
test   %rax,%rax
je     1325 <_realpath+0x125>
mov    (%r15),%edx
mov    %r13,%rdi
lea    0xc9b(%rip),%rsi
call   1040 <strncmp@plt>
test   %rax,%rax
je     1310 <_realpath+0x110>
mov    %r14,%rdi
call   1080 <strlen@plt>
cltq
movw   $0x2f,(%r14,%rax,1)
mov    (%rbx),%edx
mov    %r14,%rdi
mov    %r13,%rsi
call   10c0 <strncat@plt>
mov    %r14,%rdi
lea    -0x38(%rbp),%rsi
call   10f0 <lstat@plt>
cmp    $0xffffffff,%eax
je     1437 <_realpath+0x237>
mov    -0x38(%rbp),%edi
call   1050 <S_ISLNK@plt>
test   %rax,%rax
je     1315 <_realpath+0x115>
mov    (%rbx),%edx
mov    %r14,%rdi
mov    -0x40(%rbp),%r12
mov    %r12,%rsi
call   1070 <readlink@plt>
cmp    $0xffffffff,%eax
je     1437 <_realpath+0x237>
mov    0x2c0e(%rip),%rax
mov    (%rax),%esi
lea    0xc28(%rip),%rdi
call   1120 <open@plt>
cmp    $0xffffffff,%eax
je     1437 <_realpath+0x237>
mov    %eax,%ebx
mov    %r14,%rdi
mov    $0x2f,%esi
call   10a0 <strrchr@plt>
movb   $0x0,(%rax)
mov    %r14,%rdi
call   1090 <chdir@plt>
cmp    $0xffffffff,%eax
je     1437 <_realpath+0x237>
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <_realpath@plt>
test   %rax,%rax
je     1437 <_realpath+0x237>
mov    %ebx,%edi
call   1110 <fchdir@plt>
cmp    $0xffffffff,%eax
je     1437 <_realpath+0x237>
mov    %ebx,%edi
call   10d0 <close@plt>
cmp    $0xffffffff,%eax
mov    0x2bbf(%rip),%rbx
jne    1315 <_realpath+0x115>
xor    %r14d,%r14d
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
jmp    1458 <_realpath+0x258>
mov    0x2b7e(%rip),%rax
mov    (%rax),%eax
mov    0x2b7d(%rip),%rcx
mov    %eax,(%rcx)
xor    %r14d,%r14d
mov    %r14,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
@PATH_MAX = global i32 0
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
@NAME_MAX = global i32 0
@.str.2 = [3 x i8] c"..\00"
@O_RDONLY = global i32 0
define i8* @_realpath(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.stat
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%16 = load i8*, i8** %4
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = load i32, i32* @EINVAL
store i32 %19, i32* @errno
store i8* null, i8** %3
br label %171
20: ; preds = %2
%21 = load i8*, i8** %5
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i32, i32* @PATH_MAX
%25 = call i8* @malloc(i32 %24)
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %23
store i8* null, i8** %3
br label %171
29: ; preds = %23
br label %30
30: ; preds = %29, %20
%31 = load i8*, i8** %5
store i8 0, i8* %31
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 47
br i1 %36, label %37, label %44
37: ; preds = %30
%38 = load i8*, i8** %5
%39 = load i32, i32* @PATH_MAX
%40 = call i32* @getcwd(i8* %38, i32 %39)
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %43
42: ; preds = %37
store i8* null, i8** %3
br label %171
43: ; preds = %37
br label %44
44: ; preds = %43, %30
%45 = load i32, i32* @PATH_MAX
%46 = zext i32 %45 to i64
%47 = call i8* @llvm.stacksave()
store i8* %47, i8** %9
%48 = alloca i8, i64 %46
store i64 %46, i64* %10
%49 = load i32, i32* @PATH_MAX
%50 = zext i32 %49 to i64
%51 = alloca i8, i64 %50
store i64 %50, i64* %11
%52 = load i8*, i8** %5
%53 = call i8* @strrchr(i8* %52, i8 signext 47)
store i8* %53, i8** %7
%54 = load i8*, i8** %4
%55 = load i32, i32* @PATH_MAX
%56 = call i32 @strncpy(i8* %48, i8* %54, i32 %55)
%57 = call i32 @strlen(i8* %48)
store i32 %57, i32* %13
%58 = load i32, i32* %13
%59 = icmp sgt i32 %58, 0
br i1 %59, label %60, label %76
60: ; preds = %44
%61 = load i32, i32* %13
%62 = sub nsw i32 %61, 1
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %48, i64 %63
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp ne i32 %66, 47
br i1 %67, label %68, label %76
68: ; preds = %60
%69 = load i32, i32* %13
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %48, i64 %70
store i8 47, i8* %71
%72 = load i32, i32* %13
%73 = add nsw i32 %72, 1
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %48, i64 %74
store i8 0, i8* %75
br label %76
76: ; preds = %68, %60, %44
%77 = call i8* @strtok_r(i8* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %12)
store i8* %77, i8** %8
br label %78
78: ; preds = %165, %76
%79 = load i8*, i8** %8
%80 = icmp ne i8* %79, null
br i1 %80, label %81, label %167
81: ; preds = %78
%82 = load i8*, i8** %8
%83 = load i32, i32* @NAME_MAX
%84 = call i64 @strncmp(i8* %82, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %83)
%85 = icmp ne i64 %84, 0
br i1 %85, label %86, label %165
86: ; preds = %81
%87 = load i8*, i8** %8
%88 = load i32, i32* @NAME_MAX
%89 = call i64 @strncmp(i8* %87, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %88)
%90 = icmp ne i64 %89, 0
br i1 %90, label %100, label %91
91: ; preds = %86
%92 = load i8*, i8** %7
store i8 0, i8* %92
%93 = load i8*, i8** %5
%94 = call i8* @strrchr(i8* %93, i8 signext 47)
store i8* %94, i8** %7
%95 = load i8*, i8** %7
%96 = icmp eq i8* %95, null
br i1 %96, label %97, label %99
97: ; preds = %91
%98 = load i8*, i8** %7
store i8 47, i8* %98
br label %99
99: ; preds = %97, %91
br label %164
100: ; preds = %86
%101 = load i8*, i8** %5
%102 = call i32 @strlen(i8* %101)
store i32 %102, i32* %13
%103 = load i8*, i8** %5
%104 = load i32, i32* %13
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i8, i8* %103, i64 %105
store i8 47, i8* %106
%107 = load i8*, i8** %5
%108 = load i32, i32* %13
%109 = add nsw i32 %108, 1
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i8, i8* %107, i64 %110
store i8 0, i8* %111
%112 = load i8*, i8** %5
%113 = load i8*, i8** %8
%114 = load i32, i32* @PATH_MAX
%115 = call i32 @strncat(i8* %112, i8* %113, i32 %114)
%116 = load i8*, i8** %5
%117 = call i32 @lstat(i8* %116, %struct.stat* %6)
%118 = icmp eq i32 %117, -1
br i1 %118, label %119, label %120
119: ; preds = %100
store i8* null, i8** %3
store i32 1, i32* %14
br label %169
120: ; preds = %100
%121 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%122 = load i32, i32* %121
%123 = call i64 @S_ISLNK(i32 %122)
%124 = icmp ne i64 %123, 0
br i1 %124, label %125, label %161
125: ; preds = %120
%126 = load i8*, i8** %5
%127 = load i32, i32* @PATH_MAX
%128 = call i32 @readlink(i8* %126, i8* %51, i32 %127)
%129 = icmp eq i32 %128, -1
br i1 %129, label %130, label %131
130: ; preds = %125
store i8* null, i8** %3
store i32 1, i32* %14
br label %169
131: ; preds = %125
%132 = load i32, i32* @O_RDONLY
%133 = call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %132)
store i32 %133, i32* %15
%134 = load i32, i32* %15
%135 = icmp eq i32 %134, -1
br i1 %135, label %136, label %137
136: ; preds = %131
store i8* null, i8** %3
store i32 1, i32* %14
br label %169
137: ; preds = %131
%138 = load i8*, i8** %5
%139 = call i8* @strrchr(i8* %138, i8 signext 47)
store i8* %139, i8** %7
%140 = load i8*, i8** %7
store i8 0, i8* %140
%141 = load i8*, i8** %5
%142 = call i32 @chdir(i8* %141)
%143 = icmp eq i32 %142, -1
br i1 %143, label %144, label %145
144: ; preds = %137
store i8* null, i8** %3
store i32 1, i32* %14
br label %169
145: ; preds = %137
%146 = load i8*, i8** %5
%147 = call i8* @_realpath(i8* %51, i8* %146)
%148 = icmp eq i8* %147, null
br i1 %148, label %149, label %150
149: ; preds = %145
store i8* null, i8** %3
store i32 1, i32* %14
br label %169
150: ; preds = %145
%151 = load i32, i32* %15
%152 = call i32 @fchdir(i32 %151)
%153 = icmp eq i32 %152, -1
br i1 %153, label %154, label %155
154: ; preds = %150
store i8* null, i8** %3
store i32 1, i32* %14
br label %169
155: ; preds = %150
%156 = load i32, i32* %15
%157 = call i32 @close(i32 %156)
%158 = icmp eq i32 %157, -1
br i1 %158, label %159, label %160
159: ; preds = %155
store i8* null, i8** %3
store i32 1, i32* %14
br label %169
160: ; preds = %155
br label %161
161: ; preds = %160, %120
%162 = load i8*, i8** %5
%163 = call i8* @strrchr(i8* %162, i8 signext 47)
store i8* %163, i8** %7
br label %164
164: ; preds = %161, %99
br label %165
165: ; preds = %164, %81
%166 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %12)
store i8* %166, i8** %8
br label %78
167: ; preds = %78
%168 = load i8*, i8** %5
store i8* %168, i8** %3
store i32 1, i32* %14
br label %169
169: ; preds = %167, %159, %154, %149, %144, %136, %130, %119
%170 = load i8*, i8** %9
br label %171
171: ; preds = %169, %42, %28, %18
%172 = load i8*, i8** %3
ret i8* %172
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
@PATH_MAX = global i32 0
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
@NAME_MAX = global i32 0
@.str.2 = [3 x i8] c"..\00"
@O_RDONLY = global i32 0
define i8* @_realpath(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = alloca i8*
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = load i32, i32* @EINVAL
store i32 %7, i32* @errno
br label %110
8: ; preds = %2
%9 = icmp eq i8* %1, null
br i1 %9, label %10, label %14
10: ; preds = %8
%11 = load i32, i32* @PATH_MAX
%12 = tail call i8* @malloc(i32 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %110, label %14
14: ; preds = %10, %8
%15 = phi i8* [ %12, %10 ], [ %1, %8 ]
store i8 0, i8* %15
%16 = load i8, i8* %0
%17 = icmp eq i8 %16, 47
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i32, i32* @PATH_MAX
%20 = tail call i32* @getcwd(i8* %15, i32 %19)
%21 = icmp eq i32* %20, null
br i1 %21, label %110, label %22
22: ; preds = %18, %14
%23 = bitcast %struct.stat* %3 to i8*
%24 = load i32, i32* @PATH_MAX
%25 = zext i32 %24 to i64
%26 = tail call i8* @llvm.stacksave()
%27 = alloca i8, i64 %25
%28 = load i32, i32* @PATH_MAX
%29 = zext i32 %28 to i64
%30 = alloca i8, i64 %29
%31 = bitcast i8** %4 to i8*
%32 = tail call i8* @strrchr(i8* %15, i8 signext 47)
%33 = call i32 @strncpy(i8* %27, i8* %0, i32 %28)
%34 = call i32 @strlen(i8* %27)
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %48
36: ; preds = %22
%37 = add nsw i32 %34, -1
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %27, i64 %38
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 47
br i1 %41, label %48, label %42
42: ; preds = %36
%43 = zext i32 %34 to i64
%44 = getelementptr inbounds i8, i8* %27, i64 %43
store i8 47, i8* %44
%45 = add nuw nsw i32 %34, 1
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %27, i64 %46
store i8 0, i8* %47
br label %48
48: ; preds = %42, %36, %22
%49 = call i8* @strtok_r(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4)
%50 = icmp eq i8* %49, null
br i1 %50, label %108, label %51
51: ; preds = %48
%52 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
br label %53
53: ; preds = %51, %104
%54 = phi i8* [ %32, %51 ], [ %105, %104 ]
%55 = phi i8* [ %49, %51 ], [ %106, %104 ]
%56 = load i32, i32* @NAME_MAX
%57 = call i64 @strncmp(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %104, label %59
59: ; preds = %53
%60 = load i32, i32* @NAME_MAX
%61 = call i64 @strncmp(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %60)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %59
store i8 0, i8* %54
%64 = call i8* @strrchr(i8* %15, i8 signext 47)
%65 = icmp ne i8* %64, null
br label %104
66: ; preds = %59
%67 = call i32 @strlen(i8* %15)
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %15, i64 %68
store i8 47, i8* %69
%70 = add nsw i32 %67, 1
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %15, i64 %71
store i8 0, i8* %72
%73 = load i32, i32* @PATH_MAX
%74 = call i32 @strncat(i8* %15, i8* %55, i32 %73)
%75 = call i32 @lstat(i8* %15, %struct.stat* %3)
%76 = icmp eq i32 %75, -1
br i1 %76, label %108, label %77
77: ; preds = %66
%78 = load i32, i32* %52
%79 = call i64 @S_ISLNK(i32 %78)
%80 = icmp eq i64 %79, 0
br i1 %80, label %102, label %81
81: ; preds = %77
%82 = load i32, i32* @PATH_MAX
%83 = call i32 @readlink(i8* %15, i8* %30, i32 %82)
%84 = icmp eq i32 %83, -1
br i1 %84, label %108, label %85
85: ; preds = %81
%86 = load i32, i32* @O_RDONLY
%87 = call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %86)
%88 = icmp eq i32 %87, -1
br i1 %88, label %108, label %89
89: ; preds = %85
%90 = call i8* @strrchr(i8* %15, i8 signext 47)
store i8 0, i8* %90
%91 = call i32 @chdir(i8* %15)
%92 = icmp eq i32 %91, -1
br i1 %92, label %108, label %93
93: ; preds = %89
%94 = call i8* @_realpath(i8* %30, i8* %15)
%95 = icmp eq i8* %94, null
br i1 %95, label %108, label %96
96: ; preds = %93
%97 = call i32 @fchdir(i32 %87)
%98 = icmp eq i32 %97, -1
br i1 %98, label %108, label %99
99: ; preds = %96
%100 = call i32 @close(i32 %87)
%101 = icmp eq i32 %100, -1
br i1 %101, label %108, label %102
102: ; preds = %99, %77
%103 = call i8* @strrchr(i8* %15, i8 signext 47)
br label %104
104: ; preds = %63, %102, %53
%105 = phi i8* [ %103, %102 ], [ %64, %63 ], [ %54, %53 ]
%106 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4)
%107 = icmp eq i8* %106, null
br i1 %107, label %108, label %53
108: ; preds = %99, %66, %81, %104, %85, %89, %93, %96, %48
%109 = phi i8* [ %15, %48 ], [ null, %96 ], [ null, %93 ], [ null, %89 ], [ null, %85 ], [ %15, %104 ], [ null, %81 ], [ null, %66 ], [ null, %99 ]
br label %110
110: ; preds = %18, %10, %108, %6
%111 = phi i8* [ null, %6 ], [ %109, %108 ], [ null, %10 ], [ null, %18 ]
ret i8* %111
}