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

/* Variables and functions */
int ELOOP;
int ENAMETOOLONG;
int ENOENT;
int /*<<< orphan*/ MAXSYMLINKS;
int PATH_MAX;
scalar_t__ S_ISLNK(int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *getcwd(char *, int);
scalar_t__ lstat(char *, struct stat *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memmove(char *, char *, size_t);
int readlink(char *, char *, int);
char *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
size_t strlcat(char *, char *, int);
size_t strlcpy(char *, char const *, int);
size_t strlen(char *);
char *strrchr(char *, char);
char *realpath(const char *path, char *resolved) {
  struct stat sb;
  char *p, *q, *s;
  size_t left_len, resolved_len;
  unsigned symlinks;
  int serrno, slen, mem_allocated;
  char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX];
  if (path[0] == '\0') {
    errno = ENOENT;
    return (NULL);
  }
  serrno = errno;
  if (resolved == NULL) {
    resolved = malloc(PATH_MAX);
    if (resolved == NULL)
      return (NULL);
    mem_allocated = 1;
  } else
    mem_allocated = 0;
  symlinks = 0;
  if (path[0] == '/') {
    resolved[0] = '/';
    resolved[1] = '\0';
    if (path[1] == '\0')
      return (resolved);
    resolved_len = 1;
    left_len = strlcpy(left, path + 1, sizeof(left));
  } else {
    if (getcwd(resolved, PATH_MAX) == NULL) {
      if (mem_allocated)
        free(resolved);
      else
        strlcpy(resolved, ".", PATH_MAX);
      return (NULL);
    }
    resolved_len = strlen(resolved);
    left_len = strlcpy(left, path, sizeof(left));
  }
  if (left_len >= sizeof(left) || resolved_len >= PATH_MAX) {
    errno = ENAMETOOLONG;
    goto err;
  }
  while (left_len != 0) {
    p = strchr(left, '/');
    s = p ? p : left + left_len;
    if (s - left >= sizeof(next_token)) {
      errno = ENAMETOOLONG;
      goto err;
    }
    memcpy(next_token, left, s - left);
    next_token[s - left] = '\0';
    left_len -= s - left;
    if (p != NULL)
      memmove(left, s + 1, left_len + 1);
    if (resolved[resolved_len - 1] != '/') {
      if (resolved_len + 1 >= PATH_MAX) {
        errno = ENAMETOOLONG;
        goto err;
      }
      resolved[resolved_len++] = '/';
      resolved[resolved_len] = '\0';
    }
    if (next_token[0] == '\0')
      continue;
    else if (strcmp(next_token, ".") == 0)
      continue;
    else if (strcmp(next_token, "..") == 0) {
      if (resolved_len > 1) {
        resolved[resolved_len - 1] = '\0';
        q = strrchr(resolved, '/') + 1;
        *q = '\0';
        resolved_len = q - resolved;
      }
      continue;
    }
    resolved_len = strlcat(resolved, next_token, PATH_MAX);
    if (resolved_len >= PATH_MAX) {
      errno = ENAMETOOLONG;
      goto err;
    }
    if (lstat(resolved, &sb) != 0) {
      if (errno == ENOENT && p == NULL) {
        errno = serrno;
        return (resolved);
      }
      goto err;
    }
    if (S_ISLNK(sb.st_mode)) {
      if (symlinks++ > MAXSYMLINKS) {
        errno = ELOOP;
        goto err;
      }
      slen = readlink(resolved, symlink, sizeof(symlink) - 1);
      if (slen < 0)
        goto err;
      symlink[slen] = '\0';
      if (symlink[0] == '/') {
        resolved[1] = 0;
        resolved_len = 1;
      } else if (resolved_len > 1) {
        resolved[resolved_len - 1] = '\0';
        q = strrchr(resolved, '/') + 1;
        *q = '\0';
        resolved_len = q - resolved;
      }
      if (p != NULL) {
        if (symlink[slen - 1] != '/') {
          if (slen + 1 >= sizeof(symlink)) {
            errno = ENAMETOOLONG;
            goto err;
          }
          symlink[slen] = '/';
          symlink[slen + 1] = 0;
        }
        left_len = strlcat(symlink, left, sizeof(left));
        if (left_len >= sizeof(left)) {
          errno = ENAMETOOLONG;
          goto err;
        }
      }
      left_len = strlcpy(left, symlink, sizeof(left));
    }
  }
  if (resolved_len > 1 && resolved[resolved_len - 1] == '/')
    resolved[resolved_len - 1] = '\0';
  return (resolved);
err:
  if (mem_allocated)
    free(resolved);
  return (NULL);
}


x86 assembly (clang, -O0):
<realpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2df6(%rip),%rax
mov    (%rax),%ecx
mov    %rcx,-0xb0(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x60(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0xa8(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x68(%rbp)
mov    (%rax),%ecx
mov    %rcx,-0xa0(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x98(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x70(%rbp)
mov    (%rax),%eax
mov    %rax,-0x90(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x88(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x78(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12af <realpath+0xcf>
mov    0x2d20(%rip),%rax
mov    (%rax),%ecx
mov    0x2d2f(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1955 <realpath+0x775>
mov    0x2d12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1303 <realpath+0x123>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
call   10e0 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12f7 <realpath+0x117>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1955 <realpath+0x775>
movl   $0x1,-0x58(%rbp)
jmp    130a <realpath+0x12a>
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1383 <realpath+0x1a3>
mov    -0x18(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1355 <realpath+0x175>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1955 <realpath+0x775>
mov    -0xa8(%rbp),%rdi
mov    -0xb0(%rbp),%rax
movq   $0x1,-0x48(%rbp)
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    %eax,%edx
call   10f0 <strlcpy@plt>
mov    %rax,-0x40(%rbp)
jmp    1411 <realpath+0x231>
mov    -0x18(%rbp),%rdi
mov    0x2c62(%rip),%rax
mov    (%rax),%esi
call   10a0 <getcwd@plt>
cmp    $0x0,%rax
jne    13e4 <realpath+0x204>
cmpl   $0x0,-0x58(%rbp)
je     13b7 <realpath+0x1d7>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    13d0 <realpath+0x1f0>
mov    -0x18(%rbp),%rdi
mov    0x2c2e(%rip),%rax
mov    (%rax),%edx
lea    0xc36(%rip),%rsi
call   10f0 <strlcpy@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1955 <realpath+0x775>
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0xa8(%rbp),%rdi
mov    %rax,%rcx
mov    -0xb0(%rbp),%rax
mov    %rcx,-0x48(%rbp)
mov    -0x10(%rbp),%rsi
mov    %eax,%edx
call   10f0 <strlcpy@plt>
mov    %rax,-0x40(%rbp)
mov    -0xb0(%rbp),%rax
cmp    %rax,-0x40(%rbp)
jae    1439 <realpath+0x259>
mov    -0x48(%rbp),%rax
mov    0x2bc3(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jb     1450 <realpath+0x270>
mov    0x2b80(%rip),%rax
mov    (%rax),%ecx
mov    0x2b7f(%rip),%rax
mov    %ecx,(%rax)
jmp    1933 <realpath+0x753>
jmp    1455 <realpath+0x275>
cmpq   $0x0,-0x40(%rbp)
je     18eb <realpath+0x70b>
mov    -0xa8(%rbp),%rdi
mov    $0x2f,%esi
call   1080 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1490 <realpath+0x2b0>
mov    -0x28(%rbp),%rax
mov    %rax,-0xb8(%rbp)
jmp    14a2 <realpath+0x2c2>
mov    -0xa8(%rbp),%rax
add    -0x40(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0xa0(%rbp),%rcx
mov    -0xa8(%rbp),%rdx
mov    -0xb8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
sub    %rdx,%rax
cmp    %rcx,%rax
jb     14e2 <realpath+0x302>
mov    0x2aee(%rip),%rax
mov    (%rax),%ecx
mov    0x2aed(%rip),%rax
mov    %ecx,(%rax)
jmp    1933 <realpath+0x753>
mov    -0xa8(%rbp),%rsi
mov    -0x98(%rbp),%rdi
mov    -0x38(%rbp),%rax
sub    %rsi,%rax
mov    %eax,%edx
call   10d0 <memcpy@plt>
mov    -0x98(%rbp),%rcx
mov    -0xa8(%rbp),%rax
mov    -0x38(%rbp),%rdx
sub    %rax,%rdx
movb   $0x0,(%rcx,%rdx,1)
mov    -0x38(%rbp),%rcx
sub    %rax,%rcx
mov    -0x40(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1550 <realpath+0x370>
mov    -0xa8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
add    $0x1,%rsi
mov    -0x40(%rbp),%rdx
add    $0x1,%rdx
call   1100 <memmove@plt>
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     15be <realpath+0x3de>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    0x2a78(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jb     159b <realpath+0x3bb>
mov    0x2a35(%rip),%rax
mov    (%rax),%ecx
mov    0x2a34(%rip),%rax
mov    %ecx,(%rax)
jmp    1933 <realpath+0x753>
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x48(%rbp)
movb   $0x2f,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x98(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    15d6 <realpath+0x3f6>
jmp    1455 <realpath+0x275>
mov    -0x98(%rbp),%rdi
lea    0xa1d(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    15f8 <realpath+0x418>
jmp    1455 <realpath+0x275>
mov    -0x98(%rbp),%rdi
lea    0x9fa(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1661 <realpath+0x481>
cmpq   $0x1,-0x48(%rbp)
jbe    165c <realpath+0x47c>
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1090 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x48(%rbp)
jmp    1455 <realpath+0x275>
jmp    1666 <realpath+0x486>
jmp    166b <realpath+0x48b>
mov    -0x98(%rbp),%rsi
mov    -0x18(%rbp),%rdi
mov    0x2973(%rip),%rax
mov    (%rax),%edx
call   1060 <strlcat@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    0x295d(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jb     16b6 <realpath+0x4d6>
mov    0x291a(%rip),%rax
mov    (%rax),%ecx
mov    0x2919(%rip),%rax
mov    %ecx,(%rax)
jmp    1933 <realpath+0x753>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10b0 <lstat@plt>
cmp    $0x0,%rax
je     1715 <realpath+0x535>
mov    0x28f4(%rip),%rax
mov    (%rax),%eax
mov    0x28d3(%rip),%rcx
cmp    (%rcx),%eax
jne    1710 <realpath+0x530>
cmpq   $0x0,-0x28(%rbp)
jne    1710 <realpath+0x530>
mov    -0x50(%rbp),%ecx
mov    0x28ce(%rip),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1955 <realpath+0x775>
jmp    1933 <realpath+0x753>
mov    -0x20(%rbp),%edi
call   1040 <S_ISLNK@plt>
cmp    $0x0,%rax
je     18e6 <realpath+0x706>
mov    -0x4c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x4c(%rbp)
mov    0x28a7(%rip),%rcx
cmp    (%rcx),%eax
jbe    1758 <realpath+0x578>
mov    0x2890(%rip),%rax
mov    (%rax),%ecx
mov    0x2877(%rip),%rax
mov    %ecx,(%rax)
jmp    1933 <realpath+0x753>
mov    -0x88(%rbp),%rsi
mov    -0x90(%rbp),%rax
mov    -0x18(%rbp),%rdi
sub    $0x1,%rax
mov    %eax,%edx
call   1050 <readlink@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    1787 <realpath+0x5a7>
jmp    1933 <realpath+0x753>
mov    -0x88(%rbp),%rax
movslq -0x54(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    17b7 <realpath+0x5d7>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
movq   $0x1,-0x48(%rbp)
jmp    1803 <realpath+0x623>
cmpq   $0x1,-0x48(%rbp)
jbe    17fe <realpath+0x61e>
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1090 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x48(%rbp)
jmp    1803 <realpath+0x623>
cmpq   $0x0,-0x28(%rbp)
je     18c6 <realpath+0x6e6>
mov    -0x88(%rbp),%rax
mov    -0x54(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     1876 <realpath+0x696>
mov    -0x90(%rbp),%rcx
mov    -0x54(%rbp),%eax
add    $0x1,%eax
cltq
cmp    %rcx,%rax
jb     185a <realpath+0x67a>
mov    0x2776(%rip),%rax
mov    (%rax),%ecx
mov    0x2775(%rip),%rax
mov    %ecx,(%rax)
jmp    1933 <realpath+0x753>
mov    -0x88(%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    -0xb0(%rbp),%rax
mov    -0xa8(%rbp),%rsi
mov    -0x88(%rbp),%rdi
mov    %eax,%edx
call   1060 <strlcat@plt>
mov    %rax,%rcx
mov    -0xb0(%rbp),%rax
mov    %rcx,-0x40(%rbp)
cmp    %rax,-0x40(%rbp)
jb     18c1 <realpath+0x6e1>
mov    0x270f(%rip),%rax
mov    (%rax),%ecx
mov    0x270e(%rip),%rax
mov    %ecx,(%rax)
jmp    1933 <realpath+0x753>
jmp    18c6 <realpath+0x6e6>
mov    -0x88(%rbp),%rsi
mov    -0xa8(%rbp),%rdi
mov    -0xb0(%rbp),%rax
mov    %eax,%edx
call   10f0 <strlcpy@plt>
mov    %rax,-0x40(%rbp)
jmp    1455 <realpath+0x275>
cmpq   $0x1,-0x48(%rbp)
jbe    191f <realpath+0x73f>
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    191f <realpath+0x73f>
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1955 <realpath+0x775>
cmpl   $0x0,-0x58(%rbp)
je     1946 <realpath+0x766>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
mov    -0x60(%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    $0x68,%rsp
mov    %rsp,%r14
mov    0x2df5(%rip),%rcx
mov    (%rcx),%r13d
mov    %rsp,%rdx
lea    0xf(%r13),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    (%rcx),%eax
mov    %rsp,%rcx
mov    %rax,-0x40(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rcx,%rsp
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,%rsp
mov    (%rdi),%bl
test   %bl,%bl
je     12a8 <realpath+0xc8>
mov    %rsi,%r12
mov    %rdi,%r15
mov    0x2d7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    %rsi,-0x30(%rbp)
test   %rsi,%rsi
mov    %rcx,-0x58(%rbp)
jne    1272 <realpath+0x92>
mov    -0x40(%rbp),%rdi
call   10e0 <malloc@plt>
mov    %rax,-0x30(%rbp)
test   %rax,%rax
je     1658 <realpath+0x478>
cmp    $0x2f,%bl
jne    12bf <realpath+0xdf>
mov    -0x30(%rbp),%rcx
mov    %rcx,%rax
movw   $0x2f,(%rcx)
cmpb   $0x0,0x1(%r15)
je     165a <realpath+0x47a>
mov    %r13,%rbx
mov    %r12,-0x88(%rbp)
add    $0x1,%r15
mov    $0x1,%r13d
mov    %rax,-0x30(%rbp)
jmp    12f9 <realpath+0x119>
mov    0x2d01(%rip),%rax
mov    (%rax),%eax
mov    0x2d10(%rip),%rcx
mov    %eax,(%rcx)
jmp    1658 <realpath+0x478>
mov    %r14,-0x38(%rbp)
mov    -0x30(%rbp),%r14
mov    %r14,%rdi
mov    -0x40(%rbp),%rsi
call   10a0 <getcwd@plt>
test   %rax,%rax
je     15d2 <realpath+0x3f2>
mov    %r13,%rbx
mov    %r12,-0x88(%rbp)
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %rax,%r13
mov    %r14,-0x30(%rbp)
mov    -0x38(%rbp),%r14
mov    -0x50(%rbp),%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   10f0 <strlcpy@plt>
mov    0x2cb2(%rip),%rcx
mov    %rbx,-0x80(%rbp)
cmp    %rbx,%rax
jae    163a <realpath+0x45a>
mov    %rax,%r12
mov    0x2ccb(%rip),%rax
movslq (%rax),%rax
cmp    %rax,%r13
jae    163a <realpath+0x45a>
mov    %r14,-0x38(%rbp)
test   %r12,%r12
je     15f1 <realpath+0x411>
mov    -0x40(%rbp),%rax
add    $0xffffffff,%eax
mov    %eax,-0x74(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x50(%rbp),%r15
mov    %r13,%rax
jmp    136c <realpath+0x18c>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rax
test   %r12,%r12
je     15f5 <realpath+0x415>
mov    %rax,-0x90(%rbp)
mov    %r15,%rdi
mov    $0x2f,%esi
call   1080 <strchr@plt>
lea    (%r15,%r12,1),%r13
test   %rax,%rax
cmovne %rax,%r13
mov    %r13,%rbx
sub    %r15,%rbx
cmp    -0x40(%rbp),%rbx
jae    162f <realpath+0x44f>
mov    %r12,%r14
mov    %rax,-0x60(%rbp)
mov    -0x68(%rbp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   10d0 <memcpy@plt>
sub    %rbx,%r14
movb   $0x0,(%r12,%rbx,1)
cmpq   $0x0,-0x60(%rbp)
je     13d5 <realpath+0x1f5>
add    $0x1,%r13
lea    0x1(%r14),%rdx
mov    %r15,%rdi
mov    %r13,%rsi
call   1100 <memmove@plt>
mov    %r14,%r12
mov    -0x30(%rbp),%r14
mov    -0x90(%rbp),%rcx
cmpb   $0x2f,-0x1(%rcx,%r14,1)
jne    1400 <realpath+0x220>
mov    %rcx,%r13
mov    -0x68(%rbp),%rbx
cmpb   $0x0,(%rbx)
jne    142b <realpath+0x24b>
jmp    1360 <realpath+0x180>
nopl   0x0(%rax)
lea    0x1(%rcx),%r13
mov    0x2be5(%rip),%rax
movslq (%rax),%rax
cmp    %rax,%r13
mov    -0x68(%rbp),%rbx
jae    162b <realpath+0x44b>
movw   $0x2f,(%r14,%rcx,1)
cmpb   $0x0,(%rbx)
je     1360 <realpath+0x180>
mov    %rbx,%rdi
lea    0xbcc(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1360 <realpath+0x180>
mov    %rbx,%rdi
lea    0xbb3(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
jne    1487 <realpath+0x2a7>
cmp    $0x2,%r13
jb     1360 <realpath+0x180>
movb   $0x0,-0x1(%r13,%r14,1)
mov    %r14,%rdi
mov    $0x2f,%esi
call   1090 <strrchr@plt>
mov    %rax,%r13
movb   $0x0,0x1(%rax)
add    $0x1,%r13
sub    %r14,%r13
jmp    1360 <realpath+0x180>
mov    0x2b62(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strlcat@plt>
mov    %rax,%r13
mov    0x2b4b(%rip),%rax
movslq (%rax),%rax
cmp    %rax,%r13
mov    %r14,-0x30(%rbp)
jae    162f <realpath+0x44f>
mov    %r14,%rdi
lea    -0x70(%rbp),%rsi
call   10b0 <lstat@plt>
test   %rax,%rax
mov    -0x38(%rbp),%r14
jne    166c <realpath+0x48c>
mov    -0x70(%rbp),%edi
call   1040 <S_ISLNK@plt>
test   %rax,%rax
je     15c1 <realpath+0x3e1>
mov    -0x44(%rbp),%eax
mov    0x2af7(%rip),%rcx
cmp    (%rcx),%eax
ja     169b <realpath+0x4bb>
mov    -0x30(%rbp),%rdi
mov    -0x58(%rbp),%rbx
mov    %rbx,%rsi
mov    -0x74(%rbp),%edx
call   1050 <readlink@plt>
test   %eax,%eax
js     1645 <realpath+0x465>
mov    %eax,%r15d
mov    %eax,%r12d
movb   $0x0,(%rbx,%r12,1)
cmpb   $0x2f,(%rbx)
mov    %rbx,%rcx
jne    152f <realpath+0x34f>
mov    -0x30(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    $0x1,%r13d
jmp    155e <realpath+0x37e>
cmp    $0x2,%r13
jb     155e <realpath+0x37e>
mov    -0x30(%rbp),%rbx
movb   $0x0,-0x1(%r13,%rbx,1)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1090 <strrchr@plt>
mov    -0x58(%rbp),%rcx
mov    %rax,%r13
movb   $0x0,0x1(%rax)
add    $0x1,%r13
sub    %rbx,%r13
cmpq   $0x0,-0x60(%rbp)
je     15a7 <realpath+0x3c7>
movslq %r15d,%rax
cmpb   $0x2f,-0x1(%rax,%rcx,1)
je     1588 <realpath+0x3a8>
mov    %r12,%rax
add    $0x1,%rax
cmp    -0x40(%rbp),%eax
jae    1633 <realpath+0x453>
movb   $0x2f,(%rcx,%r12,1)
movb   $0x0,(%rcx,%rax,1)
mov    %rcx,%rdi
mov    -0x50(%rbp),%rsi
mov    -0x80(%rbp),%rbx
mov    %ebx,%edx
call   1060 <strlcat@plt>
mov    -0x58(%rbp),%rcx
cmp    %rbx,%rax
jae    1633 <realpath+0x453>
addl   $0x1,-0x44(%rbp)
mov    -0x50(%rbp),%r15
mov    %r15,%rdi
mov    %rcx,%rsi
mov    -0x80(%rbp),%rdx
call   10f0 <strlcpy@plt>
mov    %rax,%r12
mov    -0x30(%rbp),%r14
test   %r12,%r12
je     15f5 <realpath+0x415>
mov    %r13,%rax
jmp    136c <realpath+0x18c>
test   %r12,%r12
je     161b <realpath+0x43b>
mov    0x2a12(%rip),%rax
mov    (%rax),%edx
lea    0xa1a(%rip),%rsi
mov    %r14,%rdi
call   10f0 <strlcpy@plt>
jmp    1623 <realpath+0x443>
mov    -0x30(%rbp),%r14
cmp    $0x2,%r13
jb     1612 <realpath+0x432>
cmpb   $0x2f,-0x1(%r13,%r14,1)
mov    %r14,%rax
mov    -0x38(%rbp),%r14
jne    165a <realpath+0x47a>
movb   $0x0,-0x1(%rax,%r13,1)
jmp    165a <realpath+0x47a>
mov    %r14,%rax
mov    -0x38(%rbp),%r14
jmp    165a <realpath+0x47a>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    -0x38(%rbp),%r14
jmp    165a <realpath+0x47a>
mov    %r14,-0x30(%rbp)
mov    -0x38(%rbp),%r14
mov    0x2986(%rip),%rcx
mov    (%rcx),%eax
mov    0x2985(%rip),%rcx
mov    %eax,(%rcx)
cmpq   $0x0,-0x88(%rbp)
jne    1658 <realpath+0x478>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    %r14,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2955(%rip),%rax
mov    (%rax),%eax
mov    0x2934(%rip),%rcx
cmp    (%rcx),%eax
mov    -0x60(%rbp),%rax
jne    1645 <realpath+0x465>
test   %rax,%rax
jne    1645 <realpath+0x465>
mov    0x2938(%rip),%rax
mov    -0x78(%rbp),%ecx
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
jmp    165a <realpath+0x47a>
mov    0x2936(%rip),%rcx
jmp    163a <realpath+0x45a>

LLVM IR (-O0):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@ENOENT = global i32 0
@errno = global i32 0
@.str = [2 x i8] c".\00"
@ENAMETOOLONG = global i32 0
@.str.1 = [3 x i8] c"..\00"
@MAXSYMLINKS = global i32 0
@ELOOP = 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 i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
%20 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%21 = load i32, i32* @PATH_MAX
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %16
%24 = alloca i8, i64 %22
store i64 %22, i64* %17
%25 = load i32, i32* @PATH_MAX
%26 = zext i32 %25 to i64
%27 = alloca i8, i64 %26
store i64 %26, i64* %18
%28 = load i32, i32* @PATH_MAX
%29 = zext i32 %28 to i64
%30 = alloca i8, i64 %29
store i64 %29, i64* %19
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %2
%37 = load i32, i32* @ENOENT
store i32 %37, i32* @errno
store i8* null, i8** %3
store i32 1, i32* %20
br label %347
38: ; preds = %2
%39 = load i32, i32* @errno
store i32 %39, i32* %13
%40 = load i8*, i8** %5
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %49
42: ; preds = %38
%43 = load i32, i32* @PATH_MAX
%44 = call i8* @malloc(i32 %43)
store i8* %44, i8** %5
%45 = load i8*, i8** %5
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %48
47: ; preds = %42
store i8* null, i8** %3
store i32 1, i32* %20
br label %347
48: ; preds = %42
store i32 1, i32* %15
br label %50
49: ; preds = %38
store i32 0, i32* %15
br label %50
50: ; preds = %49, %48
store i32 0, i32* %12
%51 = load i8*, i8** %4
%52 = getelementptr inbounds i8, i8* %51, i64 0
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 47
br i1 %55, label %56, label %73
56: ; preds = %50
%57 = load i8*, i8** %5
%58 = getelementptr inbounds i8, i8* %57, i64 0
store i8 47, i8* %58
%59 = load i8*, i8** %5
%60 = getelementptr inbounds i8, i8* %59, i64 1
store i8 0, i8* %60
%61 = load i8*, i8** %4
%62 = getelementptr inbounds i8, i8* %61, i64 1
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %56
%67 = load i8*, i8** %5
store i8* %67, i8** %3
store i32 1, i32* %20
br label %347
68: ; preds = %56
store i64 1, i64* %11
%69 = load i8*, i8** %4
%70 = getelementptr inbounds i8, i8* %69, i64 1
%71 = trunc i64 %22 to i32
%72 = call i64 @strlcpy(i8* %24, i8* %70, i32 %71)
store i64 %72, i64* %10
br label %95
73: ; preds = %50
%74 = load i8*, i8** %5
%75 = load i32, i32* @PATH_MAX
%76 = call i32* @getcwd(i8* %74, i32 %75)
%77 = icmp eq i32* %76, null
br i1 %77, label %78, label %89
78: ; preds = %73
%79 = load i32, i32* %15
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %84
81: ; preds = %78
%82 = load i8*, i8** %5
%83 = call i32 @free(i8* %82)
br label %88
84: ; preds = %78
%85 = load i8*, i8** %5
%86 = load i32, i32* @PATH_MAX
%87 = call i64 @strlcpy(i8* %85, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %86)
br label %88
88: ; preds = %84, %81
store i8* null, i8** %3
store i32 1, i32* %20
br label %347
89: ; preds = %73
%90 = load i8*, i8** %5
%91 = call i64 @strlen(i8* %90)
store i64 %91, i64* %11
%92 = load i8*, i8** %4
%93 = trunc i64 %22 to i32
%94 = call i64 @strlcpy(i8* %24, i8* %92, i32 %93)
store i64 %94, i64* %10
br label %95
95: ; preds = %89, %68
%96 = load i64, i64* %10
%97 = icmp uge i64 %96, %22
br i1 %97, label %103, label %98
98: ; preds = %95
%99 = load i64, i64* %11
%100 = load i32, i32* @PATH_MAX
%101 = sext i32 %100 to i64
%102 = icmp uge i64 %99, %101
br i1 %102, label %103, label %105
103: ; preds = %98, %95
%104 = load i32, i32* @ENAMETOOLONG
store i32 %104, i32* @errno
br label %340
105: ; preds = %98
br label %106
106: ; preds = %321, %207, %186, %182, %105
%107 = load i64, i64* %10
%108 = icmp ne i64 %107, 0
br i1 %108, label %109, label %322
109: ; preds = %106
%110 = call i8* @strchr(i8* %24, i8 signext 47)
store i8* %110, i8** %7
%111 = load i8*, i8** %7
%112 = icmp ne i8* %111, null
br i1 %112, label %113, label %115
113: ; preds = %109
%114 = load i8*, i8** %7
br label %118
115: ; preds = %109
%116 = load i64, i64* %10
%117 = getelementptr inbounds i8, i8* %24, i64 %116
br label %118
118: ; preds = %115, %113
%119 = phi i8* [ %114, %113 ], [ %117, %115 ]
store i8* %119, i8** %9
%120 = load i8*, i8** %9
%121 = ptrtoint i8* %120 to i64
%122 = ptrtoint i8* %24 to i64
%123 = sub i64 %121, %122
%124 = icmp uge i64 %123, %26
br i1 %124, label %125, label %127
125: ; preds = %118
%126 = load i32, i32* @ENAMETOOLONG
store i32 %126, i32* @errno
br label %340
127: ; preds = %118
%128 = load i8*, i8** %9
%129 = ptrtoint i8* %128 to i64
%130 = ptrtoint i8* %24 to i64
%131 = sub i64 %129, %130
%132 = trunc i64 %131 to i32
%133 = call i32 @memcpy(i8* %27, i8* %24, i32 %132)
%134 = load i8*, i8** %9
%135 = ptrtoint i8* %134 to i64
%136 = ptrtoint i8* %24 to i64
%137 = sub i64 %135, %136
%138 = getelementptr inbounds i8, i8* %27, i64 %137
store i8 0, i8* %138
%139 = load i8*, i8** %9
%140 = ptrtoint i8* %139 to i64
%141 = ptrtoint i8* %24 to i64
%142 = sub i64 %140, %141
%143 = load i64, i64* %10
%144 = sub i64 %143, %142
store i64 %144, i64* %10
%145 = load i8*, i8** %7
%146 = icmp ne i8* %145, null
br i1 %146, label %147, label %153
147: ; preds = %127
%148 = load i8*, i8** %9
%149 = getelementptr inbounds i8, i8* %148, i64 1
%150 = load i64, i64* %10
%151 = add i64 %150, 1
%152 = call i32 @memmove(i8* %24, i8* %149, i64 %151)
br label %153
153: ; preds = %147, %127
%154 = load i8*, i8** %5
%155 = load i64, i64* %11
%156 = sub i64 %155, 1
%157 = getelementptr inbounds i8, i8* %154, i64 %156
%158 = load i8, i8* %157
%159 = sext i8 %158 to i32
%160 = icmp ne i32 %159, 47
br i1 %160, label %161, label %177
161: ; preds = %153
%162 = load i64, i64* %11
%163 = add i64 %162, 1
%164 = load i32, i32* @PATH_MAX
%165 = sext i32 %164 to i64
%166 = icmp uge i64 %163, %165
br i1 %166, label %167, label %169
167: ; preds = %161
%168 = load i32, i32* @ENAMETOOLONG
store i32 %168, i32* @errno
br label %340
169: ; preds = %161
%170 = load i8*, i8** %5
%171 = load i64, i64* %11
%172 = add i64 %171, 1
store i64 %172, i64* %11
%173 = getelementptr inbounds i8, i8* %170, i64 %171
store i8 47, i8* %173
%174 = load i8*, i8** %5
%175 = load i64, i64* %11
%176 = getelementptr inbounds i8, i8* %174, i64 %175
store i8 0, i8* %176
br label %177
177: ; preds = %169, %153
%178 = getelementptr inbounds i8, i8* %27, i64 0
%179 = load i8, i8* %178
%180 = sext i8 %179 to i32
%181 = icmp eq i32 %180, 0
br i1 %181, label %182, label %183
182: ; preds = %177
br label %106
183: ; preds = %177
%184 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%185 = icmp eq i64 %184, 0
br i1 %185, label %186, label %187
186: ; preds = %183
br label %106
187: ; preds = %183
%188 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%189 = icmp eq i64 %188, 0
br i1 %189, label %190, label %208
190: ; preds = %187
%191 = load i64, i64* %11
%192 = icmp ugt i64 %191, 1
br i1 %192, label %193, label %207
193: ; preds = %190
%194 = load i8*, i8** %5
%195 = load i64, i64* %11
%196 = sub i64 %195, 1
%197 = getelementptr inbounds i8, i8* %194, i64 %196
store i8 0, i8* %197
%198 = load i8*, i8** %5
%199 = call i8* @strrchr(i8* %198, i8 signext 47)
%200 = getelementptr inbounds i8, i8* %199, i64 1
store i8* %200, i8** %8
%201 = load i8*, i8** %8
store i8 0, i8* %201
%202 = load i8*, i8** %8
%203 = load i8*, i8** %5
%204 = ptrtoint i8* %202 to i64
%205 = ptrtoint i8* %203 to i64
%206 = sub i64 %204, %205
store i64 %206, i64* %11
br label %207
207: ; preds = %193, %190
br label %106
208: ; preds = %187
br label %209
209: ; preds = %208
br label %210
210: ; preds = %209
%211 = load i8*, i8** %5
%212 = load i32, i32* @PATH_MAX
%213 = call i64 @strlcat(i8* %211, i8* %27, i32 %212)
store i64 %213, i64* %11
%214 = load i64, i64* %11
%215 = load i32, i32* @PATH_MAX
%216 = sext i32 %215 to i64
%217 = icmp uge i64 %214, %216
br i1 %217, label %218, label %220
218: ; preds = %210
%219 = load i32, i32* @ENAMETOOLONG
store i32 %219, i32* @errno
br label %340
220: ; preds = %210
%221 = load i8*, i8** %5
%222 = call i64 @lstat(i8* %221, %struct.stat* %6)
%223 = icmp ne i64 %222, 0
br i1 %223, label %224, label %235
224: ; preds = %220
%225 = load i32, i32* @errno
%226 = load i32, i32* @ENOENT
%227 = icmp eq i32 %225, %226
br i1 %227, label %228, label %234
228: ; preds = %224
%229 = load i8*, i8** %7
%230 = icmp eq i8* %229, null
br i1 %230, label %231, label %234
231: ; preds = %228
%232 = load i32, i32* %13
store i32 %232, i32* @errno
%233 = load i8*, i8** %5
store i8* %233, i8** %3
store i32 1, i32* %20
br label %347
234: ; preds = %228, %224
br label %340
235: ; preds = %220
%236 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%237 = load i32, i32* %236
%238 = call i64 @S_ISLNK(i32 %237)
%239 = icmp ne i64 %238, 0
br i1 %239, label %240, label %321
240: ; preds = %235
%241 = load i32, i32* %12
%242 = add i32 %241, 1
store i32 %242, i32* %12
%243 = load i32, i32* @MAXSYMLINKS
%244 = icmp ugt i32 %241, %243
br i1 %244, label %245, label %247
245: ; preds = %240
%246 = load i32, i32* @ELOOP
store i32 %246, i32* @errno
br label %340
247: ; preds = %240
%248 = load i8*, i8** %5
%249 = sub i64 %29, 1
%250 = trunc i64 %249 to i32
%251 = call i32 @readlink(i8* %248, i8* %30, i32 %250)
store i32 %251, i32* %14
%252 = load i32, i32* %14
%253 = icmp slt i32 %252, 0
br i1 %253, label %254, label %255
254: ; preds = %247
br label %340
255: ; preds = %247
%256 = load i32, i32* %14
%257 = sext i32 %256 to i64
%258 = getelementptr inbounds i8, i8* %30, i64 %257
store i8 0, i8* %258
%259 = getelementptr inbounds i8, i8* %30, i64 0
%260 = load i8, i8* %259
%261 = sext i8 %260 to i32
%262 = icmp eq i32 %261, 47
br i1 %262, label %263, label %266
263: ; preds = %255
%264 = load i8*, i8** %5
%265 = getelementptr inbounds i8, i8* %264, i64 1
store i8 0, i8* %265
store i64 1, i64* %11
br label %284
266: ; preds = %255
%267 = load i64, i64* %11
%268 = icmp ugt i64 %267, 1
br i1 %268, label %269, label %283
269: ; preds = %266
%270 = load i8*, i8** %5
%271 = load i64, i64* %11
%272 = sub i64 %271, 1
%273 = getelementptr inbounds i8, i8* %270, i64 %272
store i8 0, i8* %273
%274 = load i8*, i8** %5
%275 = call i8* @strrchr(i8* %274, i8 signext 47)
%276 = getelementptr inbounds i8, i8* %275, i64 1
store i8* %276, i8** %8
%277 = load i8*, i8** %8
store i8 0, i8* %277
%278 = load i8*, i8** %8
%279 = load i8*, i8** %5
%280 = ptrtoint i8* %278 to i64
%281 = ptrtoint i8* %279 to i64
%282 = sub i64 %280, %281
store i64 %282, i64* %11
br label %283
283: ; preds = %269, %266
br label %284
284: ; preds = %283, %263
%285 = load i8*, i8** %7
%286 = icmp ne i8* %285, null
br i1 %286, label %287, label %318
287: ; preds = %284
%288 = load i32, i32* %14
%289 = sub nsw i32 %288, 1
%290 = sext i32 %289 to i64
%291 = getelementptr inbounds i8, i8* %30, i64 %290
%292 = load i8, i8* %291
%293 = sext i8 %292 to i32
%294 = icmp ne i32 %293, 47
br i1 %294, label %295, label %310
295: ; preds = %287
%296 = load i32, i32* %14
%297 = add nsw i32 %296, 1
%298 = sext i32 %297 to i64
%299 = icmp uge i64 %298, %29
br i1 %299, label %300, label %302
300: ; preds = %295
%301 = load i32, i32* @ENAMETOOLONG
store i32 %301, i32* @errno
br label %340
302: ; preds = %295
%303 = load i32, i32* %14
%304 = sext i32 %303 to i64
%305 = getelementptr inbounds i8, i8* %30, i64 %304
store i8 47, i8* %305
%306 = load i32, i32* %14
%307 = add nsw i32 %306, 1
%308 = sext i32 %307 to i64
%309 = getelementptr inbounds i8, i8* %30, i64 %308
store i8 0, i8* %309
br label %310
310: ; preds = %302, %287
%311 = trunc i64 %22 to i32
%312 = call i64 @strlcat(i8* %30, i8* %24, i32 %311)
store i64 %312, i64* %10
%313 = load i64, i64* %10
%314 = icmp uge i64 %313, %22
br i1 %314, label %315, label %317
315: ; preds = %310
%316 = load i32, i32* @ENAMETOOLONG
store i32 %316, i32* @errno
br label %340
317: ; preds = %310
br label %318
318: ; preds = %317, %284
%319 = trunc i64 %22 to i32
%320 = call i64 @strlcpy(i8* %24, i8* %30, i32 %319)
store i64 %320, i64* %10
br label %321
321: ; preds = %318, %235
br label %106
322: ; preds = %106
%323 = load i64, i64* %11
%324 = icmp ugt i64 %323, 1
br i1 %324, label %325, label %338
325: ; preds = %322
%326 = load i8*, i8** %5
%327 = load i64, i64* %11
%328 = sub i64 %327, 1
%329 = getelementptr inbounds i8, i8* %326, i64 %328
%330 = load i8, i8* %329
%331 = sext i8 %330 to i32
%332 = icmp eq i32 %331, 47
br i1 %332, label %333, label %338
333: ; preds = %325
%334 = load i8*, i8** %5
%335 = load i64, i64* %11
%336 = sub i64 %335, 1
%337 = getelementptr inbounds i8, i8* %334, i64 %336
store i8 0, i8* %337
br label %338
338: ; preds = %333, %325, %322
%339 = load i8*, i8** %5
store i8* %339, i8** %3
store i32 1, i32* %20
br label %347
340: ; preds = %315, %300, %254, %245, %234, %218, %167, %125, %103
%341 = load i32, i32* %15
%342 = icmp ne i32 %341, 0
br i1 %342, label %343, label %346
343: ; preds = %340
%344 = load i8*, i8** %5
%345 = call i32 @free(i8* %344)
br label %346
346: ; preds = %343, %340
store i8* null, i8** %3
store i32 1, i32* %20
br label %347
347: ; preds = %346, %338, %231, %88, %66, %47, %36
%348 = load i8*, i8** %16
%349 = load i8*, i8** %3
ret i8* %349
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@ENOENT = global i32 0
@errno = global i32 0
@.str = [2 x i8] c".\00"
@ENAMETOOLONG = global i32 0
@.str.1 = [3 x i8] c"..\00"
@MAXSYMLINKS = global i32 0
@ELOOP = global i32 0
define i8* @realpath(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = alloca i8, i64 %10
%12 = alloca i8, i64 %10
%13 = load i8, i8* %0
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = load i32, i32* @ENOENT
store i32 %16, i32* @errno
br label %197
17: ; preds = %2
%18 = load i32, i32* @errno
%19 = icmp eq i8* %1, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = tail call i8* @malloc(i32 %9)
%22 = icmp eq i8* %21, null
br i1 %22, label %197, label %23
23: ; preds = %17, %20
%24 = phi i8* [ %21, %20 ], [ %1, %17 ]
%25 = icmp eq i8 %13, 47
br i1 %25, label %26, label %31
26: ; preds = %23
store i8 47, i8* %24
%27 = getelementptr inbounds i8, i8* %24, i64 1
store i8 0, i8* %27
%28 = getelementptr inbounds i8, i8* %0, i64 1
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
br i1 %30, label %197, label %42
31: ; preds = %23
%32 = tail call i32* @getcwd(i8* %24, i32 %9)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %40
34: ; preds = %31
br i1 %19, label %35, label %37
35: ; preds = %34
%36 = tail call i32 @free(i8* %24)
br label %197
37: ; preds = %34
%38 = load i32, i32* @PATH_MAX
%39 = tail call i64 @strlcpy(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %38)
br label %197
40: ; preds = %31
%41 = tail call i64 @strlen(i8* %24)
br label %42
42: ; preds = %26, %40
%43 = phi i8* [ %0, %40 ], [ %28, %26 ]
%44 = phi i64 [ %41, %40 ], [ 1, %26 ]
%45 = call i64 @strlcpy(i8* %8, i8* %43, i32 %5)
%46 = icmp ult i64 %45, %6
%47 = load i32, i32* @PATH_MAX
%48 = sext i32 %47 to i64
%49 = icmp ult i64 %44, %48
%50 = select i1 %46, i1 %49, i1 false
br i1 %50, label %51, label %191
51: ; preds = %42
%52 = icmp eq i64 %45, 0
br i1 %52, label %182, label %53
53: ; preds = %51
%54 = ptrtoint i8* %8 to i64
%55 = ptrtoint i8* %24 to i64
%56 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%57 = add i32 %9, -1
%58 = getelementptr inbounds i8, i8* %24, i64 1
br label %178
59: ; preds = %178, %110
%60 = phi i64 [ %179, %178 ], [ %73, %110 ]
%61 = phi i64 [ %180, %178 ], [ %111, %110 ]
%62 = call i8* @strchr(i8* %8, i8 signext 47)
%63 = icmp eq i8* %62, null
%64 = getelementptr inbounds i8, i8* %8, i64 %60
%65 = select i1 %63, i8* %64, i8* %62
%66 = ptrtoint i8* %65 to i64
%67 = sub i64 %66, %54
%68 = icmp ult i64 %67, %10
br i1 %68, label %69, label %191
69: ; preds = %59
%70 = trunc i64 %67 to i32
%71 = call i32 @memcpy(i8* %11, i8* %8, i32 %70)
%72 = getelementptr inbounds i8, i8* %11, i64 %67
store i8 0, i8* %72
%73 = sub i64 %60, %67
br i1 %63, label %78, label %74
74: ; preds = %69
%75 = getelementptr inbounds i8, i8* %65, i64 1
%76 = add i64 %73, 1
%77 = call i32 @memmove(i8* %8, i8* %75, i64 %76)
br label %78
78: ; preds = %74, %69
%79 = add i64 %61, -1
%80 = getelementptr inbounds i8, i8* %24, i64 %79
%81 = load i8, i8* %80
%82 = icmp eq i8 %81, 47
br i1 %82, label %91, label %83
83: ; preds = %78
%84 = add i64 %61, 1
%85 = load i32, i32* @PATH_MAX
%86 = sext i32 %85 to i64
%87 = icmp ult i64 %84, %86
br i1 %87, label %88, label %191
88: ; preds = %83
%89 = getelementptr inbounds i8, i8* %24, i64 %61
store i8 47, i8* %89
%90 = getelementptr inbounds i8, i8* %24, i64 %84
store i8 0, i8* %90
br label %91
91: ; preds = %88, %78
%92 = phi i64 [ %84, %88 ], [ %61, %78 ]
%93 = load i8, i8* %11
%94 = icmp eq i8 %93, 0
br i1 %94, label %110, label %95
95: ; preds = %91
%96 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%97 = icmp eq i64 %96, 0
br i1 %97, label %110, label %98
98: ; preds = %95
%99 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%100 = icmp eq i64 %99, 0
br i1 %100, label %101, label %113
101: ; preds = %98
%102 = icmp ugt i64 %92, 1
br i1 %102, label %103, label %110
103: ; preds = %101
%104 = add i64 %92, -1
%105 = getelementptr inbounds i8, i8* %24, i64 %104
store i8 0, i8* %105
%106 = call i8* @strrchr(i8* %24, i8 signext 47)
%107 = getelementptr inbounds i8, i8* %106, i64 1
store i8 0, i8* %107
%108 = ptrtoint i8* %107 to i64
%109 = sub i64 %108, %55
br label %110
110: ; preds = %101, %103, %91, %95
%111 = phi i64 [ %92, %91 ], [ %92, %95 ], [ %109, %103 ], [ %92, %101 ]
%112 = icmp eq i64 %73, 0
br i1 %112, label %182, label %59
113: ; preds = %98
%114 = load i32, i32* @PATH_MAX
%115 = call i64 @strlcat(i8* %24, i8* %11, i32 %114)
%116 = load i32, i32* @PATH_MAX
%117 = sext i32 %116 to i64
%118 = icmp ult i64 %115, %117
br i1 %118, label %119, label %191
119: ; preds = %113
%120 = call i64 @lstat(i8* %24, %struct.stat* %3)
%121 = icmp eq i64 %120, 0
br i1 %121, label %128, label %122
122: ; preds = %119
%123 = load i32, i32* @errno
%124 = load i32, i32* @ENOENT
%125 = icmp eq i32 %123, %124
%126 = select i1 %125, i1 %63, i1 false
br i1 %126, label %127, label %194
127: ; preds = %122
store i32 %18, i32* @errno
br label %197
128: ; preds = %119
%129 = load i32, i32* %56
%130 = call i64 @S_ISLNK(i32 %129)
%131 = icmp eq i64 %130, 0
br i1 %131, label %173, label %132
132: ; preds = %128
%133 = add i32 %181, 1
%134 = load i32, i32* @MAXSYMLINKS
%135 = icmp ugt i32 %181, %134
br i1 %135, label %191, label %136
136: ; preds = %132
%137 = call i32 @readlink(i8* %24, i8* %12, i32 %57)
%138 = icmp slt i32 %137, 0
br i1 %138, label %194, label %139
139: ; preds = %136
%140 = zext i32 %137 to i64
%141 = getelementptr inbounds i8, i8* %12, i64 %140
store i8 0, i8* %141
%142 = load i8, i8* %12
%143 = icmp eq i8 %142, 47
br i1 %143, label %144, label %145
144: ; preds = %139
store i8 0, i8* %58
br label %154
145: ; preds = %139
%146 = icmp ugt i64 %115, 1
br i1 %146, label %147, label %154
147: ; preds = %145
%148 = add i64 %115, -1
%149 = getelementptr inbounds i8, i8* %24, i64 %148
store i8 0, i8* %149
%150 = call i8* @strrchr(i8* %24, i8 signext 47)
%151 = getelementptr inbounds i8, i8* %150, i64 1
store i8 0, i8* %151
%152 = ptrtoint i8* %151 to i64
%153 = sub i64 %152, %55
br label %154
154: ; preds = %145, %147, %144
%155 = phi i64 [ 1, %144 ], [ %153, %147 ], [ %115, %145 ]
br i1 %63, label %171, label %156
156: ; preds = %154
%157 = add nsw i32 %137, -1
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds i8, i8* %12, i64 %158
%160 = load i8, i8* %159
%161 = icmp eq i8 %160, 47
br i1 %161, label %168, label %162
162: ; preds = %156
%163 = add nuw nsw i32 %137, 1
%164 = icmp ult i32 %163, %9
br i1 %164, label %165, label %191
165: ; preds = %162
%166 = zext i32 %163 to i64
store i8 47, i8* %141
%167 = getelementptr inbounds i8, i8* %12, i64 %166
store i8 0, i8* %167
br label %168
168: ; preds = %165, %156
%169 = call i64 @strlcat(i8* %12, i8* %8, i32 %5)
%170 = icmp ult i64 %169, %6
br i1 %170, label %171, label %191
171: ; preds = %168, %154
%172 = call i64 @strlcpy(i8* %8, i8* %12, i32 %5)
br label %173
173: ; preds = %171, %128
%174 = phi i32 [ %133, %171 ], [ %181, %128 ]
%175 = phi i64 [ %155, %171 ], [ %115, %128 ]
%176 = phi i64 [ %172, %171 ], [ %73, %128 ]
%177 = icmp eq i64 %176, 0
br i1 %177, label %182, label %178
178: ; preds = %53, %173
%179 = phi i64 [ %45, %53 ], [ %176, %173 ]
%180 = phi i64 [ %44, %53 ], [ %175, %173 ]
%181 = phi i32 [ 0, %53 ], [ %174, %173 ]
br label %59
182: ; preds = %173, %110, %51
%183 = phi i64 [ %44, %51 ], [ %111, %110 ], [ %175, %173 ]
%184 = icmp ugt i64 %183, 1
br i1 %184, label %185, label %197
185: ; preds = %182
%186 = add i64 %183, -1
%187 = getelementptr inbounds i8, i8* %24, i64 %186
%188 = load i8, i8* %187
%189 = icmp eq i8 %188, 47
br i1 %189, label %190, label %197
190: ; preds = %185
store i8 0, i8* %187
br label %197
191: ; preds = %168, %162, %132, %113, %83, %59, %42
%192 = phi i32* [ @ENAMETOOLONG, %42 ], [ @ENAMETOOLONG, %59 ], [ @ENAMETOOLONG, %83 ], [ @ENAMETOOLONG, %113 ], [ @ELOOP, %132 ], [ @ENAMETOOLONG, %162 ], [ @ENAMETOOLONG, %168 ]
%193 = load i32, i32* %192
store i32 %193, i32* @errno
br label %194
194: ; preds = %136, %191, %122
br i1 %19, label %195, label %197
195: ; preds = %194
%196 = call i32 @free(i8* %24)
br label %197
197: ; preds = %194, %195, %182, %185, %190, %35, %37, %26, %20, %127, %15
%198 = phi i8* [ null, %15 ], [ %24, %127 ], [ null, %20 ], [ %24, %26 ], [ null, %37 ], [ null, %35 ], [ %24, %190 ], [ %24, %185 ], [ %24, %182 ], [ null, %195 ], [ null, %194 ]
ret i8* %198
}