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

/* Variables and functions */
int MAXPATHLEN;
int S_IFDIR;
int S_IFLNK;
int S_IFMT;
int /*<<< orphan*/ getcwd(char *, int);
int lstat(char *, struct stat *);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int readlink(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncmp(char *, char *, int);
char *realpath(const char *pathname, char *result) {
  struct stat sbuf;
  char curpath[MAXPATHLEN], workpath[MAXPATHLEN], linkpath[MAXPATHLEN],
      namebuf[MAXPATHLEN], *where, *ptr, *last;
  int len;
  if (!result)
    return 0;
  if (!pathname) {
    *result = 0;
    return 0;
  }
  len = strlen(pathname);
  if (len >= MAXPATHLEN) {
    *result = 0;
    return 0;
  }
  memcpy(curpath, pathname, len);
  curpath[len] = 0;
  if (*pathname != '/') {
    if (!getcwd(workpath, MAXPATHLEN)) {
      result[0] = '.';
      result[1] = 0;
      return 0;
    }
  } else
    *workpath = 0;
loop:
  where = curpath;
  while (*where != '\0') {
    if (!strcmp(where, ".")) {
      where++;
      continue;
    }
    if (!strncmp(where, "./", 2)) {
      where += 2;
      continue;
    }
    if (!strncmp(where, "../", 3)) {
      where += 3;
      ptr = last = workpath;
      while (*ptr != '\0') {
        if (*ptr == '/')
          last = ptr;
        ptr++;
      }
      *last = '\0';
      continue;
    }
    ptr = strchr(where, '/');
    if (!ptr)
      ptr = where + strlen(where) - 1;
    else
      *ptr = '\0';
    strcpy(namebuf, workpath);
    for (last = namebuf; *last; last++)
      ;
    if ((last == namebuf) || (*--last != '/'))
      strcat(namebuf, "/");
    strcat(namebuf, where);
    where = ++ptr;
    if (lstat(namebuf, &sbuf) == -1) {
      strcpy(result, namebuf);
      return 0;
    }
    if ((sbuf.st_mode & S_IFMT) == S_IFLNK) {
      len = readlink(namebuf, linkpath, MAXPATHLEN);
      if (len == 0) {
        strcpy(result, namebuf);
        return 0;
      }
      *(linkpath + len) = '\0';
      if (*linkpath == '/')
        *workpath = '\0';
      if (*where) {
        strcat(linkpath, "/");
        strcat(linkpath, where);
      }
      strcpy(curpath, linkpath);
      goto loop;
    }
    if ((sbuf.st_mode & S_IFDIR) == S_IFDIR) {
      strcpy(workpath, namebuf);
      continue;
    }
    if (*where) {
      strcpy(result, namebuf);
      return 0;
    } else
      strcpy(workpath, namebuf);
  }
  strcpy(result, workpath);
  return result;
}


x86 assembly (clang, -O0):
<realpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x28(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x88(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x30(%rbp)
mov    (%rax),%ecx
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x80(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x38(%rbp)
mov    (%rax),%ecx
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x78(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x40(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    125b <realpath+0xbb>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x68(%rbp)
jmp    168a <realpath+0x4ea>
cmpq   $0x0,-0x10(%rbp)
jne    1281 <realpath+0xe1>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x68(%rbp)
jmp    168a <realpath+0x4ea>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    0x2d49(%rip),%rcx
cmp    (%rcx),%eax
jl     12ba <realpath+0x11a>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x68(%rbp)
jmp    168a <realpath+0x4ea>
mov    -0x88(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x64(%rbp),%edx
call   10b0 <memcpy@plt>
mov    -0x88(%rbp),%rax
movslq -0x64(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     132f <realpath+0x18f>
mov    -0x80(%rbp),%rdi
mov    0x2ce9(%rip),%rax
mov    (%rax),%esi
call   1080 <getcwd@plt>
cmp    $0x0,%eax
jne    132a <realpath+0x18a>
mov    -0x18(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x68(%rbp)
jmp    168a <realpath+0x4ea>
jmp    1336 <realpath+0x196>
mov    -0x80(%rbp),%rax
movb   $0x0,(%rax)
jmp    133b <realpath+0x19b>
mov    -0x88(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     166e <realpath+0x4ce>
mov    -0x50(%rbp),%rdi
lea    0xc9f(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    1380 <realpath+0x1e0>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    1346 <realpath+0x1a6>
mov    -0x50(%rbp),%rdi
lea    0xc78(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    13af <realpath+0x20f>
mov    -0x50(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x50(%rbp)
jmp    1346 <realpath+0x1a6>
mov    -0x50(%rbp),%rdi
lea    0xc48(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    142a <realpath+0x28a>
mov    -0x80(%rbp),%rax
mov    -0x50(%rbp),%rcx
add    $0x3,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rax,-0x60(%rbp)
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     141e <realpath+0x27e>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    140d <realpath+0x26d>
mov    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    13e5 <realpath+0x245>
mov    -0x60(%rbp),%rax
movb   $0x0,(%rax)
jmp    1346 <realpath+0x1a6>
mov    -0x50(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1477 <realpath+0x2d7>
mov    -0x50(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x50(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x58(%rbp)
jmp    147e <realpath+0x2de>
mov    -0x58(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x70(%rbp),%rdi
mov    -0x80(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x70(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
cmpb   $0x0,(%rax)
je     14b6 <realpath+0x316>
jmp    14a5 <realpath+0x305>
mov    -0x60(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
jmp    1493 <realpath+0x2f3>
mov    -0x70(%rbp),%rax
cmp    %rax,-0x60(%rbp)
je     14e0 <realpath+0x340>
mov    -0x60(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x60(%rbp)
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
je     14f0 <realpath+0x350>
mov    -0x70(%rbp),%rdi
lea    0xb19(%rip),%rsi
call   10c0 <strcat@plt>
mov    -0x70(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   10c0 <strcat@plt>
mov    -0x70(%rbp),%rdi
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    %rax,-0x50(%rbp)
lea    -0x20(%rbp),%rsi
call   1090 <lstat@plt>
cmp    $0xffffffff,%eax
jne    1544 <realpath+0x3a4>
mov    -0x70(%rbp),%rsi
mov    -0x18(%rbp),%rdi
call   1040 <strcpy@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x68(%rbp)
jmp    168a <realpath+0x4ea>
mov    -0x20(%rbp),%eax
mov    0x2a82(%rip),%rcx
and    (%rcx),%eax
mov    0x2a91(%rip),%rcx
cmp    (%rcx),%eax
jne    1601 <realpath+0x461>
mov    -0x78(%rbp),%rsi
mov    -0x70(%rbp),%rdi
mov    0x2a72(%rip),%rax
mov    (%rax),%edx
call   1050 <readlink@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jne    15a3 <realpath+0x403>
mov    -0x70(%rbp),%rsi
mov    -0x18(%rbp),%rdi
call   1040 <strcpy@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x68(%rbp)
jmp    168a <realpath+0x4ea>
mov    -0x78(%rbp),%rax
movslq -0x64(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    15c2 <realpath+0x422>
mov    -0x80(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x50(%rbp),%rax
cmpb   $0x0,(%rax)
je     15ec <realpath+0x44c>
mov    -0x78(%rbp),%rdi
lea    0xa2a(%rip),%rsi
call   10c0 <strcat@plt>
mov    -0x78(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   10c0 <strcat@plt>
mov    -0x78(%rbp),%rsi
mov    -0x88(%rbp),%rdi
call   1040 <strcpy@plt>
jmp    133b <realpath+0x19b>
mov    -0x20(%rbp),%eax
mov    0x29b5(%rip),%rcx
and    (%rcx),%eax
mov    0x29ac(%rip),%rcx
cmp    (%rcx),%eax
jne    162e <realpath+0x48e>
mov    -0x70(%rbp),%rsi
mov    -0x80(%rbp),%rdi
call   1040 <strcpy@plt>
jmp    1346 <realpath+0x1a6>
mov    -0x50(%rbp),%rax
cmpb   $0x0,(%rax)
je     165c <realpath+0x4bc>
mov    -0x70(%rbp),%rsi
mov    -0x18(%rbp),%rdi
call   1040 <strcpy@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x68(%rbp)
jmp    168a <realpath+0x4ea>
mov    -0x70(%rbp),%rsi
mov    -0x80(%rbp),%rdi
call   1040 <strcpy@plt>
jmp    1346 <realpath+0x1a6>
mov    -0x80(%rbp),%rsi
mov    -0x18(%rbp),%rdi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x68(%rbp)
mov    -0x28(%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    $0x38,%rsp
mov    %rdi,%r14
mov    %rsp,%rcx
mov    0x2e22(%rip),%rdx
mov    (%rdx),%eax
mov    %rsp,%rdi
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdi
mov    %rdi,%rsp
mov    (%rdx),%eax
mov    %rsp,%rdx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
test   %rsi,%rsi
je     1258 <realpath+0xb8>
test   %r14,%r14
je     1255 <realpath+0xb5>
mov    %rdi,-0x40(%rbp)
mov    %rsi,-0x30(%rbp)
mov    %rcx,-0x38(%rbp)
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%r15d
mov    0x2dbe(%rip),%rax
cmp    (%rax),%r15d
jge    125f <realpath+0xbf>
mov    %rbx,-0x58(%rbp)
mov    -0x40(%rbp),%r13
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   10b0 <memcpy@plt>
movslq %r15d,%rax
movb   $0x0,0x0(%r13,%rax,1)
cmpb   $0x2f,(%r14)
jne    126d <realpath+0xcd>
mov    -0x50(%rbp),%rbx
movb   $0x0,(%rbx)
jmp    128a <realpath+0xea>
movb   $0x0,(%rsi)
xor    %eax,%eax
jmp    1487 <realpath+0x2e7>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
xor    %eax,%eax
jmp    1483 <realpath+0x2e3>
mov    0x2d6c(%rip),%rax
mov    (%rax),%esi
mov    -0x50(%rbp),%rbx
mov    %rbx,%rdi
call   1080 <getcwd@plt>
test   %eax,%eax
je     1499 <realpath+0x2f9>
cmpb   $0x0,0x0(%r13)
mov    -0x58(%rbp),%r13
je     1471 <realpath+0x2d1>
mov    -0x40(%rbp),%r15
jmp    12b4 <realpath+0x114>
nop
add    $0x1,%r15
mov    %r15,%r14
cmpb   $0x0,(%r14)
mov    %r14,%r15
je     1471 <realpath+0x2d1>
mov    %r15,%rdi
lea    0xd42(%rip),%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     12a0 <realpath+0x100>
mov    %r15,%rdi
lea    0xd32(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1320 <realpath+0x180>
mov    %r15,%rdi
lea    0xd19(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1329 <realpath+0x189>
mov    %r15,%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     135f <realpath+0x1bf>
mov    %rax,%r14
movb   $0x0,(%rax)
jmp    1371 <realpath+0x1d1>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x2,%r15
jmp    12a4 <realpath+0x104>
mov    %rbx,%rcx
mov    %rbx,%rax
jmp    1347 <realpath+0x1a7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rcx,%rax
add    $0x1,%rcx
movzbl (%rcx),%edx
cmp    $0x2f,%dl
je     1340 <realpath+0x1a0>
test   %dl,%dl
jne    1343 <realpath+0x1a3>
add    $0x3,%r15
movb   $0x0,(%rax)
jmp    12a4 <realpath+0x104>
mov    %r15,%rdi
call   1060 <strlen@plt>
cltq
lea    (%r15,%rax,1),%r14
add    $0xffffffffffffffff,%r14
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
xor    %eax,%eax
xchg   %ax,%ax
cmpb   $0x0,(%r12,%rax,1)
lea    0x1(%rax),%rax
jne    1380 <realpath+0x1e0>
cmp    $0x1,%rax
je     1399 <realpath+0x1f9>
cmpb   $0x2f,-0x2(%r12,%rax,1)
je     13a8 <realpath+0x208>
mov    %r12,%rdi
lea    0xc61(%rip),%rsi
call   10c0 <strcat@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   10c0 <strcat@plt>
mov    %r12,%rdi
lea    -0x48(%rbp),%rsi
call   1090 <lstat@plt>
cmp    $0xffffffff,%eax
je     14a7 <realpath+0x307>
add    $0x1,%r14
mov    -0x48(%rbp),%eax
mov    0x2bfa(%rip),%rcx
mov    (%rcx),%ecx
and    %eax,%ecx
mov    0x2c07(%rip),%rdx
cmp    (%rdx),%ecx
jne    144e <realpath+0x2ae>
mov    0x2bf4(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <readlink@plt>
test   %eax,%eax
mov    -0x40(%rbp),%r15
je     14a7 <realpath+0x307>
cltq
movb   $0x0,0x0(%r13,%rax,1)
cmpb   $0x2f,0x0(%r13)
jne    1417 <realpath+0x277>
movb   $0x0,(%rbx)
cmpb   $0x0,(%r14)
je     1437 <realpath+0x297>
mov    %r13,%rdi
lea    0xbdd(%rip),%rsi
call   10c0 <strcat@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   10c0 <strcat@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
cmpb   $0x0,(%r15)
jne    12b4 <realpath+0x114>
jmp    1471 <realpath+0x2d1>
not    %eax
mov    0x2b69(%rip),%rcx
test   %eax,(%rcx)
je     1461 <realpath+0x2c1>
cmpb   $0x0,(%r14)
jne    14a7 <realpath+0x307>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
jmp    12a7 <realpath+0x107>
mov    %rbx,%rsi
mov    -0x30(%rbp),%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rax
mov    -0x38(%rbp),%rcx
mov    %rcx,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    -0x30(%rbp),%rax
movw   $0x2e,(%rax)
jmp    1266 <realpath+0xc6>
mov    -0x30(%rbp),%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
jmp    1266 <realpath+0xc6>

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@MAXPATHLEN = global i32 0
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"./\00"
@.str.2 = [4 x i8] c"../\00"
@.str.3 = [2 x i8] c"/\00"
@S_IFMT = global i32 0
@S_IFLNK = global i32 0
@S_IFDIR = global i32 0
define i8* @realpath(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = load i32, i32* @MAXPATHLEN
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = load i32, i32* @MAXPATHLEN
%10 = zext i32 %9 to i64
%11 = alloca i8, i64 %10
%12 = alloca i8, i64 %10
%13 = alloca i8, i64 %10
%14 = icmp eq i8* %1, null
br i1 %14, label %146, label %15
15: ; preds = %2
%16 = icmp eq i8* %0, null
br i1 %16, label %17, label %18
17: ; preds = %15
store i8 0, i8* %1
br label %146
18: ; preds = %15
%19 = tail call i32 @strlen(i8* %0)
%20 = load i32, i32* @MAXPATHLEN
%21 = icmp slt i32 %19, %20
br i1 %21, label %23, label %22
22: ; preds = %18
store i8 0, i8* %1
br label %146
23: ; preds = %18
%24 = call i32 @memcpy(i8* %8, i8* %0, i32 %19)
%25 = sext i32 %19 to i64
%26 = getelementptr inbounds i8, i8* %8, i64 %25
store i8 0, i8* %26
%27 = load i8, i8* %0
%28 = icmp eq i8 %27, 47
br i1 %28, label %35, label %29
29: ; preds = %23
%30 = load i32, i32* @MAXPATHLEN
%31 = call i32 @getcwd(i8* %11, i32 %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29
store i8 46, i8* %1
%34 = getelementptr inbounds i8, i8* %1, i64 1
store i8 0, i8* %34
br label %146
35: ; preds = %23
store i8 0, i8* %11
br label %36
36: ; preds = %29, %35
%37 = load i8, i8* %8
%38 = icmp eq i8 %37, 0
br i1 %38, label %144, label %39
39: ; preds = %36
%40 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
br label %41
41: ; preds = %51, %39
%42 = phi i8* [ %8, %39 ], [ %52, %51 ]
%43 = call i32 @strcmp(i8* %42, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %53
45: ; preds = %41
%46 = getelementptr inbounds i8, i8* %42, i64 1
br label %47
47: ; preds = %45, %56, %69, %135, %142
%48 = phi i8* [ %98, %135 ], [ %98, %142 ], [ %70, %69 ], [ %57, %56 ], [ %46, %45 ]
%49 = load i8, i8* %48
%50 = icmp eq i8 %49, 0
br i1 %50, label %144, label %51
51: ; preds = %47, %127
%52 = phi i8* [ %48, %47 ], [ %8, %127 ]
br label %41
53: ; preds = %41
%54 = call i32 @strncmp(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %53
%57 = getelementptr inbounds i8, i8* %42, i64 2
br label %47
58: ; preds = %53
%59 = call i32 @strncmp(i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %71
61: ; preds = %58, %66
%62 = phi i8* [ %68, %66 ], [ %11, %58 ]
%63 = phi i8* [ %67, %66 ], [ %11, %58 ]
%64 = load i8, i8* %62
switch i8 %64, label %66 [
i8 0, label %69
i8 47, label %65
]
65: ; preds = %61
br label %66
66: ; preds = %61, %65
%67 = phi i8* [ %62, %65 ], [ %63, %61 ]
%68 = getelementptr inbounds i8, i8* %62, i64 1
br label %61
69: ; preds = %61
%70 = getelementptr inbounds i8, i8* %42, i64 3
store i8 0, i8* %63
br label %47
71: ; preds = %58
%72 = call i8* @strchr(i8* %42, i8 signext 47)
%73 = icmp eq i8* %72, null
br i1 %73, label %74, label %79
74: ; preds = %71
%75 = call i32 @strlen(i8* %42)
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %42, i64 -1
%78 = getelementptr inbounds i8, i8* %77, i64 %76
br label %80
79: ; preds = %71
store i8 0, i8* %72
br label %80
80: ; preds = %79, %74
%81 = phi i8* [ %72, %79 ], [ %78, %74 ]
%82 = call i32 @strcpy(i8* %13, i8* %11)
br label %83
83: ; preds = %83, %80
%84 = phi i8* [ %13, %80 ], [ %87, %83 ]
%85 = load i8, i8* %84
%86 = icmp eq i8 %85, 0
%87 = getelementptr inbounds i8, i8* %84, i64 1
br i1 %86, label %88, label %83
88: ; preds = %83
%89 = icmp eq i8* %84, %13
br i1 %89, label %94, label %90
90: ; preds = %88
%91 = getelementptr inbounds i8, i8* %84, i64 -1
%92 = load i8, i8* %91
%93 = icmp eq i8 %92, 47
br i1 %93, label %96, label %94
94: ; preds = %90, %88
%95 = call i32 @strcat(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %96
96: ; preds = %94, %90
%97 = call i32 @strcat(i8* %13, i8* %42)
%98 = getelementptr inbounds i8, i8* %81, i64 1
%99 = call i32 @lstat(i8* %13, %struct.stat* %3)
%100 = icmp eq i32 %99, -1
br i1 %100, label %101, label %103
101: ; preds = %96
%102 = call i32 @strcpy(i8* %1, i8* %13)
br label %146
103: ; preds = %96
%104 = load i32, i32* %40
%105 = load i32, i32* @S_IFMT
%106 = and i32 %105, %104
%107 = load i32, i32* @S_IFLNK
%108 = icmp eq i32 %106, %107
br i1 %108, label %109, label %131
109: ; preds = %103
%110 = load i32, i32* @MAXPATHLEN
%111 = call i32 @readlink(i8* %13, i8* %12, i32 %110)
%112 = icmp eq i32 %111, 0
br i1 %112, label %113, label %115
113: ; preds = %109
%114 = call i32 @strcpy(i8* %1, i8* %13)
br label %146
115: ; preds = %109
%116 = sext i32 %111 to i64
%117 = getelementptr inbounds i8, i8* %12, i64 %116
store i8 0, i8* %117
%118 = load i8, i8* %12
%119 = icmp eq i8 %118, 47
br i1 %119, label %120, label %121
120: ; preds = %115
store i8 0, i8* %11
br label %121
121: ; preds = %120, %115
%122 = load i8, i8* %98
%123 = icmp eq i8 %122, 0
br i1 %123, label %127, label %124
124: ; preds = %121
%125 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%126 = call i32 @strcat(i8* %12, i8* %98)
br label %127
127: ; preds = %124, %121
%128 = call i32 @strcpy(i8* %8, i8* %12)
%129 = load i8, i8* %8
%130 = icmp eq i8 %129, 0
br i1 %130, label %144, label %51
131: ; preds = %103
%132 = load i32, i32* @S_IFDIR
%133 = and i32 %132, %104
%134 = icmp eq i32 %133, %132
br i1 %134, label %135, label %137
135: ; preds = %131
%136 = call i32 @strcpy(i8* %11, i8* %13)
br label %47
137: ; preds = %131
%138 = load i8, i8* %98
%139 = icmp eq i8 %138, 0
br i1 %139, label %142, label %140
140: ; preds = %137
%141 = call i32 @strcpy(i8* %1, i8* %13)
br label %146
142: ; preds = %137
%143 = call i32 @strcpy(i8* %11, i8* %13)
br label %47
144: ; preds = %127, %47, %36
%145 = call i32 @strcpy(i8* %1, i8* %11)
br label %146
146: ; preds = %2, %144, %140, %113, %101, %33, %22, %17
%147 = phi i8* [ null, %22 ], [ null, %101 ], [ null, %113 ], [ null, %140 ], [ %1, %144 ], [ null, %33 ], [ null, %17 ], [ null, %2 ]
ret i8* %147
}