#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 EINVAL;
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 *__restrict path, char *__restrict resolved) {
  struct stat sb;
  char *p, *q, *s;
  size_t left_len, resolved_len;
  unsigned symlinks;
  int serrno, slen, m;
  char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX];
  if (path == NULL) {
    errno = EINVAL;
    return (NULL);
  }
  if (path[0] == '\0') {
    errno = ENOENT;
    return (NULL);
  }
  serrno = errno;
  if (resolved == NULL) {
    resolved = malloc(PATH_MAX);
    if (resolved == NULL)
      return (NULL);
    m = 1;
  } else
    m = 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 (m)
        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) {
    if (m)
      free(resolved);
    errno = ENAMETOOLONG;
    return (NULL);
  }
  while (left_len != 0) {
    p = strchr(left, '/');
    s = p ? p : left + left_len;
    if (s - left >= sizeof(next_token)) {
      if (m)
        free(resolved);
      errno = ENAMETOOLONG;
      return (NULL);
    }
    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) {
        if (m)
          free(resolved);
        errno = ENAMETOOLONG;
        return (NULL);
      }
      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) {
      if (m)
        free(resolved);
      errno = ENAMETOOLONG;
      return (NULL);
    }
    if (lstat(resolved, &sb) != 0) {
      if (errno == ENOENT && p == NULL) {
        errno = serrno;
        return (resolved);
      }
      if (m)
        free(resolved);
      return (NULL);
    }
    if (S_ISLNK(sb.st_mode)) {
      if (symlinks++ > MAXSYMLINKS) {
        if (m)
          free(resolved);
        errno = ELOOP;
        return (NULL);
      }
      slen = readlink(resolved, symlink, sizeof(symlink) - 1);
      if (slen < 0) {
        if (m)
          free(resolved);
        return (NULL);
      }
      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)) {
            if (m)
              free(resolved);
            errno = ENAMETOOLONG;
            return (NULL);
          }
          symlink[slen] = '/';
          symlink[slen + 1] = 0;
        }
        left_len = strlcat(symlink, left, sizeof(left));
        if (left_len >= sizeof(left)) {
          if (m)
            free(resolved);
          errno = ENAMETOOLONG;
          return (NULL);
        }
      }
      left_len = strlcpy(left, symlink, sizeof(left));
    }
  }
  if (resolved_len > 1 && resolved[resolved_len - 1] == '/')
    resolved[resolved_len - 1] = '\0';
  return (resolved);
}


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)
cmpq   $0x0,-0x10(%rbp)
jne    12aa <realpath+0xca>
mov    0x2d35(%rip),%rax
mov    (%rax),%ecx
mov    0x2d34(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a91 <realpath+0x8b1>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12e0 <realpath+0x100>
mov    0x2ce7(%rip),%rax
mov    (%rax),%ecx
mov    0x2cfe(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a91 <realpath+0x8b1>
mov    0x2ce1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1334 <realpath+0x154>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
call   10e0 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1328 <realpath+0x148>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a91 <realpath+0x8b1>
movl   $0x1,-0x58(%rbp)
jmp    133b <realpath+0x15b>
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    13b4 <realpath+0x1d4>
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    1386 <realpath+0x1a6>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a91 <realpath+0x8b1>
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    1442 <realpath+0x262>
mov    -0x18(%rbp),%rdi
mov    0x2c31(%rip),%rax
mov    (%rax),%esi
call   10a0 <getcwd@plt>
cmp    $0x0,%rax
jne    1415 <realpath+0x235>
cmpl   $0x0,-0x58(%rbp)
je     13e8 <realpath+0x208>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    1401 <realpath+0x221>
mov    -0x18(%rbp),%rdi
mov    0x2bfd(%rip),%rax
mov    (%rax),%edx
lea    0xc05(%rip),%rsi
call   10f0 <strlcpy@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a91 <realpath+0x8b1>
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    146a <realpath+0x28a>
mov    -0x48(%rbp),%rax
mov    0x2b92(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jb     14a3 <realpath+0x2c3>
cmpl   $0x0,-0x58(%rbp)
je     147d <realpath+0x29d>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2b34(%rip),%rax
mov    (%rax),%ecx
mov    0x2b3b(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a91 <realpath+0x8b1>
jmp    14a8 <realpath+0x2c8>
cmpq   $0x0,-0x40(%rbp)
je     1a4e <realpath+0x86e>
mov    -0xa8(%rbp),%rdi
mov    $0x2f,%esi
call   1080 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     14e3 <realpath+0x303>
mov    -0x28(%rbp),%rax
mov    %rax,-0xb8(%rbp)
jmp    14f5 <realpath+0x315>
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     1557 <realpath+0x377>
cmpl   $0x0,-0x58(%rbp)
je     1531 <realpath+0x351>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2a80(%rip),%rax
mov    (%rax),%ecx
mov    0x2a87(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a91 <realpath+0x8b1>
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     15c5 <realpath+0x3e5>
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     1655 <realpath+0x475>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    0x2a03(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jb     1632 <realpath+0x452>
cmpl   $0x0,-0x58(%rbp)
je     160c <realpath+0x42c>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x29a5(%rip),%rax
mov    (%rax),%ecx
mov    0x29ac(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a91 <realpath+0x8b1>
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    166d <realpath+0x48d>
jmp    14a8 <realpath+0x2c8>
mov    -0x98(%rbp),%rdi
lea    0x986(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    168f <realpath+0x4af>
jmp    14a8 <realpath+0x2c8>
mov    -0x98(%rbp),%rdi
lea    0x963(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    16f8 <realpath+0x518>
cmpq   $0x1,-0x48(%rbp)
jbe    16f3 <realpath+0x513>
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    14a8 <realpath+0x2c8>
jmp    16fd <realpath+0x51d>
jmp    1702 <realpath+0x522>
mov    -0x98(%rbp),%rsi
mov    -0x18(%rbp),%rdi
mov    0x28dc(%rip),%rax
mov    (%rax),%edx
call   1060 <strlcat@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    0x28c6(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jb     176f <realpath+0x58f>
cmpl   $0x0,-0x58(%rbp)
je     1749 <realpath+0x569>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2868(%rip),%rax
mov    (%rax),%ecx
mov    0x286f(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a91 <realpath+0x8b1>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10b0 <lstat@plt>
cmp    $0x0,%rax
je     17f0 <realpath+0x610>
mov    0x283b(%rip),%rax
mov    (%rax),%eax
mov    0x2812(%rip),%rcx
cmp    (%rcx),%eax
jne    17c9 <realpath+0x5e9>
cmpq   $0x0,-0x28(%rbp)
jne    17c9 <realpath+0x5e9>
mov    -0x50(%rbp),%ecx
mov    0x2815(%rip),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a91 <realpath+0x8b1>
cmpl   $0x0,-0x58(%rbp)
je     17dc <realpath+0x5fc>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a91 <realpath+0x8b1>
mov    -0x20(%rbp),%edi
call   1040 <S_ISLNK@plt>
cmp    $0x0,%rax
je     1a49 <realpath+0x869>
mov    -0x4c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x4c(%rbp)
mov    0x27cc(%rip),%rcx
cmp    (%rcx),%eax
jbe    1855 <realpath+0x675>
cmpl   $0x0,-0x58(%rbp)
je     182f <realpath+0x64f>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x27a2(%rip),%rax
mov    (%rax),%ecx
mov    0x2789(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a91 <realpath+0x8b1>
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    18a6 <realpath+0x6c6>
cmpl   $0x0,-0x58(%rbp)
je     1892 <realpath+0x6b2>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a91 <realpath+0x8b1>
mov    -0x88(%rbp),%rax
movslq -0x54(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    18d6 <realpath+0x6f6>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
movq   $0x1,-0x48(%rbp)
jmp    1922 <realpath+0x742>
cmpq   $0x1,-0x48(%rbp)
jbe    191d <realpath+0x73d>
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    1922 <realpath+0x742>
cmpq   $0x0,-0x28(%rbp)
je     1a29 <realpath+0x849>
mov    -0x88(%rbp),%rax
mov    -0x54(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     19b7 <realpath+0x7d7>
mov    -0x90(%rbp),%rcx
mov    -0x54(%rbp),%eax
add    $0x1,%eax
cltq
cmp    %rcx,%rax
jb     199b <realpath+0x7bb>
cmpl   $0x0,-0x58(%rbp)
je     1975 <realpath+0x795>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x263c(%rip),%rax
mov    (%rax),%ecx
mov    0x2643(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a91 <realpath+0x8b1>
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     1a24 <realpath+0x844>
cmpl   $0x0,-0x58(%rbp)
je     19fe <realpath+0x81e>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x25b3(%rip),%rax
mov    (%rax),%ecx
mov    0x25ba(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a91 <realpath+0x8b1>
jmp    1a29 <realpath+0x849>
mov    -0x88(%rbp),%rsi
mov    -0xa8(%rbp),%rdi
mov    -0xb0(%rbp),%rax
mov    %eax,%edx
call   10f0 <strlcpy@plt>
mov    %rax,-0x40(%rbp)
jmp    14a8 <realpath+0x2c8>
cmpq   $0x1,-0x48(%rbp)
jbe    1a82 <realpath+0x8a2>
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1a82 <realpath+0x8a2>
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)
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    %rdi,%r14
mov    %rsp,%r12
mov    0x2df2(%rip),%rcx
mov    (%rcx),%edx
mov    %rsp,%r13
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    (%rcx),%eax
mov    %rsp,%rcx
mov    %rax,-0x48(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,%rsp
mov    %rsp,%rdi
sub    %rax,%rdi
mov    %rdi,%rsp
test   %r14,%r14
je     12a3 <realpath+0xc3>
mov    %rcx,-0x88(%rbp)
mov    (%r14),%bl
test   %bl,%bl
je     12af <realpath+0xcf>
mov    %rdx,-0x80(%rbp)
mov    0x2d79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    %rsi,-0x30(%rbp)
mov    %rsi,-0x40(%rbp)
test   %rsi,%rsi
mov    %rdi,-0x68(%rbp)
jne    127b <realpath+0x9b>
mov    -0x48(%rbp),%rdi
call   10e0 <malloc@plt>
mov    %rax,-0x30(%rbp)
test   %rax,%rax
je     15eb <realpath+0x40b>
cmp    $0x2f,%bl
jne    12bb <realpath+0xdb>
mov    -0x30(%rbp),%rax
movw   $0x2f,(%rax)
cmpb   $0x0,0x1(%r14)
je     1603 <realpath+0x423>
mov    %r12,%r15
add    $0x1,%r14
mov    $0x1,%r12d
jmp    12e6 <realpath+0x106>
mov    0x2d16(%rip),%rax
jmp    15e0 <realpath+0x400>
mov    0x2cf2(%rip),%rax
jmp    15e0 <realpath+0x400>
mov    -0x30(%rbp),%rbx
mov    %rbx,%rdi
mov    -0x48(%rbp),%rsi
call   10a0 <getcwd@plt>
test   %rax,%rax
je     1609 <realpath+0x429>
mov    %r12,%r15
mov    %rbx,-0x30(%rbp)
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %rax,%r12
mov    %r13,%rdi
mov    %r14,%rsi
mov    -0x80(%rbp),%rbx
mov    %ebx,%edx
call   10f0 <strlcpy@plt>
cmp    %rbx,%rax
jae    15c6 <realpath+0x3e6>
mov    %rax,%rbx
mov    %r12,%r14
mov    0x2ce3(%rip),%rax
movslq (%rax),%rax
cmp    %rax,%r12
jae    15c6 <realpath+0x3e6>
mov    %r15,-0x38(%rbp)
test   %rbx,%rbx
je     162a <realpath+0x44a>
mov    -0x48(%rbp),%rax
add    $0xffffffff,%eax
mov    %eax,-0x74(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    %r14,%rax
jmp    1350 <realpath+0x170>
nopl   0x0(%rax)
mov    -0x58(%rbp),%rbx
mov    %r14,%rax
test   %rbx,%rbx
je     162e <realpath+0x44e>
mov    %rax,-0x90(%rbp)
mov    %r13,%rdi
mov    $0x2f,%esi
call   1080 <strchr@plt>
lea    (%rbx,%r13,1),%r14
test   %rax,%rax
cmovne %rax,%r14
mov    %rbx,%r12
mov    %r14,%rbx
sub    %r13,%rbx
cmp    -0x48(%rbp),%rbx
jae    164e <realpath+0x46e>
mov    %rax,-0x60(%rbp)
mov    %r13,%r15
mov    -0x88(%rbp),%r13
mov    %r13,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   10d0 <memcpy@plt>
sub    %rbx,%r12
movb   $0x0,0x0(%r13,%rbx,1)
mov    %r13,%rbx
mov    %r15,%r13
cmpq   $0x0,-0x60(%rbp)
je     13c7 <realpath+0x1e7>
add    $0x1,%r14
lea    0x1(%r12),%rdx
mov    %r13,%rdi
mov    %r14,%rsi
call   1100 <memmove@plt>
mov    %r12,-0x58(%rbp)
mov    -0x30(%rbp),%r15
mov    -0x90(%rbp),%rcx
cmpb   $0x2f,-0x1(%rcx,%r15,1)
jne    13f0 <realpath+0x210>
mov    %rcx,%r14
cmpb   $0x0,(%rbx)
jne    1417 <realpath+0x237>
jmp    1340 <realpath+0x160>
nopl   0x0(%rax,%rax,1)
lea    0x1(%rcx),%r14
mov    0x2bf5(%rip),%rax
movslq (%rax),%rax
cmp    %rax,%r14
jae    1665 <realpath+0x485>
movw   $0x2f,(%r15,%rcx,1)
cmpb   $0x0,(%rbx)
je     1340 <realpath+0x160>
mov    %rbx,%rdi
lea    0xbe0(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1340 <realpath+0x160>
mov    %rbx,%rdi
lea    0xbc7(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
jne    1477 <realpath+0x297>
cmp    $0x2,%r14
mov    -0x58(%rbp),%rbx
jb     1344 <realpath+0x164>
movb   $0x0,-0x1(%r14,%r15,1)
mov    %r15,%rdi
mov    $0x2f,%esi
call   1090 <strrchr@plt>
mov    %rax,%r14
movb   $0x0,0x1(%rax)
add    $0x1,%r14
sub    %r15,%r14
jmp    1344 <realpath+0x164>
mov    0x2b72(%rip),%r14
mov    (%r14),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <strlcat@plt>
movslq (%r14),%rcx
cmp    %rcx,%rax
jae    1692 <realpath+0x4b2>
mov    %rax,%r14
mov    %r15,%rdi
lea    -0x70(%rbp),%rsi
call   10b0 <lstat@plt>
test   %rax,%rax
mov    -0x38(%rbp),%r12
jne    16a9 <realpath+0x4c9>
mov    -0x70(%rbp),%edi
call   1040 <S_ISLNK@plt>
test   %rax,%rax
je     1515 <realpath+0x335>
mov    -0x4c(%rbp),%eax
mov    0x2b15(%rip),%rcx
cmp    (%rcx),%eax
ja     16d5 <realpath+0x4f5>
mov    %r14,%r12
mov    %r15,%rdi
mov    -0x68(%rbp),%rbx
mov    %rbx,%rsi
mov    -0x74(%rbp),%edx
call   1050 <readlink@plt>
test   %eax,%eax
js     16f0 <realpath+0x510>
mov    %eax,%r14d
mov    %eax,%ecx
movb   $0x0,(%rbx,%rcx,1)
cmpb   $0x2f,(%rbx)
mov    %rbx,%rsi
jne    151e <realpath+0x33e>
mov    -0x30(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    $0x1,%r12d
mov    -0x60(%rbp),%rbx
jmp    155a <realpath+0x37a>
mov    -0x58(%rbp),%rbx
jmp    15b9 <realpath+0x3d9>
cmp    $0x2,%r12
mov    -0x60(%rbp),%rbx
jb     155a <realpath+0x37a>
mov    %r12,%rax
mov    -0x30(%rbp),%r12
movb   $0x0,-0x1(%rax,%r12,1)
mov    %r12,%rdi
mov    $0x2f,%esi
mov    %rcx,%r15
call   1090 <strrchr@plt>
mov    %r15,%rcx
mov    -0x68(%rbp),%rsi
movb   $0x0,0x1(%rax)
add    $0x1,%rax
sub    %r12,%rax
mov    %rax,%r12
test   %rbx,%rbx
mov    -0x80(%rbp),%r15
je     15a0 <realpath+0x3c0>
movslq %r14d,%rax
cmpb   $0x2f,-0x1(%rax,%rsi,1)
je     1585 <realpath+0x3a5>
mov    %rcx,%rax
add    $0x1,%rax
cmp    -0x48(%rbp),%eax
jae    164e <realpath+0x46e>
movb   $0x2f,(%rsi,%rcx,1)
movb   $0x0,(%rsi,%rax,1)
mov    %rsi,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
call   1060 <strlcat@plt>
mov    -0x68(%rbp),%rsi
cmp    %r15,%rax
jae    164e <realpath+0x46e>
addl   $0x1,-0x4c(%rbp)
mov    %r13,%rdi
mov    %r15d,%edx
call   10f0 <strlcpy@plt>
mov    %rax,%rbx
mov    -0x30(%rbp),%r15
mov    %r12,%r14
test   %rbx,%rbx
je     162e <realpath+0x44e>
mov    %r14,%rax
jmp    1350 <realpath+0x170>
cmpq   $0x0,-0x40(%rbp)
mov    %r15,%r12
jne    15d9 <realpath+0x3f9>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    0x29d8(%rip),%rax
mov    (%rax),%eax
mov    0x29df(%rip),%rcx
mov    %eax,(%rcx)
xor    %r15d,%r15d
mov    %r12,%rsp
mov    %r15,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    -0x30(%rbp),%r15
jmp    15ee <realpath+0x40e>
cmpq   $0x0,-0x40(%rbp)
je     165b <realpath+0x47b>
mov    0x29d9(%rip),%rax
mov    (%rax),%edx
lea    0x9e1(%rip),%rsi
mov    %rbx,%rdi
call   10f0 <strlcpy@plt>
jmp    15eb <realpath+0x40b>
mov    -0x30(%rbp),%r15
cmp    $0x2,%r14
jb     1648 <realpath+0x468>
cmpb   $0x2f,-0x1(%r14,%r15,1)
mov    -0x38(%rbp),%r12
jne    15ee <realpath+0x40e>
movb   $0x0,-0x1(%r15,%r14,1)
jmp    15ee <realpath+0x40e>
mov    -0x38(%rbp),%r12
jmp    15ee <realpath+0x40e>
cmpq   $0x0,-0x40(%rbp)
jne    1674 <realpath+0x494>
mov    -0x30(%rbp),%rdi
jmp    166f <realpath+0x48f>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    15eb <realpath+0x40b>
cmpq   $0x0,-0x40(%rbp)
jne    1674 <realpath+0x494>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x293d(%rip),%rax
mov    (%rax),%eax
mov    0x2944(%rip),%rcx
mov    %eax,(%rcx)
xor    %r15d,%r15d
mov    -0x38(%rbp),%r12
jmp    15ee <realpath+0x40e>
cmpq   $0x0,-0x40(%rbp)
mov    -0x38(%rbp),%r12
jne    15d9 <realpath+0x3f9>
mov    %r15,%rdi
jmp    15d4 <realpath+0x3f4>
mov    0x2918(%rip),%rax
mov    (%rax),%eax
mov    0x28ef(%rip),%rcx
cmp    (%rcx),%eax
jne    1702 <realpath+0x522>
cmpq   $0x0,-0x60(%rbp)
jne    1702 <realpath+0x522>
mov    0x28fd(%rip),%rax
mov    -0x78(%rbp),%ecx
mov    %ecx,(%rax)
jmp    15ee <realpath+0x40e>
cmpq   $0x0,-0x40(%rbp)
jne    16e4 <realpath+0x504>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x28ed(%rip),%rax
jmp    15e0 <realpath+0x400>
cmpq   $0x0,-0x40(%rbp)
jne    1686 <realpath+0x4a6>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1686 <realpath+0x4a6>
cmpq   $0x0,-0x40(%rbp)
jne    15eb <realpath+0x40b>
mov    %r15,%rdi
jmp    165e <realpath+0x47e>

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

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