#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 m, serrno, slen;
  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 {
        resolved[0] = '.';
        resolved[1] = '\0';
      }
      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    1a87 <realpath+0x8a7>
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    1a87 <realpath+0x8a7>
mov    0x2ce1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%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    1a87 <realpath+0x8a7>
movl   $0x1,-0x50(%rbp)
jmp    133b <realpath+0x15b>
movl   $0x0,-0x50(%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    1a87 <realpath+0x8a7>
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    1438 <realpath+0x258>
mov    -0x18(%rbp),%rdi
mov    0x2c31(%rip),%rax
mov    (%rax),%esi
call   10a0 <getcwd@plt>
cmp    $0x0,%rax
jne    140b <realpath+0x22b>
cmpl   $0x0,-0x50(%rbp)
je     13e8 <realpath+0x208>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    13f7 <realpath+0x217>
mov    -0x18(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a87 <realpath+0x8a7>
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    1460 <realpath+0x280>
mov    -0x48(%rbp),%rax
mov    0x2b9c(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jb     1499 <realpath+0x2b9>
cmpl   $0x0,-0x50(%rbp)
je     1473 <realpath+0x293>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2b3e(%rip),%rax
mov    (%rax),%ecx
mov    0x2b45(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a87 <realpath+0x8a7>
jmp    149e <realpath+0x2be>
cmpq   $0x0,-0x40(%rbp)
je     1a44 <realpath+0x864>
mov    -0xa8(%rbp),%rdi
mov    $0x2f,%esi
call   1080 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     14d9 <realpath+0x2f9>
mov    -0x28(%rbp),%rax
mov    %rax,-0xb8(%rbp)
jmp    14eb <realpath+0x30b>
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     154d <realpath+0x36d>
cmpl   $0x0,-0x50(%rbp)
je     1527 <realpath+0x347>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2a8a(%rip),%rax
mov    (%rax),%ecx
mov    0x2a91(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a87 <realpath+0x8a7>
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     15bb <realpath+0x3db>
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     164b <realpath+0x46b>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    0x2a0d(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jb     1628 <realpath+0x448>
cmpl   $0x0,-0x50(%rbp)
je     1602 <realpath+0x422>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x29af(%rip),%rax
mov    (%rax),%ecx
mov    0x29b6(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a87 <realpath+0x8a7>
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    1663 <realpath+0x483>
jmp    149e <realpath+0x2be>
mov    -0x98(%rbp),%rdi
lea    0x990(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1685 <realpath+0x4a5>
jmp    149e <realpath+0x2be>
mov    -0x98(%rbp),%rdi
lea    0x96d(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    16ee <realpath+0x50e>
cmpq   $0x1,-0x48(%rbp)
jbe    16e9 <realpath+0x509>
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    149e <realpath+0x2be>
jmp    16f3 <realpath+0x513>
jmp    16f8 <realpath+0x518>
mov    -0x98(%rbp),%rsi
mov    -0x18(%rbp),%rdi
mov    0x28e6(%rip),%rax
mov    (%rax),%edx
call   1060 <strlcat@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    0x28d0(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jb     1765 <realpath+0x585>
cmpl   $0x0,-0x50(%rbp)
je     173f <realpath+0x55f>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2872(%rip),%rax
mov    (%rax),%ecx
mov    0x2879(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a87 <realpath+0x8a7>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10b0 <lstat@plt>
cmp    $0x0,%rax
je     17e6 <realpath+0x606>
mov    0x2845(%rip),%rax
mov    (%rax),%eax
mov    0x281c(%rip),%rcx
cmp    (%rcx),%eax
jne    17bf <realpath+0x5df>
cmpq   $0x0,-0x28(%rbp)
jne    17bf <realpath+0x5df>
mov    -0x54(%rbp),%ecx
mov    0x281f(%rip),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a87 <realpath+0x8a7>
cmpl   $0x0,-0x50(%rbp)
je     17d2 <realpath+0x5f2>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a87 <realpath+0x8a7>
mov    -0x20(%rbp),%edi
call   1040 <S_ISLNK@plt>
cmp    $0x0,%rax
je     1a3f <realpath+0x85f>
mov    -0x4c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x4c(%rbp)
mov    0x27d6(%rip),%rcx
cmp    (%rcx),%eax
jbe    184b <realpath+0x66b>
cmpl   $0x0,-0x50(%rbp)
je     1825 <realpath+0x645>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x27ac(%rip),%rax
mov    (%rax),%ecx
mov    0x2793(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a87 <realpath+0x8a7>
mov    -0x88(%rbp),%rsi
mov    -0x90(%rbp),%rax
mov    -0x18(%rbp),%rdi
sub    $0x1,%rax
mov    %eax,%edx
call   1050 <readlink@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x58(%rbp)
jge    189c <realpath+0x6bc>
cmpl   $0x0,-0x50(%rbp)
je     1888 <realpath+0x6a8>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a87 <realpath+0x8a7>
mov    -0x88(%rbp),%rax
movslq -0x58(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    18cc <realpath+0x6ec>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
movq   $0x1,-0x48(%rbp)
jmp    1918 <realpath+0x738>
cmpq   $0x1,-0x48(%rbp)
jbe    1913 <realpath+0x733>
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    1918 <realpath+0x738>
cmpq   $0x0,-0x28(%rbp)
je     1a1f <realpath+0x83f>
mov    -0x88(%rbp),%rax
mov    -0x58(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     19ad <realpath+0x7cd>
mov    -0x90(%rbp),%rcx
mov    -0x58(%rbp),%eax
add    $0x1,%eax
cltq
cmp    %rcx,%rax
jb     1991 <realpath+0x7b1>
cmpl   $0x0,-0x50(%rbp)
je     196b <realpath+0x78b>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2646(%rip),%rax
mov    (%rax),%ecx
mov    0x264d(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a87 <realpath+0x8a7>
mov    -0x88(%rbp),%rax
movslq -0x58(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x58(%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     1a1a <realpath+0x83a>
cmpl   $0x0,-0x50(%rbp)
je     19f4 <realpath+0x814>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x25bd(%rip),%rax
mov    (%rax),%ecx
mov    0x25c4(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1a87 <realpath+0x8a7>
jmp    1a1f <realpath+0x83f>
mov    -0x88(%rbp),%rsi
mov    -0xa8(%rbp),%rdi
mov    -0xb0(%rbp),%rax
mov    %eax,%edx
call   10f0 <strlcpy@plt>
mov    %rax,-0x40(%rbp)
jmp    149e <realpath+0x2be>
cmpq   $0x1,-0x48(%rbp)
jbe    1a78 <realpath+0x898>
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1a78 <realpath+0x898>
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     1617 <realpath+0x437>
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     161b <realpath+0x43b>
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    163b <realpath+0x45b>
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    1652 <realpath+0x472>
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    167f <realpath+0x49f>
mov    %rax,%r14
mov    %r15,%rdi
lea    -0x70(%rbp),%rsi
call   10b0 <lstat@plt>
test   %rax,%rax
mov    -0x38(%rbp),%r12
jne    1696 <realpath+0x4b6>
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     16c2 <realpath+0x4e2>
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     16dd <realpath+0x4fd>
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    163b <realpath+0x45b>
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    163b <realpath+0x45b>
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     161b <realpath+0x43b>
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     1648 <realpath+0x468>
movw   $0x2e,(%rbx)
jmp    15eb <realpath+0x40b>
mov    -0x30(%rbp),%r15
cmp    $0x2,%r14
jb     1635 <realpath+0x455>
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    1661 <realpath+0x481>
mov    -0x30(%rbp),%rdi
jmp    165c <realpath+0x47c>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    15eb <realpath+0x40b>
cmpq   $0x0,-0x40(%rbp)
jne    1661 <realpath+0x481>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2950(%rip),%rax
mov    (%rax),%eax
mov    0x2957(%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    0x292b(%rip),%rax
mov    (%rax),%eax
mov    0x2902(%rip),%rcx
cmp    (%rcx),%eax
jne    16ef <realpath+0x50f>
cmpq   $0x0,-0x60(%rbp)
jne    16ef <realpath+0x50f>
mov    0x2910(%rip),%rax
mov    -0x78(%rbp),%ecx
mov    %ecx,(%rax)
jmp    15ee <realpath+0x40e>
cmpq   $0x0,-0x40(%rbp)
jne    16d1 <realpath+0x4f1>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2900(%rip),%rax
jmp    15e0 <realpath+0x400>
cmpq   $0x0,-0x40(%rbp)
jne    1673 <realpath+0x493>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1673 <realpath+0x493>
cmpq   $0x0,-0x40(%rbp)
jne    15eb <realpath+0x40b>
mov    %r15,%rdi
jmp    164b <realpath+0x46b>

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

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