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

/* Variables and functions */
int EACCES;
int ELOOP;
int ENAMETOOLONG;
int /*<<< orphan*/ O_RDONLY;
scalar_t__ S_ISBLK(int);
scalar_t__ S_ISCHR(int);
scalar_t__ S_ISDIR(int);
scalar_t__ S_ISFIFO(int);
scalar_t__ S_ISLNK(int);
scalar_t__ S_ISREG(int);
scalar_t__ S_ISSOCK(int);
char *calloc(size_t, int);
int chdir(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ delay_signaling();
int /*<<< orphan*/ enable_signaling();
int errno;
int fchdir(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ geteuid();
int lstat(char *, struct stat *);
int myreadlink(char *, char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ seteuid(int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char *, char);
char *fb_realpath(const char *path, char *resolved) {
  struct stat sb;
  int fd, rootd, serrno;
  char *p, *q, wbuf[10];
  int resultcode;
  errno = 0;
  fd = open(".", O_RDONLY);
  if (EACCES == errno) {
    uid_t userid = geteuid();
    delay_signaling();
    seteuid(0);
    fd = open(".", O_RDONLY);
    seteuid(userid);
    enable_signaling();
  }
  if (fd < 0) {
    (void)strcpy(resolved, ".");
    return (NULL);
  }
  (void)strncpy(resolved, path, 10 - 1);
  resolved[10 - 1] = '\0';
loop:
  q = strrchr(resolved, '/');
  if (0)
    printf("q inside LOOP = %s\n", q);
  if (q != NULL) {
    p = q + 1;
    if (q == resolved)
      q = "/";
    else {
      do {
        --q;
      } while (q > resolved && *q == '/');
      q[1] = '\0';
      q = resolved;
    }
    errno = 0;
    if (0)
      printf("trying to chdir(%s)\n", q);
    resultcode = chdir(q);
    if (EACCES == errno) {
      uid_t userid = geteuid();
      delay_signaling();
      seteuid(0);
      errno = 0;
      resultcode = chdir(q);
      seteuid(userid);
      enable_signaling();
    }
    if (resultcode < 0) {
      if (0)
        printf("error occurred while trying to chdir(%s)\n", q);
      goto err1;
    }
  } else
    p = resolved;
  if (*p != '\0') {
    errno = 0;
    if (0)
      printf("trying to lstat %s\n", p);
    resultcode = lstat(p, &sb);
    if (0)
      printf("Resultcode = %d\n", resultcode);
    if (0)
      printf("errno=%d\n", errno);
    if (EACCES == errno) {
      uid_t userid = geteuid();
      delay_signaling();
      seteuid(0);
      errno = 0;
      resultcode = lstat(p, &sb);
      seteuid(userid);
      enable_signaling();
    }
    if (resultcode == 0) {
      int symlinks = 0;
      int n;
      if (0)
        printf("sb.st_mode=%d\n", sb.st_mode);
      if (S_ISREG(sb.st_mode))
        if (0)
          printf("isreg\n");
      if (S_ISDIR(sb.st_mode))
        if (0)
          printf("isdir\n");
      if (S_ISCHR(sb.st_mode))
        if (0)
          printf("ischr\n");
      if (S_ISBLK(sb.st_mode))
        if (0)
          printf("isblk\n");
      if (S_ISFIFO(sb.st_mode))
        if (0)
          printf("isfifo\n");
      if (S_ISLNK(sb.st_mode))
        if (0)
          printf("islnk\n");
      if (S_ISSOCK(sb.st_mode))
        if (0)
          printf("issock\n");
      if (S_ISLNK(sb.st_mode)) {
        if (++symlinks > 5) {
          errno = ELOOP;
          goto err1;
        }
        errno = 0;
        {
          size_t len = strlen(p);
          char *tmp = calloc(len + 1, sizeof(char));
          if (tmp == 0) {
            serrno = errno;
            goto err1;
          }
          strcpy(tmp, p);
          p = tmp;
        }
        n = myreadlink(p, resolved, 10);
        if (EACCES == errno) {
          uid_t userid = geteuid();
          delay_signaling();
          seteuid(0);
          errno = 0;
          n = myreadlink(p, resolved, 10);
          seteuid(userid);
          enable_signaling();
        }
        if (n < 0) {
          free(p);
          goto err1;
        }
        free(p);
        resolved[n] = '\0';
        goto loop;
      }
      if (S_ISDIR(sb.st_mode)) {
        if (0)
          printf("S_ISDIR..\n");
        errno = 0;
        resultcode = chdir(p);
        if (0)
          printf("chdir(%s) = resultcode = %d\n", p, resultcode);
        if (EACCES == errno) {
          uid_t userid = geteuid();
          delay_signaling();
          seteuid(0);
          errno = 0;
          resultcode = chdir(p);
          seteuid(userid);
          enable_signaling();
        }
        if (resultcode < 0)
          goto err1;
        p = "";
      }
    }
  }
  (void)strcpy(wbuf, p);
  if (0)
    printf("wbuf now contains %s\n", wbuf);
  errno = 0;
  resultcode = getcwd(resolved, 10) == NULL ? 0 : 1;
  if (0)
    printf("getcwd: resultcode = %d\n", resultcode);
  if (EACCES == errno) {
    uid_t userid = geteuid();
    delay_signaling();
    seteuid(0);
    errno = 0;
    resultcode = getcwd(resolved, 10) == NULL ? 0 : 1;
    seteuid(userid);
    enable_signaling();
  }
  if (resultcode == 0) {
    if (0)
      printf("going to err1.. resultcode = %d\n", resultcode);
    goto err1;
  }
  if (resolved[0] == '/' && resolved[1] == '\0')
    rootd = 1;
  else
    rootd = 0;
  if (0)
    printf("resolved(%d) = %s\n", strlen(resolved), resolved);
  if (0)
    printf("wbuf(%d) = %s \n", strlen(wbuf), wbuf);
  if (0)
    printf("rootd=%d\n", rootd);
  if (0)
    printf("strlen(resolved) + strlen(wbuf) + rootd + 1 = %d\n",
           strlen(resolved) + strlen(wbuf) + rootd + 1);
  if (*wbuf) {
    if (strlen(resolved) + strlen(wbuf) + rootd + 1 > 10) {
      errno = ENAMETOOLONG;
      if (0)
        printf("resolved path too long!\n");
      goto err1;
    }
    if (rootd == 0)
      (void)strcat(resolved, "/");
    if (0)
      printf("resolved=%s  len=%d \n", resolved, strlen(resolved));
    if (0)
      printf("wbuf=%s  len=%d \n", wbuf, strlen(wbuf));
    (void)strcat(resolved, wbuf);
    if (0)
      printf("after strcat, resolved = %s, strlen(resolved) = %d\n", resolved,
             strlen(resolved));
    if ((strlen(resolved) + 1) > 10)
      if (0)
        printf("strlen(resolve) > MAXPATHLEN -- buffer overflow\n");
  }
  errno = 0;
  resultcode = fchdir(fd);
  if (EACCES == errno) {
    uid_t userid = geteuid();
    delay_signaling();
    seteuid(0);
    errno = 0;
    resultcode = fchdir(fd);
    seteuid(userid);
    enable_signaling();
  }
  if (resultcode < 0) {
    serrno = errno;
    goto err2;
  }
  (void)close(fd);
  return (resolved);
err1:
  serrno = errno;
  (void)fchdir(fd);
  if (EACCES == errno) {
    uid_t userid = geteuid();
    delay_signaling();
    seteuid(0);
    (void)fchdir(fd);
    seteuid(userid);
    enable_signaling();
  }
err2:
  (void)close(fd);
  errno = serrno;
  return (NULL);
}


x86 assembly (clang, -O0):
<fb_realpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2d1e(%rip),%rax
movl   $0x0,(%rax)
mov    0x2d31(%rip),%rax
mov    (%rax),%esi
lea    0xd40(%rip),%rdi
call   1170 <open@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d11(%rip),%rax
mov    (%rax),%eax
mov    0x2cf0(%rip),%rcx
cmp    (%rcx),%eax
jne    131f <fb_realpath+0x8f>
mov    $0x0,%al
call   10e0 <geteuid@plt>
mov    %eax,-0x54(%rbp)
mov    $0x0,%al
call   1180 <delay_signaling@plt>
xor    %edi,%edi
call   11b0 <seteuid@plt>
mov    0x2ce9(%rip),%rax
mov    (%rax),%esi
lea    0xcf8(%rip),%rdi
call   1170 <open@plt>
mov    %eax,-0x24(%rbp)
mov    -0x54(%rbp),%edi
call   11b0 <seteuid@plt>
mov    $0x0,%al
call   1190 <enable_signaling@plt>
cmpl   $0x0,-0x24(%rbp)
jge    1346 <fb_realpath+0xb6>
mov    -0x18(%rbp),%rdi
lea    0xccc(%rip),%rsi
call   1050 <strcpy@plt>
movq   $0x0,-0x8(%rbp)
jmp    1a66 <fb_realpath+0x7d6>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x9,%edx
call   1040 <strncpy@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0x9(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   10d0 <strrchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1484 <fb_realpath+0x1f4>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    13a7 <fb_realpath+0x117>
lea    0xc64(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    13ff <fb_realpath+0x16f>
jmp    13ac <fb_realpath+0x11c>
mov    -0x40(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x8d(%rbp)
jbe    13e1 <fb_realpath+0x151>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x8d(%rbp)
mov    -0x8d(%rbp),%al
test   $0x1,%al
jne    13ac <fb_realpath+0x11c>
mov    -0x40(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2bc2(%rip),%rax
movl   $0x0,(%rax)
mov    -0x40(%rbp),%rdi
call   1090 <chdir@plt>
mov    %eax,-0x50(%rbp)
mov    0x2bc1(%rip),%rax
mov    (%rax),%eax
mov    0x2ba0(%rip),%rcx
cmp    (%rcx),%eax
jne    1470 <fb_realpath+0x1e0>
mov    $0x0,%al
call   10e0 <geteuid@plt>
mov    %eax,-0x58(%rbp)
mov    $0x0,%al
call   1180 <delay_signaling@plt>
xor    %edi,%edi
call   11b0 <seteuid@plt>
mov    0x2b79(%rip),%rax
movl   $0x0,(%rax)
mov    -0x40(%rbp),%rdi
call   1090 <chdir@plt>
mov    %eax,-0x50(%rbp)
mov    -0x58(%rbp),%edi
call   11b0 <seteuid@plt>
mov    $0x0,%al
call   1190 <enable_signaling@plt>
cmpl   $0x0,-0x50(%rbp)
jge    147f <fb_realpath+0x1ef>
jmp    19e4 <fb_realpath+0x754>
jmp    148c <fb_realpath+0x1fc>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     17b4 <fb_realpath+0x524>
mov    0x2b25(%rip),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1110 <lstat@plt>
mov    %eax,-0x50(%rbp)
mov    0x2b20(%rip),%rax
mov    (%rax),%eax
mov    0x2aff(%rip),%rcx
cmp    (%rcx),%eax
jne    1515 <fb_realpath+0x285>
mov    $0x0,%al
call   10e0 <geteuid@plt>
mov    %eax,-0x5c(%rbp)
mov    $0x0,%al
call   1180 <delay_signaling@plt>
xor    %edi,%edi
call   11b0 <seteuid@plt>
mov    0x2ad8(%rip),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1110 <lstat@plt>
mov    %eax,-0x50(%rbp)
mov    -0x5c(%rbp),%edi
call   11b0 <seteuid@plt>
mov    $0x0,%al
call   1190 <enable_signaling@plt>
cmpl   $0x0,-0x50(%rbp)
jne    17af <fb_realpath+0x51f>
movl   $0x0,-0x60(%rbp)
mov    -0x20(%rbp),%edi
call   1130 <S_ISREG@plt>
cmp    $0x0,%rax
je     153d <fb_realpath+0x2ad>
jmp    153d <fb_realpath+0x2ad>
mov    -0x20(%rbp),%edi
call   10b0 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1554 <fb_realpath+0x2c4>
jmp    1554 <fb_realpath+0x2c4>
mov    -0x20(%rbp),%edi
call   1140 <S_ISCHR@plt>
cmp    $0x0,%rax
je     156b <fb_realpath+0x2db>
jmp    156b <fb_realpath+0x2db>
mov    -0x20(%rbp),%edi
call   1160 <S_ISBLK@plt>
cmp    $0x0,%rax
je     1582 <fb_realpath+0x2f2>
jmp    1582 <fb_realpath+0x2f2>
mov    -0x20(%rbp),%edi
call   1080 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     1599 <fb_realpath+0x309>
jmp    1599 <fb_realpath+0x309>
mov    -0x20(%rbp),%edi
call   1060 <S_ISLNK@plt>
cmp    $0x0,%rax
je     15b0 <fb_realpath+0x320>
jmp    15b0 <fb_realpath+0x320>
mov    -0x20(%rbp),%edi
call   10a0 <S_ISSOCK@plt>
cmp    $0x0,%rax
je     15c7 <fb_realpath+0x337>
jmp    15c7 <fb_realpath+0x337>
mov    -0x20(%rbp),%edi
call   1060 <S_ISLNK@plt>
cmp    $0x0,%rax
je     170d <fb_realpath+0x47d>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
cmp    $0x5,%eax
jle    1602 <fb_realpath+0x372>
mov    0x29e6(%rip),%rax
mov    (%rax),%ecx
mov    0x29cd(%rip),%rax
mov    %ecx,(%rax)
jmp    19e4 <fb_realpath+0x754>
mov    0x29bf(%rip),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
call   1070 <strlen@plt>
cltq
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1120 <calloc@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    1650 <fb_realpath+0x3c0>
mov    0x2982(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    19e4 <fb_realpath+0x754>
mov    -0x78(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x78(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   10c0 <myreadlink@plt>
mov    %eax,-0x64(%rbp)
mov    0x295f(%rip),%rax
mov    (%rax),%eax
mov    0x293e(%rip),%rcx
cmp    (%rcx),%eax
jne    16db <fb_realpath+0x44b>
mov    $0x0,%al
call   10e0 <geteuid@plt>
mov    %eax,-0x7c(%rbp)
mov    $0x0,%al
call   1180 <delay_signaling@plt>
xor    %edi,%edi
call   11b0 <seteuid@plt>
mov    0x2917(%rip),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   10c0 <myreadlink@plt>
mov    %eax,-0x64(%rbp)
mov    -0x7c(%rbp),%edi
call   11b0 <seteuid@plt>
mov    $0x0,%al
call   1190 <enable_signaling@plt>
cmpl   $0x0,-0x64(%rbp)
jge    16f3 <fb_realpath+0x463>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    19e4 <fb_realpath+0x754>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
movslq -0x64(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1360 <fb_realpath+0xd0>
mov    -0x20(%rbp),%edi
call   10b0 <S_ISDIR@plt>
cmp    $0x0,%rax
je     17aa <fb_realpath+0x51a>
mov    0x28a2(%rip),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
call   1090 <chdir@plt>
mov    %eax,-0x50(%rbp)
mov    0x28a1(%rip),%rax
mov    (%rax),%eax
mov    0x2880(%rip),%rcx
cmp    (%rcx),%eax
jne    1790 <fb_realpath+0x500>
mov    $0x0,%al
call   10e0 <geteuid@plt>
mov    %eax,-0x80(%rbp)
mov    $0x0,%al
call   1180 <delay_signaling@plt>
xor    %edi,%edi
call   11b0 <seteuid@plt>
mov    0x2859(%rip),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
call   1090 <chdir@plt>
mov    %eax,-0x50(%rbp)
mov    -0x80(%rbp),%edi
call   11b0 <seteuid@plt>
mov    $0x0,%al
call   1190 <enable_signaling@plt>
cmpl   $0x0,-0x50(%rbp)
jge    179f <fb_realpath+0x50f>
jmp    19e4 <fb_realpath+0x754>
lea    0x85b(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    17af <fb_realpath+0x51f>
jmp    17b4 <fb_realpath+0x524>
lea    -0x4a(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1050 <strcpy@plt>
mov    0x2800(%rip),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   10f0 <getcwd@plt>
mov    %rax,%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x50(%rbp)
mov    0x27e9(%rip),%rax
mov    (%rax),%eax
mov    0x27c8(%rip),%rcx
cmp    (%rcx),%eax
jne    1864 <fb_realpath+0x5d4>
mov    $0x0,%al
call   10e0 <geteuid@plt>
mov    %eax,-0x84(%rbp)
mov    $0x0,%al
call   1180 <delay_signaling@plt>
xor    %edi,%edi
call   11b0 <seteuid@plt>
mov    0x279e(%rip),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   10f0 <getcwd@plt>
mov    %rax,%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x50(%rbp)
mov    -0x84(%rbp),%edi
call   11b0 <seteuid@plt>
mov    $0x0,%al
call   1190 <enable_signaling@plt>
cmpl   $0x0,-0x50(%rbp)
jne    1873 <fb_realpath+0x5e3>
jmp    19e4 <fb_realpath+0x754>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    18a0 <fb_realpath+0x610>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    18a0 <fb_realpath+0x610>
movl   $0x1,-0x28(%rbp)
jmp    18a7 <fb_realpath+0x617>
movl   $0x0,-0x28(%rbp)
cmpb   $0x0,-0x4a(%rbp)
je     193f <fb_realpath+0x6af>
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x94(%rbp)
lea    -0x4a(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x94(%rbp),%eax
add    %ecx,%eax
add    -0x28(%rbp),%eax
add    $0x1,%eax
cmp    $0xa,%eax
jle    18f9 <fb_realpath+0x669>
mov    0x26d7(%rip),%rax
mov    (%rax),%ecx
mov    0x26d6(%rip),%rax
mov    %ecx,(%rax)
jmp    19e4 <fb_realpath+0x754>
cmpl   $0x0,-0x28(%rbp)
jne    1913 <fb_realpath+0x683>
mov    -0x18(%rbp),%rdi
lea    0x6f4(%rip),%rsi
call   11a0 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    -0x4a(%rbp),%rsi
call   11a0 <strcat@plt>
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
add    $0x1,%eax
cmp    $0xa,%eax
jle    193a <fb_realpath+0x6aa>
jmp    193a <fb_realpath+0x6aa>
jmp    193f <fb_realpath+0x6af>
mov    0x2682(%rip),%rax
movl   $0x0,(%rax)
mov    -0x24(%rbp),%edi
call   1150 <fchdir@plt>
mov    %eax,-0x50(%rbp)
mov    0x2682(%rip),%rax
mov    (%rax),%eax
mov    0x2661(%rip),%rcx
cmp    (%rcx),%eax
jne    19b4 <fb_realpath+0x724>
mov    $0x0,%al
call   10e0 <geteuid@plt>
mov    %eax,-0x88(%rbp)
mov    $0x0,%al
call   1180 <delay_signaling@plt>
xor    %edi,%edi
call   11b0 <seteuid@plt>
mov    0x2637(%rip),%rax
movl   $0x0,(%rax)
mov    -0x24(%rbp),%edi
call   1150 <fchdir@plt>
mov    %eax,-0x50(%rbp)
mov    -0x88(%rbp),%edi
call   11b0 <seteuid@plt>
mov    $0x0,%al
call   1190 <enable_signaling@plt>
cmpl   $0x0,-0x50(%rbp)
jge    19cf <fb_realpath+0x73f>
mov    0x2603(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    1a4a <fb_realpath+0x7ba>
mov    -0x24(%rbp),%edi
call   1100 <close@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1a66 <fb_realpath+0x7d6>
mov    0x25dd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%edi
call   1150 <fchdir@plt>
mov    0x25e1(%rip),%rax
mov    (%rax),%eax
mov    0x25c0(%rip),%rcx
cmp    (%rcx),%eax
jne    1a45 <fb_realpath+0x7b5>
mov    $0x0,%al
call   10e0 <geteuid@plt>
mov    %eax,-0x8c(%rbp)
mov    $0x0,%al
call   1180 <delay_signaling@plt>
xor    %edi,%edi
call   11b0 <seteuid@plt>
mov    -0x24(%rbp),%edi
call   1150 <fchdir@plt>
mov    -0x8c(%rbp),%edi
call   11b0 <seteuid@plt>
mov    $0x0,%al
call   1190 <enable_signaling@plt>
jmp    1a4a <fb_realpath+0x7ba>
mov    -0x24(%rbp),%edi
call   1100 <close@plt>
mov    -0x2c(%rbp),%ecx
mov    0x256c(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fb_realpath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
mov    0x2d25(%rip),%r15
movl   $0x0,(%r15)
mov    0x2d2f(%rip),%rbx
mov    (%rbx),%esi
lea    0xd3e(%rip),%rdi
call   1170 <open@plt>
mov    %eax,%ebp
mov    0x2d10(%rip),%r13
mov    0x0(%r13),%eax
cmp    (%r15),%eax
jne    130e <fb_realpath+0x7e>
xor    %eax,%eax
call   10e0 <geteuid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1180 <delay_signaling@plt>
xor    %edi,%edi
call   11b0 <seteuid@plt>
mov    (%rbx),%esi
lea    0xd07(%rip),%rdi
call   1170 <open@plt>
mov    %ebp,%edi
mov    %eax,%ebp
call   11b0 <seteuid@plt>
xor    %eax,%eax
call   1190 <enable_signaling@plt>
test   %ebp,%ebp
js     1563 <fb_realpath+0x2d3>
mov    %ebp,0x4(%rsp)
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x9,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x9(%r12)
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    $0x2f,%esi
call   10d0 <strrchr@plt>
mov    %r12,%rbp
test   %rax,%rax
je     1401 <fb_realpath+0x171>
mov    %rax,%rbx
mov    %r13,%r15
lea    0xc9c(%rip),%rbp
cmp    %r12,%rax
je     1388 <fb_realpath+0xf8>
lea    -0x1(%rbx),%rcx
nop
mov    %rcx,%rax
cmp    %r12,%rcx
jbe    1381 <fb_realpath+0xf1>
lea    -0x1(%rax),%rcx
cmpb   $0x2f,(%rax)
je     1370 <fb_realpath+0xe0>
movb   $0x0,0x1(%rax)
mov    %r12,%rbp
mov    0x2c41(%rip),%r14
movl   $0x0,(%r14)
mov    %rbp,%rdi
call   1090 <chdir@plt>
mov    %eax,%r13d
mov    (%r15),%eax
cmp    (%r14),%eax
jne    13e4 <fb_realpath+0x154>
xor    %eax,%eax
call   10e0 <geteuid@plt>
mov    %eax,0x8(%rsp)
xor    %eax,%eax
call   1180 <delay_signaling@plt>
xor    %edi,%edi
call   11b0 <seteuid@plt>
movl   $0x0,(%r14)
mov    %rbp,%rdi
call   1090 <chdir@plt>
mov    %eax,%r13d
mov    0x8(%rsp),%edi
call   11b0 <seteuid@plt>
xor    %eax,%eax
call   1190 <enable_signaling@plt>
mov    %rsp,%r14
test   %r13d,%r13d
mov    %r15,%r13
mov    0x2bdc(%rip),%r15
js     169e <fb_realpath+0x40e>
add    $0x1,%rbx
mov    %rbx,%rbp
cmpb   $0x0,0x0(%rbp)
je     15e4 <fb_realpath+0x354>
movl   $0x0,(%r15)
mov    %rbp,%rdi
mov    %r14,%rsi
call   1110 <lstat@plt>
mov    %eax,%ebx
mov    0x0(%r13),%eax
cmp    (%r15),%eax
jne    1466 <fb_realpath+0x1d6>
xor    %eax,%eax
call   10e0 <geteuid@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1180 <delay_signaling@plt>
xor    %edi,%edi
call   11b0 <seteuid@plt>
movl   $0x0,(%r15)
mov    %rbp,%rdi
mov    %rsp,%rsi
call   1110 <lstat@plt>
mov    %eax,%ebx
mov    %r14d,%edi
mov    %rsp,%r14
call   11b0 <seteuid@plt>
xor    %eax,%eax
call   1190 <enable_signaling@plt>
test   %ebx,%ebx
jne    15e4 <fb_realpath+0x354>
mov    (%rsp),%ebx
mov    %ebx,%edi
call   1130 <S_ISREG@plt>
mov    %ebx,%edi
call   10b0 <S_ISDIR@plt>
mov    %ebx,%edi
call   1140 <S_ISCHR@plt>
mov    %ebx,%edi
call   1160 <S_ISBLK@plt>
mov    %ebx,%edi
call   1080 <S_ISFIFO@plt>
mov    %ebx,%edi
call   1060 <S_ISLNK@plt>
mov    %ebx,%edi
call   10a0 <S_ISSOCK@plt>
mov    %ebx,%edi
call   1060 <S_ISLNK@plt>
test   %rax,%rax
je     1577 <fb_realpath+0x2e7>
movl   $0x0,(%r15)
mov    %rbp,%rdi
call   1070 <strlen@plt>
movslq %eax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1120 <calloc@plt>
test   %rax,%rax
je     169e <fb_realpath+0x40e>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0xa,%edx
call   10c0 <myreadlink@plt>
mov    %eax,%ebp
mov    0x0(%r13),%eax
cmp    (%r15),%eax
jne    1547 <fb_realpath+0x2b7>
xor    %eax,%eax
call   10e0 <geteuid@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1180 <delay_signaling@plt>
xor    %edi,%edi
call   11b0 <seteuid@plt>
movl   $0x0,(%r15)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0xa,%edx
call   10c0 <myreadlink@plt>
mov    %eax,%ebp
mov    %r14d,%edi
mov    %rsp,%r14
call   11b0 <seteuid@plt>
xor    %eax,%eax
call   1190 <enable_signaling@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
js     169e <fb_realpath+0x40e>
mov    %ebp,%eax
movb   $0x0,(%r12,%rax,1)
jmp    1340 <fb_realpath+0xb0>
lea    0xa96(%rip),%rsi
mov    %r12,%rdi
call   1050 <strcpy@plt>
jmp    16ed <fb_realpath+0x45d>
mov    %ebx,%edi
call   10b0 <S_ISDIR@plt>
test   %rax,%rax
je     15e4 <fb_realpath+0x354>
movl   $0x0,(%r15)
mov    %rbp,%rdi
call   1090 <chdir@plt>
mov    %eax,%ebx
mov    0x0(%r13),%eax
cmp    (%r15),%eax
jne    15d5 <fb_realpath+0x345>
xor    %eax,%eax
call   10e0 <geteuid@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1180 <delay_signaling@plt>
xor    %edi,%edi
call   11b0 <seteuid@plt>
movl   $0x0,(%r15)
mov    %rbp,%rdi
call   1090 <chdir@plt>
mov    %eax,%ebx
mov    %r14d,%edi
call   11b0 <seteuid@plt>
xor    %eax,%eax
call   1190 <enable_signaling@plt>
test   %ebx,%ebx
js     169e <fb_realpath+0x40e>
lea    0xa1d(%rip),%rbp
lea    0xe(%rsp),%rdi
mov    %rbp,%rsi
call   1050 <strcpy@plt>
movl   $0x0,(%r15)
mov    %r12,%rdi
mov    $0xa,%esi
call   10f0 <getcwd@plt>
mov    %rax,%rbx
mov    0x0(%r13),%eax
cmp    (%r15),%eax
jne    164d <fb_realpath+0x3bd>
xor    %eax,%eax
call   10e0 <geteuid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1180 <delay_signaling@plt>
xor    %edi,%edi
call   11b0 <seteuid@plt>
movl   $0x0,(%r15)
mov    %r12,%rdi
mov    $0xa,%esi
call   10f0 <getcwd@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   11b0 <seteuid@plt>
xor    %eax,%eax
call   1190 <enable_signaling@plt>
test   %rbx,%rbx
je     169e <fb_realpath+0x40e>
cmpb   $0x2f,(%r12)
jne    1665 <fb_realpath+0x3d5>
cmpb   $0x0,0x1(%r12)
je     179d <fb_realpath+0x50d>
xor    %ebp,%ebp
mov    $0x1,%r14b
cmpb   $0x0,0xe(%rsp)
je     172b <fb_realpath+0x49b>
mov    %r12,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebx
lea    0xe(%rsp),%rdi
call   1070 <strlen@plt>
add    %ebp,%ebx
add    %eax,%ebx
cmp    $0xa,%ebx
jl     1702 <fb_realpath+0x472>
mov    0x292f(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r15)
mov    (%r15),%ebp
mov    0x4(%rsp),%ebx
mov    %ebx,%edi
call   1150 <fchdir@plt>
mov    0x0(%r13),%eax
cmp    (%r15),%eax
jne    16e3 <fb_realpath+0x453>
xor    %eax,%eax
call   10e0 <geteuid@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1180 <delay_signaling@plt>
xor    %edi,%edi
call   11b0 <seteuid@plt>
mov    %ebx,%edi
call   1150 <fchdir@plt>
mov    %r14d,%edi
call   11b0 <seteuid@plt>
xor    %eax,%eax
call   1190 <enable_signaling@plt>
mov    %ebx,%edi
call   1100 <close@plt>
mov    %ebp,(%r15)
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %r14b,%r14b
je     1716 <fb_realpath+0x486>
lea    0x8f4(%rip),%rsi
mov    %r12,%rdi
call   11a0 <strcat@plt>
lea    0xe(%rsp),%rsi
mov    %r12,%rdi
call   11a0 <strcat@plt>
mov    %r12,%rdi
call   1070 <strlen@plt>
movl   $0x0,(%r15)
mov    0x4(%rsp),%ebp
mov    %ebp,%edi
call   1150 <fchdir@plt>
mov    %eax,%ebx
mov    0x0(%r13),%eax
cmp    (%r15),%eax
jne    177f <fb_realpath+0x4ef>
xor    %eax,%eax
call   10e0 <geteuid@plt>
mov    %ebp,%ebx
mov    %eax,%ebp
xor    %eax,%eax
call   1180 <delay_signaling@plt>
xor    %edi,%edi
call   11b0 <seteuid@plt>
movl   $0x0,(%r15)
mov    %ebx,%edi
call   1150 <fchdir@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   11b0 <seteuid@plt>
xor    %eax,%eax
call   1190 <enable_signaling@plt>
test   %ebx,%ebx
js     1791 <fb_realpath+0x501>
mov    0x4(%rsp),%edi
call   1100 <close@plt>
jmp    16f0 <fb_realpath+0x460>
mov    (%r15),%ebp
mov    0x4(%rsp),%ebx
jmp    16e3 <fb_realpath+0x453>
mov    $0x1,%ebp
xor    %r14d,%r14d
cmpb   $0x0,0xe(%rsp)
jne    1675 <fb_realpath+0x3e5>
jmp    172b <fb_realpath+0x49b>

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

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