// File: mniip[P]sandbox/path.cpp
// Function: canon_path_at(int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
std::string canon_path_at(pid_t tid, int fd, std::string path)
{
	path = path.c_str();
	std::string real = "";
	if(*path.begin() != '/')
	{
		std::string proc;
		if(fd == AT_FDCWD)
			proc = ((std::ostringstream &)(std::ostringstream() << "/proc/" << tid << "/cwd")).str();
		else
			proc = ((std::ostringstream &)(std::ostringstream() << "/proc/" << tid << "/fd/" << fd)).str();
		if(!read_link(proc, real))
			return path;
	}

	std::stringstream s(path);
	std::string segment;
	while(std::getline(s, segment, '/'))
	{
		if(segment != "" && segment != ".")
		{
			if(segment != "..")
			{
				if(*real.rbegin() != '/')
					real += "/";
				real += segment;
			}
			else
				if(real.rfind('/') == std::string::npos)
					real = "";
				else
					real.erase(real.rfind('/'), std::string::npos);
		}
		std::string link;
		if(real != "/proc/self" && read_link(real, link))
		{
			if(*link.begin() == '/')
				real = link;
			else
				if(real.rfind('/') == std::string::npos)
					real = link;
				else
				{
					real.erase(real.rfind('/'), std::string::npos);
					real += "/" + link;
				}
			real = canon_path_at(tid, fd, real);
		}
	}
	if(*path.rbegin() == '/' && *real.rbegin() != '/')
		real += "/";
	return real;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x720, %rsp            # imm = 0x720
movq %rcx, -0x650(%rbp)
movq %rdi, %rax
movq -0x650(%rbp), %rdi
movq %rax, -0x660(%rbp)
movq %rax, %rcx
movq %rcx, -0x658(%rbp)
movq %rax, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
callq 0x5200
movq -0x650(%rbp), %rdi
movq %rax, %rsi
callq 0x56d0
leaq -0x39(%rbp), %rdi
movq %rdi, -0x648(%rbp)
callq 0x5900
movq -0x648(%rbp), %rdx
leaq 0x8892(%rip), %rsi      # 0x1c09f
leaq -0x38(%rbp), %rdi
callq 0x72d0
jmp 0x13818
leaq -0x39(%rbp), %rdi
callq 0x5560
movq -0x650(%rbp), %rdi
callq 0x5450
movq %rax, -0x58(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x140f0
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x13ad2
leaq -0x78(%rbp), %rdi
callq 0x5700
cmpl $-0x64, -0x10(%rbp)
jne 0x13942
leaq -0x210(%rbp), %rdi
callq 0x56c0
jmp 0x13867
leaq 0x898b(%rip), %rsi      # 0x1c1f9
leaq -0x210(%rbp), %rdi
callq 0x14170
movq %rax, -0x668(%rbp)
jmp 0x13883
movq -0x668(%rbp), %rdi
leaq -0xc(%rbp), %rsi
callq 0x14140
movq %rax, -0x670(%rbp)
jmp 0x1389c
movq -0x670(%rbp), %rdi
leaq 0x8b10(%rip), %rsi      # 0x1c3ba
callq 0x14110
movq %rax, -0x678(%rbp)
jmp 0x138b8
movq -0x678(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0x5500
jmp 0x138cd
leaq -0x78(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x55f0
leaq -0x98(%rbp), %rdi
callq 0x59b8
leaq -0x210(%rbp), %rdi
callq 0x5110
jmp 0x13a16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x5560
jmp 0x14087
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x13ac4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x5110
jmp 0x13ac4
leaq -0x3a8(%rbp), %rdi
callq 0x56c0
jmp 0x13950
leaq 0x88a2(%rip), %rsi      # 0x1c1f9
leaq -0x3a8(%rbp), %rdi
callq 0x14170
movq %rax, -0x680(%rbp)
jmp 0x1396c
movq -0x680(%rbp), %rdi
leaq -0xc(%rbp), %rsi
callq 0x14140
movq %rax, -0x688(%rbp)
jmp 0x13985
movq -0x688(%rbp), %rdi
leaq 0x86ab(%rip), %rsi      # 0x1c03e
callq 0x14110
movq %rax, -0x690(%rbp)
jmp 0x139a1
movq -0x690(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x14140
movq %rax, -0x698(%rbp)
jmp 0x139ba
movq -0x698(%rbp), %rsi
leaq -0x230(%rbp), %rdi
callq 0x5500
jmp 0x139cf
leaq -0x78(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x55f0
leaq -0x230(%rbp), %rdi
callq 0x59b8
leaq -0x3a8(%rbp), %rdi
callq 0x5110
jmp 0x13a16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x3a8(%rbp), %rdi
callq 0x5110
jmp 0x13ac4
leaq -0x3c8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x5210
jmp 0x13a28
leaq -0x3c8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x13610
movb %al, -0x699(%rbp)
jmp 0x13a40
movb -0x699(%rbp), %al
xorb $-0x1, %al
movb %al, -0x69a(%rbp)
leaq -0x3c8(%rbp), %rdi
callq 0x59b8
movb -0x69a(%rbp), %al
testb $0x1, %al
jne 0x13a66
jmp 0x13a9f
movq -0x650(%rbp), %rsi
movq -0x660(%rbp), %rdi
callq 0x52f0
movl $0x1, -0x3cc(%rbp)
jmp 0x13aa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x3c8(%rbp), %rdi
callq 0x59b8
jmp 0x13ac4
movl $0x0, -0x3cc(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x59b8
movl -0x3cc(%rbp), %eax
testl %eax, %eax
jne 0x14065
jmp 0x13ac2
jmp 0x13ad2
leaq -0x78(%rbp), %rdi
callq 0x59b8
jmp 0x1407e
movl $0x10, %edi
movl $0x8, %esi
callq 0x141a0
movl %eax, -0x6a0(%rbp)
jmp 0x13ae9
movl -0x6a0(%rbp), %edx
movq -0x650(%rbp), %rsi
leaq -0x558(%rbp), %rdi
callq 0x5800
jmp 0x13b04
leaq -0x578(%rbp), %rdi
callq 0x5700
leaq -0x558(%rbp), %rdi
leaq -0x578(%rbp), %rsi
movl $0x2f, %edx
callq 0x5930
movq %rax, -0x6a8(%rbp)
jmp 0x13b31
movq -0x6a8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x5620
movb %al, -0x6a9(%rbp)
jmp 0x13b4f
movb -0x6a9(%rbp), %al
testb $0x1, %al
jne 0x13b5e
jmp 0x13f6f
leaq 0x853a(%rip), %rsi      # 0x1c09f
leaq -0x578(%rbp), %rdi
callq 0x141c0
movb %al, -0x6aa(%rbp)
jmp 0x13b79
movb -0x6aa(%rbp), %al
testb $0x1, %al
jne 0x13b88
jmp 0x13cd1
leaq 0x8831(%rip), %rsi      # 0x1c3c0
leaq -0x578(%rbp), %rdi
callq 0x141c0
movb %al, -0x6ab(%rbp)
jmp 0x13ba3
movb -0x6ab(%rbp), %al
testb $0x1, %al
jne 0x13bb2
jmp 0x13cd1
leaq 0x8806(%rip), %rsi      # 0x1c3bf
leaq -0x578(%rbp), %rdi
callq 0x141c0
movb %al, -0x6ac(%rbp)
jmp 0x13bcd
movb -0x6ac(%rbp), %al
testb $0x1, %al
jne 0x13bdc
jmp 0x13c61
leaq -0x580(%rbp), %rdi
movq %rdi, -0x6c0(%rbp)
leaq -0x38(%rbp), %rsi
callq 0x58e0
movq -0x6c0(%rbp), %rdi
callq 0x141f0
movq %rax, -0x6b8(%rbp)
jmp 0x13c08
movq -0x6b8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x13c4d
leaq 0x85a3(%rip), %rsi      # 0x1c1c1
leaq -0x38(%rbp), %rdi
callq 0x54b0
jmp 0x13c29
jmp 0x13c4d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1407e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1404b
leaq -0x38(%rbp), %rdi
leaq -0x578(%rbp), %rsi
callq 0x5640
jmp 0x13c5f
jmp 0x13ccf
leaq -0x38(%rbp), %rdi
movl $0x2f, %esi
movq $-0x1, %rdx
callq 0x5980
cmpq $-0x1, %rax
jne 0x13c90
leaq 0x841c(%rip), %rsi      # 0x1c09f
leaq -0x38(%rbp), %rdi
callq 0x56d0
jmp 0x13c8e
jmp 0x13ccd
leaq -0x38(%rbp), %rdi
movq %rdi, -0x6d0(%rbp)
movl $0x2f, %esi
movq $-0x1, %rdx
movq %rdx, -0x6c8(%rbp)
callq 0x5980
movq -0x6d0(%rbp), %rdi
movq -0x6c8(%rbp), %rdx
movq %rax, %rsi
callq 0x5100
jmp 0x13ccb
jmp 0x13ccd
jmp 0x13ccf
jmp 0x13cd1
leaq -0x5a0(%rbp), %rdi
callq 0x5700
movb $0x0, -0x5c1(%rbp)
leaq 0x86d7(%rip), %rsi      # 0x1c3c2
leaq -0x38(%rbp), %rdi
callq 0x141c0
movb %al, -0x6d1(%rbp)
jmp 0x13cfc
movb -0x6d1(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x6d2(%rbp)
jne 0x13d11
jmp 0x13d53
leaq -0x5c0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x5210
jmp 0x13d23
movb $0x1, -0x5c1(%rbp)
leaq -0x5c0(%rbp), %rdi
leaq -0x5a0(%rbp), %rsi
callq 0x13610
movb %al, -0x6d3(%rbp)
jmp 0x13d45
movb -0x6d3(%rbp), %al
movb %al, -0x6d2(%rbp)
jmp 0x13d53
movb -0x6d2(%rbp), %al
movb %al, -0x6d4(%rbp)
testb $0x1, -0x5c1(%rbp)
jne 0x13d6a
jmp 0x13d76
leaq -0x5c0(%rbp), %rdi
callq 0x59b8
movb -0x6d4(%rbp), %al
testb $0x1, %al
jne 0x13d85
jmp 0x13f4d
leaq -0x5a0(%rbp), %rdi
callq 0x5450
movq %rax, -0x5d0(%rbp)
leaq -0x5d0(%rbp), %rdi
callq 0x140f0
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x13dfc
leaq -0x38(%rbp), %rdi
leaq -0x5a0(%rbp), %rsi
callq 0x5050
jmp 0x13dbe
jmp 0x13ec4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x13f5e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
testb $0x1, -0x5c1(%rbp)
jne 0x13deb
jmp 0x13df7
leaq -0x5c0(%rbp), %rdi
callq 0x59b8
jmp 0x13f5e
leaq -0x38(%rbp), %rdi
movl $0x2f, %esi
movq $-0x1, %rdx
callq 0x5980
cmpq $-0x1, %rax
jne 0x13e2e
leaq -0x38(%rbp), %rdi
leaq -0x5a0(%rbp), %rsi
callq 0x5050
jmp 0x13e29
jmp 0x13ec2
leaq -0x38(%rbp), %rdi
movq %rdi, -0x6e8(%rbp)
movl $0x2f, %esi
movq $-0x1, %rdx
movq %rdx, -0x6e0(%rbp)
callq 0x5980
movq -0x6e8(%rbp), %rdi
movq -0x6e0(%rbp), %rdx
movq %rax, %rsi
callq 0x5100
jmp 0x13e69
leaq 0x8351(%rip), %rsi      # 0x1c1c1
leaq -0x5f0(%rbp), %rdi
leaq -0x5a0(%rbp), %rdx
callq 0x14220
jmp 0x13e85
leaq -0x38(%rbp), %rdi
leaq -0x5f0(%rbp), %rsi
callq 0x5640
jmp 0x13e97
leaq -0x5f0(%rbp), %rdi
callq 0x59b8
jmp 0x13ec2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x5f0(%rbp), %rdi
callq 0x59b8
jmp 0x13f5e
jmp 0x13ec4
movl -0xc(%rbp), %eax
movl %eax, -0x6f0(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x6ec(%rbp)
leaq -0x630(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x5210
jmp 0x13ee8
movl -0x6ec(%rbp), %edx
movl -0x6f0(%rbp), %esi
leaq -0x610(%rbp), %rdi
leaq -0x630(%rbp), %rcx
callq 0x137a0
jmp 0x13f09
leaq -0x38(%rbp), %rdi
leaq -0x610(%rbp), %rsi
callq 0x55f0
leaq -0x610(%rbp), %rdi
callq 0x59b8
leaq -0x630(%rbp), %rdi
callq 0x59b8
jmp 0x13f4d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x630(%rbp), %rdi
callq 0x59b8
jmp 0x13f5e
leaq -0x5a0(%rbp), %rdi
callq 0x59b8
jmp 0x13b10
leaq -0x5a0(%rbp), %rdi
callq 0x59b8
jmp 0x1404b
movq -0x650(%rbp), %rsi
leaq -0x638(%rbp), %rdi
movq %rdi, -0x700(%rbp)
callq 0x58e0
movq -0x700(%rbp), %rdi
callq 0x141f0
movq %rax, -0x6f8(%rbp)
jmp 0x13f9e
movq -0x6f8(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x2f, %ecx
movb %al, -0x701(%rbp)
jne 0x13ff7
leaq -0x640(%rbp), %rdi
movq %rdi, -0x718(%rbp)
leaq -0x38(%rbp), %rsi
callq 0x58e0
movq -0x718(%rbp), %rdi
callq 0x141f0
movq %rax, -0x710(%rbp)
jmp 0x13fe1
movq -0x710(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
setne %al
movb %al, -0x701(%rbp)
movb -0x701(%rbp), %al
testb $0x1, %al
jne 0x14003
jmp 0x14017
leaq 0x81b7(%rip), %rsi      # 0x1c1c1
leaq -0x38(%rbp), %rdi
callq 0x54b0
jmp 0x14015
jmp 0x14017
movq -0x660(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x52f0
movl $0x1, -0x3cc(%rbp)
leaq -0x578(%rbp), %rdi
callq 0x59b8
leaq -0x558(%rbp), %rdi
callq 0x5380
jmp 0x14065
leaq -0x578(%rbp), %rdi
callq 0x59b8
leaq -0x558(%rbp), %rdi
callq 0x5380
jmp 0x1407e
leaq -0x38(%rbp), %rdi
callq 0x59b8
movq -0x658(%rbp), %rax
addq $0x720, %rsp            # imm = 0x720
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x59b8
movq -0x48(%rbp), %rdi
callq 0x58f0