#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 /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int EACCES;
int ENAMETOOLONG;
int /*<<< orphan*/ O_RDONLY;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int chdir(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ delay_signaling();
int /*<<< orphan*/ enable_signaling();
int errno;
int fchdir(int);
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ geteuid();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ seteuid(int /*<<< orphan*/);
int stat(char *, struct stat *);
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';
  if (0)
    printf("Before loop resolved = %s\n", resolved);
loop:
  q = strrchr(resolved, '/');
  if (q != NULL) {
    p = q + 1;
    if (q == resolved)
      q = "/";
    else {
      do {
        --q;
      } while (q > resolved && *q == '/');
      q[1] = '\0';
      q = resolved;
    }
    if (0)
      printf("now resolved = %s\n", resolved);
    errno = 0;
    resultcode = chdir(q);
    if (0)
      printf("result of chdir(%s) = %d\n", q, resultcode);
    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("Going to err1..\n");
      goto err1;
    }
  } else
    p = resolved;
  if (0)
    printf("Dealing with p = %s\n", p);
  if (*p != '\0') {
    errno = 0;
    resultcode = stat(p, &sb);
    if (0)
      printf("lstat(%s, &sb) = %d\n", p, resultcode);
    if (EACCES == errno) {
      uid_t userid = geteuid();
      delay_signaling();
      seteuid(0);
      errno = 0;
      resultcode = stat(p, &sb);
      seteuid(userid);
      enable_signaling();
    }
    if (resultcode == 0) {
      if (S_ISDIR(sb.st_mode)) {
        errno = 0;
        resultcode = chdir(p);
        if (0)
          printf("changed dir to %s\n", p);
        if (0)
          printf("resultcode = %d\n", resultcode);
        if (EACCES == errno) {
          uid_t userid = geteuid();
          if (0)
            printf("had an access error while chdir'ing to %s\n", p);
          delay_signaling();
          seteuid(0);
          errno = 0;
          resultcode = chdir(p);
          seteuid(userid);
          enable_signaling();
        }
        if (resultcode < 0) {
          if (0)
            printf("resultcode = %d in S_ISDIR\n", resultcode);
          goto err1;
        }
        p = "";
      }
    }
  }
  (void)strcpy(wbuf, p);
  if (0)
    printf("wbuf = %s\n", wbuf);
  errno = 0;
  resultcode = getcwd(resolved, 10) == NULL ? 0 : 1;
  if (0)
    printf("getcwd yields resolved = %s\n", resolved);
  if (EACCES == errno) {
    uid_t userid = geteuid();
    delay_signaling();
    seteuid(0);
    errno = 0;
    resultcode = getcwd(resolved, 10) == NULL ? 0 : 1;
    if (0)
      printf("getcwd gives resultcode = %d\n", resultcode);
    seteuid(userid);
    enable_signaling();
  }
  if (resultcode == 0) {
    if (0)
      printf("resultcode was 0, going to err1\n");
    goto err1;
  }
  if (resolved[0] == '/' && resolved[1] == '\0') {
    if (0)
      printf("rootd = 1\n");
    rootd = 1;
  } else {
    if (0)
      printf("rootd = 0\n");
    rootd = 0;
  }
  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, "/");
    (void)strcat(resolved, wbuf);
    if (0)
      printf("after strcat, resolved = %s, strlen(resolved) = %d\n", resolved,
             strlen(resolved));
  }
  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 (0)
    printf("fchdir(fd) completed\n");
  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    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2db6(%rip),%rax
