#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 */

/* Variables and functions */
int AT_FDCWD;
int PATH_MAX;
int /*<<< orphan*/ *getcwd(char *, int);
int getpid();
char *malloc(size_t);
char *memchr(char const *, char, int);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
char *memrchr(char *, char, size_t);
size_t readlink(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int);
size_t strlen(char const *);
char *normalize_pathat(int dirfd, const char *src) {
  char *res;
  size_t res_len;
  size_t src_len;
  size_t pwd_len;
  const char *ptr;
  const char *end;
  const char *next;
  char pwd[PATH_MAX];
  if (!src)
    return NULL;
  src_len = strlen(src);
  ptr = src;
  end = &src[src_len];
  if (src[0] != '/') {
    if (dirfd == AT_FDCWD) {
      if (getcwd(pwd, PATH_MAX) == NULL)
        return NULL;
      pwd_len = strlen(pwd);
    } else {
      char lnkpth[PATH_MAX];
      snprintf(lnkpth, PATH_MAX, "/proc/%d/fd/%d", getpid(), dirfd);
      if ((pwd_len = readlink(lnkpth, pwd, PATH_MAX - 1)) == -1)
        return NULL;
      lnkpth[pwd_len] = '\0';
    }
    res = malloc(pwd_len + 1 + src_len + 1);
    memcpy(res, pwd, pwd_len);
    res_len = pwd_len;
  } else {
    res = malloc((src_len > 0 ? src_len : 1) + 1);
    res_len = 0;
  }
  for (ptr = src; ptr < end; ptr = next + 1) {
    size_t len;
    next = memchr(ptr, '/', end - ptr);
    if (next == NULL) {
      next = end;
    }
    len = next - ptr;
    switch (len) {
    case 2:
      if (ptr[0] == '.' && ptr[1] == '.') {
        const char *slash = memrchr(res, '/', res_len);
        if (slash != NULL) {
          res_len = slash - res;
        }
        continue;
      }
      break;
    case 1:
      if (ptr[0] == '.') {
        continue;
      }
      break;
    case 0:
      continue;
    }
    res[res_len++] = '/';
    memcpy(&res[res_len], ptr, len);
    res_len += len;
  }
  if (res_len == 0) {
    res[res_len++] = '/';
  }
  res[res_len] = '\0';
  return res;
}