movl   $0x0,(%rax)
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
lea    0xdd0(%rip),%rdi
call   10e0 <open@plt>
mov    %eax,-0x24(%rbp)
mov    0x2da1(%rip),%rax
mov    (%rax),%eax
mov    0x2d88(%rip),%rcx
cmp    (%rcx),%eax
jne    128f <fb_realpath+0x8f>
mov    $0x0,%al
call   1090 <geteuid@plt>
mov    %eax,-0x54(%rbp)
mov    $0x0,%al
call   10f0 <delay_signaling@plt>
xor    %edi,%edi
call   1120 <seteuid@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%esi
lea    0xd88(%rip),%rdi
call   10e0 <open@plt>
mov    %eax,-0x24(%rbp)
mov    -0x54(%rbp),%edi
call   1120 <seteuid@plt>
mov    $0x0,%al
call   1100 <enable_signaling@plt>
cmpl   $0x0,-0x24(%rbp)
jge    12b6 <fb_realpath+0xb6>
mov    -0x18(%rbp),%rdi
lea    0xd5c(%rip),%rsi
call   1040 <strcpy@plt>
movq   $0x0,-0x8(%rbp)
jmp    17a8 <fb_realpath+0x5a8>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x9,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0x9(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1080 <strrchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     13eb <fb_realpath+0x1eb>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    1317 <fb_realpath+0x117>
lea    0xcf4(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    1366 <fb_realpath+0x166>
jmp    131c <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,-0x6d(%rbp)
jbe    134b <fb_realpath+0x14b>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x6d(%rbp)
mov    -0x6d(%rbp),%al
test   $0x1,%al
jne    131c <fb_realpath+0x11c>
mov    -0x40(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2c63(%rip),%rax
movl   $0x0,(%rax)
mov    -0x40(%rbp),%rdi
call   1060 <chdir@plt>
mov    %eax,-0x50(%rbp)
mov    0x2c5a(%rip),%rax
mov    (%rax),%eax
mov    0x2c41(%rip),%rcx
cmp    (%rcx),%eax
jne    13d7 <fb_realpath+0x1d7>
mov    $0x0,%al
call   1090 <geteuid@plt>
mov    %eax,-0x58(%rbp)
mov    $0x0,%al
call   10f0 <delay_signaling@plt>
xor    %edi,%edi
call   1120 <seteuid@plt>
mov    0x2c1a(%rip),%rax
movl   $0x0,(%rax)
mov    -0x40(%rbp),%rdi
call   1060 <chdir@plt>
mov    %eax,-0x50(%rbp)
mov    -0x58(%rbp),%edi
call   1120 <seteuid@plt>
mov    $0x0,%al
call   1100 <enable_signaling@plt>
cmpl   $0x0,-0x50(%rbp)
jge    13e6 <fb_realpath+0x1e6>
jmp    172c <fb_realpath+0x52c>
jmp    13f3 <fb_realpath+0x1f3>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     152d <fb_realpath+0x32d>
mov    0x2bc6(%rip),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10c0 <stat@plt>
mov    %eax,-0x50(%rbp)
mov    0x2bb9(%rip),%rax
mov    (%rax),%eax
mov    0x2ba0(%rip),%rcx
cmp    (%rcx),%eax
jne    147c <fb_realpath+0x27c>
mov    $0x0,%al
call   1090 <geteuid@plt>
mov    %eax,-0x5c(%rbp)
mov    $0x0,%al
call   10f0 <delay_signaling@plt>
xor    %edi,%edi
call   1120 <seteuid@plt>
mov    0x2b79(%rip),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10c0 <stat@plt>
mov    %eax,-0x50(%rbp)
mov    -0x5c(%rbp),%edi
call   1120 <seteuid@plt>
mov    $0x0,%al
call   1100 <enable_signaling@plt>
cmpl   $0x0,-0x50(%rbp)
jne    1528 <fb_realpath+0x328>
mov    -0x20(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1523 <fb_realpath+0x323>
mov    0x2b31(%rip),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
call   1060 <chdir@plt>
mov    %eax,-0x50(%rbp)
mov    0x2b28(%rip),%rax
mov    (%rax),%eax
mov    0x2b0f(%rip),%rcx
cmp    (%rcx),%eax
jne    1509 <fb_realpath+0x309>
mov    $0x0,%al
call   1090 <geteuid@plt>
mov    %eax,-0x60(%rbp)
mov    $0x0,%al
call   10f0 <delay_signaling@plt>
xor    %edi,%edi
call   1120 <seteuid@plt>
mov    0x2ae8(%rip),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
call   1060 <chdir@plt>
mov    %eax,-0x50(%rbp)
mov    -0x60(%rbp),%edi
call   1120 <seteuid@plt>
mov    $0x0,%al
call   1100 <enable_signaling@plt>
cmpl   $0x0,-0x50(%rbp)
jge    1518 <fb_realpath+0x318>
jmp    172c <fb_realpath+0x52c>
lea    0xae2(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    1528 <fb_realpath+0x328>
jmp    152d <fb_realpath+0x32d>
lea    -0x4a(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <strcpy@plt>
mov    0x2a8f(%rip),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   10a0 <getcwd@plt>
mov    %rax,%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x50(%rbp)
mov    0x2a70(%rip),%rax
mov    (%rax),%eax
mov    0x2a57(%rip),%rcx
cmp    (%rcx),%eax
jne    15d7 <fb_realpath+0x3d7>
mov    $0x0,%al
call   1090 <geteuid@plt>
mov    %eax,-0x64(%rbp)
mov    $0x0,%al
call   10f0 <delay_signaling@plt>
xor    %edi,%edi
call   1120 <seteuid@plt>
mov    0x2a30(%rip),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   10a0 <getcwd@plt>
mov    %rax,%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x50(%rbp)
mov    -0x64(%rbp),%edi
call   1120 <seteuid@plt>
mov    $0x0,%al
call   1100 <enable_signaling@plt>
cmpl   $0x0,-0x50(%rbp)
jne    15e6 <fb_realpath+0x3e6>
jmp    172c <fb_realpath+0x52c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1613 <fb_realpath+0x413>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1613 <fb_realpath+0x413>
movl   $0x1,-0x28(%rbp)
jmp    161a <fb_realpath+0x41a>
movl   $0x0,-0x28(%rbp)
cmpb   $0x0,-0x4a(%rbp)
je     168d <fb_realpath+0x48d>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x74(%rbp)
lea    -0x4a(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x74(%rbp),%eax
add    %ecx,%eax
add    -0x28(%rbp),%eax
add    $0x1,%eax
cmp    $0xa,%eax
jl     1666 <fb_realpath+0x466>
mov    0x2972(%rip),%rax
mov    (%rax),%ecx
mov    0x2971(%rip),%rax
mov    %ecx,(%rax)
jmp    172c <fb_realpath+0x52c>
cmpl   $0x0,-0x28(%rbp)
jne    1680 <fb_realpath+0x480>
mov    -0x18(%rbp),%rdi
lea    0x987(%rip),%rsi
call   1110 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    -0x4a(%rbp),%rsi
call   1110 <strcat@plt>
mov    0x293c(%rip),%rax
movl   $0x0,(%rax)
mov    -0x24(%rbp),%edi
call   10d0 <fchdir@plt>
mov    %eax,-0x50(%rbp)
mov    0x2934(%rip),%rax
mov    (%rax),%eax
mov    0x291b(%rip),%rcx
cmp    (%rcx),%eax
jne    16fc <fb_realpath+0x4fc>
mov    $0x0,%al
call   1090 <geteuid@plt>
mov    %eax,-0x68(%rbp)
mov    $0x0,%al
call   10f0 <delay_signaling@plt>
xor    %edi,%edi
call   1120 <seteuid@plt>
mov    0x28f4(%rip),%rax
movl   $0x0,(%rax)
mov    -0x24(%rbp),%edi
call   10d0 <fchdir@plt>
mov    %eax,-0x50(%rbp)
mov    -0x68(%rbp),%edi
call   1120 <seteuid@plt>
mov    $0x0,%al
call   1100 <enable_signaling@plt>
cmpl   $0x0,-0x50(%rbp)
jge    1717 <fb_realpath+0x517>
mov    0x28c3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    178c <fb_realpath+0x58c>
mov    -0x24(%rbp),%edi
call   10b0 <close@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    17a8 <fb_realpath+0x5a8>
mov    0x289d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%edi
call   10d0 <fchdir@plt>
mov    0x2899(%rip),%rax
mov    (%rax),%eax
mov    0x2880(%rip),%rcx
cmp    (%rcx),%eax
jne    1787 <fb_realpath+0x587>
mov    $0x0,%al
call   1090 <geteuid@plt>
mov    %eax,-0x6c(%rbp)
mov    $0x0,%al
call   10f0 <delay_signaling@plt>
xor    %edi,%edi
call   1120 <seteuid@plt>
mov    -0x24(%rbp),%edi
call   10d0 <fchdir@plt>
mov    -0x6c(%rbp),%edi
call   1120 <seteuid@plt>
mov    $0x0,%al
call   1100 <enable_signaling@plt>
jmp    178c <fb_realpath+0x58c>
mov    -0x24(%rbp),%edi
call   10b0 <close@plt>
mov    -0x2c(%rbp),%ecx
mov    0x2832(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%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,%rbx
mov    %rdi,%r15
mov    0x2db5(%rip),%r13
movl   $0x0,0x0(%r13)
mov    0x2dbe(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0xdcc(%rip),%rdi
call   10e0 <open@plt>
mov    %eax,%r14d
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
cmp    0x0(%r13),%eax
jne    1284 <fb_realpath+0x84>
xor    %eax,%eax
call   1090 <geteuid@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   10f0 <delay_signaling@plt>
xor    %edi,%edi
call   1120 <seteuid@plt>
mov    0x0(%rbp),%esi
lea    0xd93(%rip),%rdi
call   10e0 <open@plt>
mov    %eax,%r14d
mov    %r12d,%edi
call   1120 <seteuid@plt>
xor    %eax,%eax
call   1100 <enable_signaling@plt>
test   %r14d,%r14d
js     12ea <fb_realpath+0xea>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x9,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x9(%rbx)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1080 <strrchr@plt>
mov    %rbx,%r15
test   %rax,%rax
je     137d <fb_realpath+0x17d>
mov    %rax,%rbp
cmp    %rbx,%rax
je     12fe <fb_realpath+0xfe>
lea    -0x1(%rbp),%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rcx,%rax
cmp    %rbx,%rcx
jbe    12e1 <fb_realpath+0xe1>
lea    -0x1(%rax),%rcx
cmpb   $0x2f,(%rax)
je     12d0 <fb_realpath+0xd0>
movb   $0x0,0x1(%rax)
mov    %rbx,%r15
jmp    1305 <fb_realpath+0x105>
lea    0xd0f(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
jmp    1622 <fb_realpath+0x422>
lea    0xcfd(%rip),%r15
movl   $0x0,0x0(%r13)
mov    %r15,%rdi
call   1060 <chdir@plt>
mov    %eax,%r12d
mov    0x2cc1(%rip),%rax
mov    (%rax),%eax
cmp    0x0(%r13),%eax
jne    136d <fb_realpath+0x16d>
xor    %eax,%eax
call   1090 <geteuid@plt>
mov    %eax,%r13d
xor    %eax,%eax
call   10f0 <delay_signaling@plt>
xor    %edi,%edi
call   1120 <seteuid@plt>
mov    0x2c8a(%rip),%rax
movl   $0x0,(%rax)
mov    %r15,%rdi
call   1060 <chdir@plt>
mov    %eax,%r12d
mov    %r13d,%edi
mov    0x2c6f(%rip),%r13
call   1120 <seteuid@plt>
xor    %eax,%eax
call   1100 <enable_signaling@plt>
test   %r12d,%r12d
js     1538 <fb_realpath+0x338>
add    $0x1,%rbp
mov    %rbp,%r15
cmpb   $0x0,(%r15)
je     13ef <fb_realpath+0x1ef>
movl   $0x0,0x0(%r13)
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
call   10c0 <stat@plt>
mov    %eax,%ebp
mov    0x2c3f(%rip),%rax
mov    (%rax),%eax
cmp    0x0(%r13),%eax
jne    13e7 <fb_realpath+0x1e7>
xor    %eax,%eax
call   1090 <geteuid@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   10f0 <delay_signaling@plt>
xor    %edi,%edi
call   1120 <seteuid@plt>
movl   $0x0,0x0(%r13)
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
call   10c0 <stat@plt>
mov    %eax,%ebp
mov    %r12d,%edi
call   1120 <seteuid@plt>
xor    %eax,%eax
call   1100 <enable_signaling@plt>
test   %ebp,%ebp
je     14bc <fb_realpath+0x2bc>
lea    0xe(%rsp),%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
movl   $0x0,0x0(%r13)
mov    %rbx,%rdi
mov    $0xa,%esi
call   10a0 <getcwd@plt>
mov    %rax,%rbp
mov    0x2bc5(%rip),%rax
mov    (%rax),%eax
cmp    0x0(%r13),%eax
jne    1462 <fb_realpath+0x262>
xor    %eax,%eax
call   1090 <geteuid@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   10f0 <delay_signaling@plt>
xor    %edi,%edi
call   1120 <seteuid@plt>
movl   $0x0,0x0(%r13)
mov    %rbx,%rdi
mov    $0xa,%esi
call   10a0 <getcwd@plt>
mov    %rax,%rbp
mov    %r15d,%edi
call   1120 <seteuid@plt>
xor    %eax,%eax
call   1100 <enable_signaling@plt>
test   %rbp,%rbp
je     1538 <fb_realpath+0x338>
cmpb   $0x2f,(%rbx)
jne    147a <fb_realpath+0x27a>
cmpb   $0x0,0x1(%rbx)
je     1636 <fb_realpath+0x436>
xor    %r12d,%r12d
mov    $0x1,%r15b
cmpb   $0x0,0xe(%rsp)
je     15aa <fb_realpath+0x3aa>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
lea    0xe(%rsp),%rdi
call   1050 <strlen@plt>
add    %r12d,%ebp
add    %eax,%ebp
cmp    $0x9,%ebp
jl     1589 <fb_realpath+0x389>
mov    0x2b14(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x0(%r13)
jmp    1538 <fb_realpath+0x338>
mov    0x8(%rsp),%edi
call   1070 <S_ISDIR@plt>
test   %rax,%rax
je     13ef <fb_realpath+0x1ef>
movl   $0x0,0x0(%r13)
mov    %r15,%rdi
call   1060 <chdir@plt>
mov    %eax,%ebp
mov    0x2af9(%rip),%rax
mov    (%rax),%eax
cmp    0x0(%r13),%eax
jne    1528 <fb_realpath+0x328>
xor    %eax,%eax
call   1090 <geteuid@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   10f0 <delay_signaling@plt>
xor    %edi,%edi
call   1120 <seteuid@plt>
movl   $0x0,0x0(%r13)
mov    %r15,%rdi
call   1060 <chdir@plt>
mov    %eax,%ebp
mov    %r12d,%edi
call   1120 <seteuid@plt>
xor    %eax,%eax
call   1100 <enable_signaling@plt>
test   %ebp,%ebp
js     1538 <fb_realpath+0x338>
lea    0xace(%rip),%r15
jmp    13ef <fb_realpath+0x1ef>
mov    0x0(%r13),%ebp
mov    %r14d,%edi
call   10d0 <fchdir@plt>
mov    0x2a95(%rip),%rax
mov    (%rax),%eax
cmp    0x0(%r13),%eax
jne    1616 <fb_realpath+0x416>
xor    %eax,%eax
call   1090 <geteuid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10f0 <delay_signaling@plt>
xor    %edi,%edi
call   1120 <seteuid@plt>
mov    %r14d,%edi
call   10d0 <fchdir@plt>
mov    %ebx,%edi
call   1120 <seteuid@plt>
xor    %eax,%eax
call   1100 <enable_signaling@plt>
jmp    1616 <fb_realpath+0x416>
test   %r15b,%r15b
je     159d <fb_realpath+0x39d>
lea    0xa6d(%rip),%rsi
mov    %rbx,%rdi
call   1110 <strcat@plt>
lea    0xe(%rsp),%rsi
mov    %rbx,%rdi
call   1110 <strcat@plt>
movl   $0x0,0x0(%r13)
mov    %r14d,%edi
call   10d0 <fchdir@plt>
mov    %eax,%ebp
mov    0x2a1d(%rip),%rax
mov    (%rax),%eax
cmp    0x0(%r13),%eax
jne    1604 <fb_realpath+0x404>
xor    %eax,%eax
call   1090 <geteuid@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   10f0 <delay_signaling@plt>
xor    %edi,%edi
call   1120 <seteuid@plt>
movl   $0x0,0x0(%r13)
mov    %r14d,%edi
call   10d0 <fchdir@plt>
mov    %eax,%ebp
mov    %r15d,%edi
call   1120 <seteuid@plt>
xor    %eax,%eax
call   1100 <enable_signaling@plt>
test   %ebp,%ebp
js     1612 <fb_realpath+0x412>
mov    %r14d,%edi
call   10b0 <close@plt>
jmp    1624 <fb_realpath+0x424>
mov    0x0(%r13),%ebp
mov    %r14d,%edi
call   10b0 <close@plt>
mov    %ebp,0x0(%r13)
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r12d
xor    %r15d,%r15d
cmpb   $0x0,0xe(%rsp)
jne    148b <fb_realpath+0x28b>
jmp    15aa <fb_realpath+0x3aa>

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"
@.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 i32
%20 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* @errno
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* @EACCES
%24 = load i32, i32* @errno
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %35
26: ; preds = %2
%27 = call i32 (...) @geteuid()
store i32 %27, i32* %14
%28 = call i32 (...) @delay_signaling()
%29 = call i32 @seteuid(i32 0)
%30 = load i32, i32* @O_RDONLY
%31 = call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %30)
store i32 %31, i32* %7
%32 = load i32, i32* %14
%33 = call i32 @seteuid(i32 %32)
%34 = call i32 (...) @enable_signaling()
br label %35
35: ; preds = %26, %2
%36 = load i32, i32* %7
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i8*, i8** %5
%40 = call i32 @strcpy(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
br label %263
41: ; preds = %35
%42 = load i8*, i8** %5
%43 = load i8*, i8** %4
%44 = call i32 @strncpy(i8* %42, i8* %43, i32 9)
%45 = load i8*, i8** %5
%46 = getelementptr inbounds i8, i8* %45, i64 9
store i8 0, i8* %46
br label %47
47: ; preds = %41
%48 = load i8*, i8** %5
%49 = call i8* @strrchr(i8* %48, i8 signext 47)
store i8* %49, i8** %11
%50 = load i8*, i8** %11
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %98
52: ; preds = %47
%53 = load i8*, i8** %11
%54 = getelementptr inbounds i8, i8* %53, i64 1
store i8* %54, i8** %10
%55 = load i8*, i8** %11
%56 = load i8*, i8** %5
%57 = icmp eq i8* %55, %56
br i1 %57, label %58, label %59
58: ; preds = %52
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %11
br label %78
59: ; preds = %52
br label %60
60: ; preds = %72, %59
%61 = load i8*, i8** %11
%62 = getelementptr inbounds i8, i8* %61, i32 -1
store i8* %62, i8** %11
br label %63
63: ; preds = %60
%64 = load i8*, i8** %11
%65 = load i8*, i8** %5
%66 = icmp ugt i8* %64, %65
br i1 %66, label %67, label %72
67: ; preds = %63
%68 = load i8*, i8** %11
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 47
br label %72
72: ; preds = %67, %63
%73 = phi i1 [ false, %63 ], [ %71, %67 ]
br i1 %73, label %60, label %74
74: ; preds = %72
%75 = load i8*, i8** %11
%76 = getelementptr inbounds i8, i8* %75, i64 1
store i8 0, i8* %76
%77 = load i8*, i8** %5
store i8* %77, i8** %11
br label %78
78: ; preds = %74, %58
store i32 0, i32* @errno
%79 = load i8*, i8** %11
%80 = call i32 @chdir(i8* %79)
store i32 %80, i32* %13
%81 = load i32, i32* @EACCES
%82 = load i32, i32* @errno
%83 = icmp eq i32 %81, %82
br i1 %83, label %84, label %93
84: ; preds = %78
%85 = call i32 (...) @geteuid()
store i32 %85, i32* %15
%86 = call i32 (...) @delay_signaling()
%87 = call i32 @seteuid(i32 0)
store i32 0, i32* @errno
%88 = load i8*, i8** %11
%89 = call i32 @chdir(i8* %88)
store i32 %89, i32* %13
%90 = load i32, i32* %15
%91 = call i32 @seteuid(i32 %90)
%92 = call i32 (...) @enable_signaling()
br label %93
93: ; preds = %84, %78
%94 = load i32, i32* %13
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %97
96: ; preds = %93
br label %242
97: ; preds = %93
br label %100
98: ; preds = %47
%99 = load i8*, i8** %5
store i8* %99, i8** %10
br label %100
100: ; preds = %98, %97
%101 = load i8*, i8** %10
%102 = load i8, i8* %101
%103 = sext i8 %102 to i32
%104 = icmp ne i32 %103, 0
br i1 %104, label %105, label %150
105: ; preds = %100
store i32 0, i32* @errno
%106 = load i8*, i8** %10
%107 = call i32 @stat(i8* %106, %struct.stat* %6)
store i32 %107, i32* %13
%108 = load i32, i32* @EACCES
%109 = load i32, i32* @errno
%110 = icmp eq i32 %108, %109
br i1 %110, label %111, label %120
111: ; preds = %105
%112 = call i32 (...) @geteuid()
store i32 %112, i32* %16
%113 = call i32 (...) @delay_signaling()
%114 = call i32 @seteuid(i32 0)
store i32 0, i32* @errno
%115 = load i8*, i8** %10
%116 = call i32 @stat(i8* %115, %struct.stat* %6)
store i32 %116, i32* %13
%117 = load i32, i32* %16
%118 = call i32 @seteuid(i32 %117)
%119 = call i32 (...) @enable_signaling()
br label %120
120: ; preds = %111, %105
%121 = load i32, i32* %13
%122 = icmp eq i32 %121, 0
br i1 %122, label %123, label %149
123: ; preds = %120
%124 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%125 = load i32, i32* %124
%126 = call i64 @S_ISDIR(i32 %125)
%127 = icmp ne i64 %126, 0
br i1 %127, label %128, label %148
128: ; preds = %123
store i32 0, i32* @errno
%129 = load i8*, i8** %10
%130 = call i32 @chdir(i8* %129)
store i32 %130, i32* %13
%131 = load i32, i32* @EACCES
%132 = load i32, i32* @errno
%133 = icmp eq i32 %131, %132
br i1 %133, label %134, label %143
134: ; preds = %128
%135 = call i32 (...) @geteuid()
store i32 %135, i32* %17
%136 = call i32 (...) @delay_signaling()
%137 = call i32 @seteuid(i32 0)
store i32 0, i32* @errno
%138 = load i8*, i8** %10
%139 = call i32 @chdir(i8* %138)
store i32 %139, i32* %13
%140 = load i32, i32* %17
%141 = call i32 @seteuid(i32 %140)
%142 = call i32 (...) @enable_signaling()
br label %143
143: ; preds = %134, %128
%144 = load i32, i32* %13
%145 = icmp slt i32 %144, 0
br i1 %145, label %146, label %147
146: ; preds = %143
br label %242
147: ; preds = %143
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8** %10
br label %148
148: ; preds = %147, %123
br label %149
149: ; preds = %148, %120
br label %150
150: ; preds = %149, %100
%151 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%152 = load i8*, i8** %10
%153 = call i32 @strcpy(i8* %151, i8* %152)
store i32 0, i32* @errno
%154 = load i8*, i8** %5
%155 = call i32* @getcwd(i8* %154, i32 10)
%156 = icmp eq i32* %155, null
%157 = zext i1 %156 to i64
%158 = select i1 %156, i32 0, i32 1
store i32 %158, i32* %13
%159 = load i32, i32* @EACCES
%160 = load i32, i32* @errno
%161 = icmp eq i32 %159, %160
br i1 %161, label %162, label %174
162: ; preds = %150
%163 = call i32 (...) @geteuid()
store i32 %163, i32* %18
%164 = call i32 (...) @delay_signaling()
%165 = call i32 @seteuid(i32 0)
store i32 0, i32* @errno
%166 = load i8*, i8** %5
%167 = call i32* @getcwd(i8* %166, i32 10)
%168 = icmp eq i32* %167, null
%169 = zext i1 %168 to i64
%170 = select i1 %168, i32 0, i32 1
store i32 %170, i32* %13
%171 = load i32, i32* %18
%172 = call i32 @seteuid(i32 %171)
%173 = call i32 (...) @enable_signaling()
br label %174
174: ; preds = %162, %150
%175 = load i32, i32* %13
%176 = icmp eq i32 %175, 0
br i1 %176, label %177, label %178
177: ; preds = %174
br label %242
178: ; preds = %174
%179 = load i8*, i8** %5
%180 = getelementptr inbounds i8, i8* %179, i64 0
%181 = load i8, i8* %180
%182 = sext i8 %181 to i32
%183 = icmp eq i32 %182, 47
br i1 %183, label %184, label %191
184: ; preds = %178
%185 = load i8*, i8** %5
%186 = getelementptr inbounds i8, i8* %185, i64 1
%187 = load i8, i8* %186
%188 = sext i8 %187 to i32
%189 = icmp eq i32 %188, 0
br i1 %189, label %190, label %191
190: ; preds = %184
store i32 1, i32* %8
br label %192
191: ; preds = %184, %178
store i32 0, i32* %8
br label %192
192: ; preds = %191, %190
%193 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%194 = load i8, i8* %193
%195 = icmp ne i8 %194, 0
br i1 %195, label %196, label %218
196: ; preds = %192
%197 = load i8*, i8** %5
%198 = call i32 @strlen(i8* %197)
%199 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%200 = call i32 @strlen(i8* %199)
%201 = add nsw i32 %198, %200
%202 = load i32, i32* %8
%203 = add nsw i32 %201, %202
%204 = add nsw i32 %203, 1
%205 = icmp sge i32 %204, 10
br i1 %205, label %206, label %208
206: ; preds = %196
%207 = load i32, i32* @ENAMETOOLONG
store i32 %207, i32* @errno
br label %242
208: ; preds = %196
%209 = load i32, i32* %8
%210 = icmp eq i32 %209, 0
br i1 %210, label %211, label %214
211: ; preds = %208
%212 = load i8*, i8** %5
%213 = call i32 @strcat(i8* %212, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %214
214: ; preds = %211, %208
%215 = load i8*, i8** %5
%216 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%217 = call i32 @strcat(i8* %215, i8* %216)
br label %218
218: ; preds = %214, %192
store i32 0, i32* @errno
%219 = load i32, i32* %7
%220 = call i32 @fchdir(i32 %219)
store i32 %220, i32* %13
%221 = load i32, i32* @EACCES
%222 = load i32, i32* @errno
%223 = icmp eq i32 %221, %222
br i1 %223, label %224, label %233
224: ; preds = %218
%225 = call i32 (...) @geteuid()
store i32 %225, i32* %19
%226 = call i32 (...) @delay_signaling()
%227 = call i32 @seteuid(i32 0)
store i32 0, i32* @errno
%228 = load i32, i32* %7
%229 = call i32 @fchdir(i32 %228)
store i32 %229, i32* %13
%230 = load i32, i32* %19
%231 = call i32 @seteuid(i32 %230)
%232 = call i32 (...) @enable_signaling()
br label %233
233: ; preds = %224, %218
%234 = load i32, i32* %13
%235 = icmp slt i32 %234, 0
br i1 %235, label %236, label %238
236: ; preds = %233
%237 = load i32, i32* @errno
store i32 %237, i32* %9
br label %259
238: ; preds = %233
%239 = load i32, i32* %7
%240 = call i32 @close(i32 %239)
%241 = load i8*, i8** %5
store i8* %241, i8** %3
br label %263
242: ; preds = %206, %177, %146, %96
%243 = load i32, i32* @errno
store i32 %243, i32* %9
%244 = load i32, i32* %7
%245 = call i32 @fchdir(i32 %244)
%246 = load i32, i32* @EACCES
%247 = load i32, i32* @errno
%248 = icmp eq i32 %246, %247
br i1 %248, label %249, label %258
249: ; preds = %242
%250 = call i32 (...) @geteuid()
store i32 %250, i32* %20
%251 = call i32 (...) @delay_signaling()
%252 = call i32 @seteuid(i32 0)
%253 = load i32, i32* %7
%254 = call i32 @fchdir(i32 %253)
%255 = load i32, i32* %20
%256 = call i32 @seteuid(i32 %255)
%257 = call i32 (...) @enable_signaling()
br label %258
258: ; preds = %249, %242
br label %259
259: ; preds = %258, %236
%260 = load i32, i32* %7
%261 = call i32 @close(i32 %260)
%262 = load i32, i32* %9
store i32 %262, i32* @errno
store i8* null, i8** %3
br label %263
263: ; preds = %259, %238, %38
%264 = load i8*, i8** %3
ret i8* %264
}

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"
@.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 %174
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 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 47)
%29 = icmp eq i8* %28, null
br i1 %29, label %57, label %30
30: ; preds = %25
%31 = getelementptr inbounds i8, i8* %28, i64 1
%32 = icmp eq i8* %28, %1
br i1 %32, label %41, label %33
33: ; preds = %30, %37
%34 = phi i8* [ %35, %37 ], [ %28, %30 ]
%35 = getelementptr inbounds i8, i8* %34, i64 -1
%36 = icmp ugt i8* %35, %1
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i8, i8* %35
%39 = icmp eq i8 %38, 47
br i1 %39, label %33, label %40
40: ; preds = %33, %37
store i8 0, i8* %34
br label %41
41: ; preds = %30, %40
%42 = phi i8* [ %1, %40 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %30 ]
store i32 0, i32* @errno
%43 = tail call i32 @chdir(i8* %42)
%44 = load i32, i32* @EACCES
%45 = load i32, i32* @errno
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %54
47: ; preds = %41
%48 = tail call i32 (...) @geteuid()
%49 = tail call i32 (...) @delay_signaling()
%50 = tail call i32 @seteuid(i32 0)
store i32 0, i32* @errno
%51 = tail call i32 @chdir(i8* %42)
%52 = tail call i32 @seteuid(i32 %48)
%53 = tail call i32 (...) @enable_signaling()
br label %54
54: ; preds = %47, %41
%55 = phi i32 [ %51, %47 ], [ %43, %41 ]
%56 = icmp slt i32 %55, 0
br i1 %56, label %158, label %57
57: ; preds = %25, %54
%58 = phi i8* [ %31, %54 ], [ %1, %25 ]
%59 = load i8, i8* %58
%60 = icmp eq i8 %59, 0
br i1 %60, label %96, label %61
61: ; preds = %57
store i32 0, i32* @errno
%62 = call i32 @stat(i8* %58, %struct.stat* %3)
%63 = load i32, i32* @EACCES
%64 = load i32, i32* @errno
%65 = icmp eq i32 %63, %64
br i1 %65, label %66, label %73
66: ; preds = %61
%67 = tail call i32 (...) @geteuid()
%68 = tail call i32 (...) @delay_signaling()
%69 = tail call i32 @seteuid(i32 0)
store i32 0, i32* @errno
%70 = call i32 @stat(i8* %58, %struct.stat* %3)
%71 = tail call i32 @seteuid(i32 %67)
%72 = tail call i32 (...) @enable_signaling()
br label %73
73: ; preds = %66, %61
%74 = phi i32 [ %70, %66 ], [ %62, %61 ]
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %96
76: ; preds = %73
%77 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%78 = load i32, i32* %77
%79 = tail call i64 @S_ISDIR(i32 %78)
%80 = icmp eq i64 %79, 0
br i1 %80, label %96, label %81
81: ; preds = %76
store i32 0, i32* @errno
%82 = tail call i32 @chdir(i8* %58)
%83 = load i32, i32* @EACCES
%84 = load i32, i32* @errno
%85 = icmp eq i32 %83, %84
br i1 %85, label %86, label %93
86: ; preds = %81
%87 = tail call i32 (...) @geteuid()
%88 = tail call i32 (...) @delay_signaling()
%89 = tail call i32 @seteuid(i32 0)
store i32 0, i32* @errno
%90 = tail call i32 @chdir(i8* %58)
%91 = tail call i32 @seteuid(i32 %87)
%92 = tail call i32 (...) @enable_signaling()
br label %93
93: ; preds = %86, %81
%94 = phi i32 [ %90, %86 ], [ %82, %81 ]
%95 = icmp slt i32 %94, 0
br i1 %95, label %158, label %96
96: ; preds = %93, %73, %76, %57
%97 = phi i8* [ %58, %76 ], [ %58, %73 ], [ %58, %57 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %93 ]
%98 = call i32 @strcpy(i8* %6, i8* %97)
store i32 0, i32* @errno
%99 = call i32* @getcwd(i8* %1, i32 10)
%100 = load i32, i32* @EACCES
%101 = load i32, i32* @errno
%102 = icmp eq i32 %100, %101
br i1 %102, label %103, label %110
103: ; preds = %96
%104 = call i32 (...) @geteuid()
%105 = call i32 (...) @delay_signaling()
%106 = call i32 @seteuid(i32 0)
store i32 0, i32* @errno
%107 = call i32* @getcwd(i8* %1, i32 10)
%108 = call i32 @seteuid(i32 %104)
%109 = call i32 (...) @enable_signaling()
br label %110
110: ; preds = %103, %96
%111 = phi i32* [ %107, %103 ], [ %99, %96 ]
%112 = icmp eq i32* %111, null
br i1 %112, label %158, label %113
113: ; preds = %110
%114 = load i8, i8* %1
%115 = icmp eq i8 %114, 47
br i1 %115, label %116, label %120
116: ; preds = %113
%117 = getelementptr inbounds i8, i8* %1, i64 1
%118 = load i8, i8* %117
%119 = icmp eq i8 %118, 0
br i1 %119, label %121, label %120
120: ; preds = %116, %113
br label %121
121: ; preds = %116, %120
%122 = phi i1 [ true, %120 ], [ false, %116 ]
%123 = phi i32 [ 0, %120 ], [ 1, %116 ]
%124 = load i8, i8* %6
%125 = icmp eq i8 %124, 0
br i1 %125, label %139, label %126
126: ; preds = %121
%127 = call i32 @strlen(i8* %1)
%128 = call i32 @strlen(i8* %6)
%129 = add i32 %127, %123
%130 = add i32 %129, %128
%131 = icmp sgt i32 %130, 8
br i1 %131, label %132, label %134
132: ; preds = %126
%133 = load i32, i32* @ENAMETOOLONG
store i32 %133, i32* @errno
br label %158
134: ; preds = %126
br i1 %122, label %135, label %137
135: ; preds = %134
%136 = call i32 @strcat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %137
137: ; preds = %135, %134
%138 = call i32 @strcat(i8* %1, i8* %6)
br label %139
139: ; preds = %137, %121
store i32 0, i32* @errno
%140 = call i32 @fchdir(i32 %21)
%141 = load i32, i32* @EACCES
%142 = load i32, i32* @errno
%143 = icmp eq i32 %141, %142
br i1 %143, label %144, label %151
144: ; preds = %139
%145 = call i32 (...) @geteuid()
%146 = call i32 (...) @delay_signaling()
%147 = call i32 @seteuid(i32 0)
store i32 0, i32* @errno
%148 = call i32 @fchdir(i32 %21)
%149 = call i32 @seteuid(i32 %145)
%150 = call i32 (...) @enable_signaling()
br label %151
151: ; preds = %144, %139
%152 = phi i32 [ %148, %144 ], [ %140, %139 ]
%153 = icmp slt i32 %152, 0
br i1 %153, label %154, label %156
154: ; preds = %151
%155 = load i32, i32* @errno
br label %171
156: ; preds = %151
%157 = call i32 @close(i32 %21)
br label %174
158: ; preds = %110, %93, %54, %132
%159 = load i32, i32* @errno
%160 = call i32 @fchdir(i32 %21)
%161 = load i32, i32* @EACCES
%162 = load i32, i32* @errno
%163 = icmp eq i32 %161, %162
br i1 %163, label %164, label %171
164: ; preds = %158
%165 = call i32 (...) @geteuid()
%166 = call i32 (...) @delay_signaling()
%167 = call i32 @seteuid(i32 0)
%168 = call i32 @fchdir(i32 %21)
%169 = call i32 @seteuid(i32 %165)
%170 = call i32 (...) @enable_signaling()
br label %171
171: ; preds = %158, %164, %154
%172 = phi i32 [ %159, %164 ], [ %159, %158 ], [ %155, %154 ]
%173 = call i32 @close(i32 %21)
store i32 %172, i32* @errno
br label %174
174: ; preds = %171, %156, %23
%175 = phi i8* [ null, %23 ], [ null, %171 ], [ %1, %156 ]
ret i8* %175
}