x86 assembly (clang, -O0):
<normalize_pathat>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x90(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f0 <normalize_pathat+0x60>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1579 <normalize_pathat+0x3e9>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     138c <normalize_pathat+0x1fc>
mov    -0xc(%rbp),%eax
mov    0x2da5(%rip),%rcx
cmp    (%rcx),%eax
jne    127b <normalize_pathat+0xeb>
mov    -0x90(%rbp),%rdi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
call   1070 <getcwd@plt>
cmp    $0x0,%rax
jne    1266 <normalize_pathat+0xd6>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1579 <normalize_pathat+0x3e9>
mov    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x38(%rbp)
jmp    1352 <normalize_pathat+0x1c2>
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x98(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x78(%rbp)
mov    0x2d3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x9c(%rbp),%esi
mov    -0x98(%rbp),%rdi
mov    %eax,%ecx
mov    -0xc(%rbp),%r8d
lea    0xd26(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x98(%rbp),%rdi
mov    -0x90(%rbp),%rsi
mov    0x2cfc(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
call   1030 <readlink@plt>
mov    %rax,-0x38(%rbp)
cmp    $0xffffffffffffffff,%rax
jne    1320 <normalize_pathat+0x190>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1336 <normalize_pathat+0x1a6>
mov    -0x98(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x64(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,%rsp
mov    -0x64(%rbp),%eax
test   %eax,%eax
jne    1579 <normalize_pathat+0x3e9>
jmp    134d <normalize_pathat+0x1bd>
jmp    1352 <normalize_pathat+0x1c2>
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
add    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   10a0 <malloc@plt>
mov    -0x90(%rbp),%rsi
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rdx
call   1090 <memcpy@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    13d4 <normalize_pathat+0x244>
cmpq   $0x0,-0x30(%rbp)
jbe    13a7 <normalize_pathat+0x217>
mov    -0x30(%rbp),%rax
mov    %rax,-0xa8(%rbp)
jmp    13b8 <normalize_pathat+0x228>
mov    $0x1,%eax
mov    %rax,-0xa8(%rbp)
jmp    13b8 <normalize_pathat+0x228>
mov    -0xa8(%rbp),%rdi
add    $0x1,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x48(%rbp),%rax
jae    153c <normalize_pathat+0x3ac>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    $0x2f,%esi
call   1080 <memchr@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    141c <normalize_pathat+0x28c>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
mov    %rax,-0xb0(%rbp)
test   %rax,%rax
je     14ee <normalize_pathat+0x35e>
jmp    1444 <normalize_pathat+0x2b4>
mov    -0xb0(%rbp),%rax
sub    $0x1,%rax
je     14d4 <normalize_pathat+0x344>
jmp    145a <normalize_pathat+0x2ca>
mov    -0xb0(%rbp),%rax
sub    $0x2,%rax
jne    14f3 <normalize_pathat+0x363>
jmp    1470 <normalize_pathat+0x2e0>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    14cf <normalize_pathat+0x33f>
mov    -0x40(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    14cf <normalize_pathat+0x33f>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x2f,%esi
call   10b0 <memrchr@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     14ca <normalize_pathat+0x33a>
mov    -0x88(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    152b <normalize_pathat+0x39b>
jmp    14f3 <normalize_pathat+0x363>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    14e9 <normalize_pathat+0x359>
jmp    152b <normalize_pathat+0x39b>
jmp    14f3 <normalize_pathat+0x363>
jmp    152b <normalize_pathat+0x39b>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
movb   $0x2f,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x80(%rbp),%rdx
call   1090 <memcpy@plt>
mov    -0x80(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    13dc <normalize_pathat+0x24c>
cmpq   $0x0,-0x28(%rbp)
jne    155e <normalize_pathat+0x3ce>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
movb   $0x2f,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x64(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize_pathat>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e48(%rip),%rax
mov    (%rax),%r12d
mov    %rsp,%rbx
lea    0xf(%r12),%r15
and    $0xfffffffffffffff0,%r15
sub    %r15,%rbx
mov    %rbx,%rsp
test   %rsi,%rsi
je     139d <normalize_pathat+0x20d>
mov    %rsi,%r13
mov    %edi,-0x30(%rbp)
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %rax,%r14
cmpb   $0x2f,0x0(%r13)
jne    1208 <normalize_pathat+0x78>
lea    0x1(%r14),%rax
test   %r14,%r14
mov    $0x2,%edi
cmovne %rax,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
xor    %r15d,%r15d
test   %r14,%r14
jg     12c6 <normalize_pathat+0x136>
jmp    1380 <normalize_pathat+0x1f0>
mov    0x2dc1(%rip),%rax
mov    -0x30(%rbp),%ecx
cmp    %ecx,(%rax)
jne    1237 <normalize_pathat+0xa7>
mov    %rbx,%rdi
mov    %r12d,%esi
call   1070 <getcwd@plt>
test   %rax,%rax
je     139d <normalize_pathat+0x20d>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rax,%r15
jmp    129e <normalize_pathat+0x10e>
mov    %rsp,-0x40(%rbp)
mov    %rsp,%r12
sub    %r15,%r12
mov    %r12,%rsp
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
xor    %eax,%eax
mov    %ecx,%r15d
call   1040 <getpid@plt>
lea    0xd9f(%rip),%rdx
mov    %r12,%rdi
mov    -0x34(%rbp),%esi
mov    %eax,%ecx
mov    %r15d,%r8d
call   1060 <snprintf@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edx
add    $0xffffffff,%edx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <readlink@plt>
cmp    $0xffffffffffffffff,%rax
je     1399 <normalize_pathat+0x209>
mov    %rax,%r15
movb   $0x0,(%r12,%rax,1)
mov    -0x40(%rbp),%rsp
lea    (%r14,%r15,1),%rdi
add    $0x2,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1090 <memcpy@plt>
test   %r14,%r14
jle    1380 <normalize_pathat+0x1f0>
add    %r13,%r14
jmp    1303 <normalize_pathat+0x173>
nopl   0x0(%rax,%rax,1)
mov    -0x30(%rbp),%rax
movb   $0x2f,(%rax,%r15,1)
lea    (%rax,%r15,1),%rdi
add    $0x1,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1090 <memcpy@plt>
add    %r12,%r15
add    $0x1,%r15
add    $0x1,%rbx
mov    %rbx,%r13
cmp    %r14,%rbx
jae    1380 <normalize_pathat+0x1f0>
mov    %r14d,%edx
sub    %r13d,%edx
mov    %r13,%rdi
mov    $0x2f,%esi
call   1080 <memchr@plt>
mov    %rax,%rbx
test   %rax,%rax
cmove  %r14,%rbx
mov    %rbx,%r12
sub    %r13,%r12
je     12f3 <normalize_pathat+0x163>
cmp    $0x1,%r12
je     1370 <normalize_pathat+0x1e0>
cmp    $0x2,%r12
jne    12d0 <normalize_pathat+0x140>
cmpb   $0x2e,0x0(%r13)
jne    12d0 <normalize_pathat+0x140>
cmpb   $0x2e,0x1(%r13)
jne    12d0 <normalize_pathat+0x140>
mov    -0x30(%rbp),%r12
mov    %r12,%rdi
mov    $0x2f,%esi
mov    %r15,%rdx
call   10b0 <memrchr@plt>
mov    %rax,%rcx
sub    %r12,%rcx
test   %rax,%rax
cmovne %rcx,%r15
jmp    12f3 <normalize_pathat+0x163>
cs nopw 0x0(%rax,%rax,1)
nop
cmpb   $0x2e,0x0(%r13)
jne    12d0 <normalize_pathat+0x140>
jmp    12f3 <normalize_pathat+0x163>
test   %r15,%r15
mov    -0x30(%rbp),%rax
jne    1392 <normalize_pathat+0x202>
movb   $0x2f,(%rax)
mov    $0x1,%r15d
movb   $0x0,(%rax,%r15,1)
jmp    139f <normalize_pathat+0x20f>
mov    -0x40(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@AT_FDCWD = global i32 0
@.str = [15 x i8] c"/proc/%d/fd/%d\00"
define i8* @normalize_pathat(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i64
%19 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
%20 = load i32, i32* @PATH_MAX
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %13
%23 = alloca i8, i64 %21
store i64 %21, i64* %14
%24 = load i8*, i8** %5
%25 = icmp ne i8* %24, null
br i1 %25, label %27, label %26
26: ; preds = %2
store i8* null, i8** %3
store i32 1, i32* %15
br label %183
27: ; preds = %2
%28 = load i8*, i8** %5
%29 = call i64 @strlen(i8* %28)
store i64 %29, i64* %8
%30 = load i8*, i8** %5
store i8* %30, i8** %10
%31 = load i8*, i8** %5
%32 = load i64, i64* %8
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8* %33, i8** %11
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 0
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 47
br i1 %38, label %39, label %82
39: ; preds = %27
%40 = load i32, i32* %4
%41 = load i32, i32* @AT_FDCWD
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %50
43: ; preds = %39
%44 = load i32, i32* @PATH_MAX
%45 = call i32* @getcwd(i8* %23, i32 %44)
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %48
47: ; preds = %43
store i8* null, i8** %3
store i32 1, i32* %15
br label %183
48: ; preds = %43
%49 = call i64 @strlen(i8* %23)
store i64 %49, i64* %9
br label %71
50: ; preds = %39
%51 = load i32, i32* @PATH_MAX
%52 = zext i32 %51 to i64
%53 = call i8* @llvm.stacksave()
store i8* %53, i8** %16
%54 = alloca i8, i64 %52
store i64 %52, i64* %17
%55 = load i32, i32* @PATH_MAX
%56 = call i32 (...) @getpid()
%57 = load i32, i32* %4
%58 = call i32 @snprintf(i8* %54, i32 %55, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %56, i32 %57)
%59 = load i32, i32* @PATH_MAX
%60 = sub nsw i32 %59, 1
%61 = call i64 @readlink(i8* %54, i8* %23, i32 %60)
store i64 %61, i64* %9
%62 = icmp eq i64 %61, -1
br i1 %62, label %63, label %64
63: ; preds = %50
store i8* null, i8** %3
store i32 1, i32* %15
br label %67
64: ; preds = %50
%65 = load i64, i64* %9
%66 = getelementptr inbounds i8, i8* %54, i64 %65
store i8 0, i8* %66
store i32 0, i32* %15
br label %67
67: ; preds = %64, %63
%68 = load i8*, i8** %16
%69 = load i32, i32* %15
switch i32 %69, label %183 [
i32 0, label %70
]
70: ; preds = %67
br label %71
71: ; preds = %70, %48
%72 = load i64, i64* %9
%73 = add i64 %72, 1
%74 = load i64, i64* %8
%75 = add i64 %73, %74
%76 = add i64 %75, 1
%77 = call i8* @malloc(i64 %76)
store i8* %77, i8** %6
%78 = load i8*, i8** %6
%79 = load i64, i64* %9
%80 = call i32 @memcpy(i8* %78, i8* %23, i64 %79)
%81 = load i64, i64* %9
store i64 %81, i64* %7
br label %92
82: ; preds = %27
%83 = load i64, i64* %8
%84 = icmp ugt i64 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %82
%86 = load i64, i64* %8
br label %88
87: ; preds = %82
br label %88
88: ; preds = %87, %85
%89 = phi i64 [ %86, %85 ], [ 1, %87 ]
%90 = add i64 %89, 1
%91 = call i8* @malloc(i64 %90)
store i8* %91, i8** %6
store i64 0, i64* %7
br label %92
92: ; preds = %88, %71
%93 = load i8*, i8** %5
store i8* %93, i8** %10
br label %94
94: ; preds = %167, %92
%95 = load i8*, i8** %10
%96 = load i8*, i8** %11
%97 = icmp ult i8* %95, %96
br i1 %97, label %98, label %170
98: ; preds = %94
%99 = load i8*, i8** %10
%100 = load i8*, i8** %11
%101 = load i8*, i8** %10
%102 = ptrtoint i8* %100 to i64
%103 = ptrtoint i8* %101 to i64
%104 = sub i64 %102, %103
%105 = trunc i64 %104 to i32
%106 = call i8* @memchr(i8* %99, i8 signext 47, i32 %105)
store i8* %106, i8** %12
%107 = load i8*, i8** %12
%108 = icmp eq i8* %107, null
br i1 %108, label %109, label %111
109: ; preds = %98
%110 = load i8*, i8** %11
store i8* %110, i8** %12
br label %111
111: ; preds = %109, %98
%112 = load i8*, i8** %12
%113 = load i8*, i8** %10
%114 = ptrtoint i8* %112 to i64
%115 = ptrtoint i8* %113 to i64
%116 = sub i64 %114, %115
store i64 %116, i64* %18
%117 = load i64, i64* %18
switch i64 %117, label %153 [
i64 2, label %118
i64 1, label %144
i64 0, label %152
]
118: ; preds = %111
%119 = load i8*, i8** %10
%120 = getelementptr inbounds i8, i8* %119, i64 0
%121 = load i8, i8* %120
%122 = sext i8 %121 to i32
%123 = icmp eq i32 %122, 46
br i1 %123, label %124, label %143
124: ; preds = %118
%125 = load i8*, i8** %10
%126 = getelementptr inbounds i8, i8* %125, i64 1
%127 = load i8, i8* %126
%128 = sext i8 %127 to i32
%129 = icmp eq i32 %128, 46
br i1 %129, label %130, label %143
130: ; preds = %124
%131 = load i8*, i8** %6
%132 = load i64, i64* %7
%133 = call i8* @memrchr(i8* %131, i8 signext 47, i64 %132)
store i8* %133, i8** %19
%134 = load i8*, i8** %19
%135 = icmp ne i8* %134, null
br i1 %135, label %136, label %142
136: ; preds = %130
%137 = load i8*, i8** %19
%138 = load i8*, i8** %6
%139 = ptrtoint i8* %137 to i64
%140 = ptrtoint i8* %138 to i64
%141 = sub i64 %139, %140
store i64 %141, i64* %7
br label %142
142: ; preds = %136, %130
br label %167
143: ; preds = %124, %118
br label %153
144: ; preds = %111
%145 = load i8*, i8** %10
%146 = getelementptr inbounds i8, i8* %145, i64 0
%147 = load i8, i8* %146
%148 = sext i8 %147 to i32
%149 = icmp eq i32 %148, 46
br i1 %149, label %150, label %151
150: ; preds = %144
br label %167
151: ; preds = %144
br label %153
152: ; preds = %111
br label %167
153: ; preds = %111, %151, %143
%154 = load i8*, i8** %6
%155 = load i64, i64* %7
%156 = add i64 %155, 1
store i64 %156, i64* %7
%157 = getelementptr inbounds i8, i8* %154, i64 %155
store i8 47, i8* %157
%158 = load i8*, i8** %6
%159 = load i64, i64* %7
%160 = getelementptr inbounds i8, i8* %158, i64 %159
%161 = load i8*, i8** %10
%162 = load i64, i64* %18
%163 = call i32 @memcpy(i8* %160, i8* %161, i64 %162)
%164 = load i64, i64* %18
%165 = load i64, i64* %7
%166 = add i64 %165, %164
store i64 %166, i64* %7
br label %167
167: ; preds = %153, %152, %150, %142
%168 = load i8*, i8** %12
%169 = getelementptr inbounds i8, i8* %168, i64 1
store i8* %169, i8** %10
br label %94
170: ; preds = %94
%171 = load i64, i64* %7
%172 = icmp eq i64 %171, 0
br i1 %172, label %173, label %178
173: ; preds = %170
%174 = load i8*, i8** %6
%175 = load i64, i64* %7
%176 = add i64 %175, 1
store i64 %176, i64* %7
%177 = getelementptr inbounds i8, i8* %174, i64 %175
store i8 47, i8* %177
br label %178
178: ; preds = %173, %170
%179 = load i8*, i8** %6
%180 = load i64, i64* %7
%181 = getelementptr inbounds i8, i8* %179, i64 %180
store i8 0, i8* %181
%182 = load i8*, i8** %6
store i8* %182, i8** %3
store i32 1, i32* %15
br label %183
183: ; preds = %178, %67, %47, %26
%184 = load i8*, i8** %13
%185 = load i8*, i8** %3
ret i8* %185
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@AT_FDCWD = global i32 0
@.str = [15 x i8] c"/proc/%d/fd/%d\00"
define i8* @normalize_pathat(i32 %0, i8* %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp eq i8* %1, null
br i1 %6, label %95, label %7
7: ; preds = %2
%8 = tail call i64 @strlen(i8* %1)
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = load i8, i8* %1
%11 = icmp eq i8 %10, 47
br i1 %11, label %38, label %12
12: ; preds = %7
%13 = load i32, i32* @AT_FDCWD
%14 = icmp eq i32 %13, %0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = call i32* @getcwd(i8* %5, i32 %3)
%17 = icmp eq i32* %16, null
br i1 %17, label %95, label %18
18: ; preds = %15
%19 = call i64 @strlen(i8* %5)
br label %32
20: ; preds = %12
%21 = tail call i8* @llvm.stacksave()
%22 = alloca i8, i64 %4
%23 = load i32, i32* @PATH_MAX
%24 = tail call i32 (...) @getpid()
%25 = call i32 @snprintf(i8* %22, i32 %23, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %0)
%26 = load i32, i32* @PATH_MAX
%27 = add nsw i32 %26, -1
%28 = call i64 @readlink(i8* %22, i8* %5, i32 %27)
%29 = icmp eq i64 %28, -1
br i1 %29, label %94, label %30
30: ; preds = %20
%31 = getelementptr inbounds i8, i8* %22, i64 %28
store i8 0, i8* %31
br label %32
32: ; preds = %30, %18
%33 = phi i64 [ %19, %18 ], [ %28, %30 ]
%34 = add i64 %8, 2
%35 = add i64 %34, %33
%36 = call i8* @malloc(i64 %35)
%37 = call i32 @memcpy(i8* %36, i8* %5, i64 %33)
br label %43
38: ; preds = %7
%39 = icmp eq i64 %8, 0
%40 = add i64 %8, 1
%41 = select i1 %39, i64 2, i64 %40
%42 = tail call i8* @malloc(i64 %41)
br label %43
43: ; preds = %38, %32
%44 = phi i64 [ %33, %32 ], [ 0, %38 ]
%45 = phi i8* [ %36, %32 ], [ %42, %38 ]
%46 = icmp sgt i64 %8, 0
br i1 %46, label %47, label %87
47: ; preds = %43
%48 = ptrtoint i8* %9 to i64
%49 = ptrtoint i8* %45 to i64
br label %50
50: ; preds = %47, %83
%51 = phi i64 [ %44, %47 ], [ %84, %83 ]
%52 = phi i8* [ %1, %47 ], [ %85, %83 ]
%53 = ptrtoint i8* %52 to i64
%54 = sub i64 %48, %53
%55 = trunc i64 %54 to i32
%56 = call i8* @memchr(i8* %52, i8 signext 47, i32 %55)
%57 = icmp eq i8* %56, null
%58 = select i1 %57, i8* %9, i8* %56
%59 = ptrtoint i8* %58 to i64
%60 = sub i64 %59, %53
switch i64 %60, label %77 [
i64 2, label %61
i64 1, label %74
i64 0, label %83
]
61: ; preds = %50
%62 = load i8, i8* %52
%63 = icmp eq i8 %62, 46
br i1 %63, label %64, label %77
64: ; preds = %61
%65 = getelementptr inbounds i8, i8* %52, i64 1
%66 = load i8, i8* %65
%67 = icmp eq i8 %66, 46
br i1 %67, label %68, label %77
68: ; preds = %64
%69 = call i8* @memrchr(i8* %45, i8 signext 47, i64 %51)
%70 = icmp eq i8* %69, null
%71 = ptrtoint i8* %69 to i64
%72 = sub i64 %71, %49
%73 = select i1 %70, i64 %51, i64 %72
br label %83
74: ; preds = %50
%75 = load i8, i8* %52
%76 = icmp eq i8 %75, 46
br i1 %76, label %83, label %77
77: ; preds = %74, %61, %64, %50
%78 = add i64 %51, 1
%79 = getelementptr inbounds i8, i8* %45, i64 %51
store i8 47, i8* %79
%80 = getelementptr inbounds i8, i8* %45, i64 %78
%81 = call i32 @memcpy(i8* %80, i8* %52, i64 %60)
%82 = add i64 %60, %78
br label %83
83: ; preds = %50, %74, %77, %68
%84 = phi i64 [ %82, %77 ], [ %73, %68 ], [ %51, %74 ], [ %51, %50 ]
%85 = getelementptr inbounds i8, i8* %58, i64 1
%86 = icmp ult i8* %85, %9
br i1 %86, label %50, label %87
87: ; preds = %83, %43
%88 = phi i64 [ %44, %43 ], [ %84, %83 ]
%89 = icmp eq i64 %88, 0
br i1 %89, label %90, label %91
90: ; preds = %87
store i8 47, i8* %45
br label %91
91: ; preds = %90, %87
%92 = phi i64 [ 1, %90 ], [ %88, %87 ]
%93 = getelementptr inbounds i8, i8* %45, i64 %92
store i8 0, i8* %93
br label %95
94: ; preds = %20
br label %95
95: ; preds = %94, %15, %2, %91
%96 = phi i8* [ %45, %91 ], [ null, %2 ], [ null, %15 ], [ null, %94 ]
ret i8* %96
}