#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 size_t ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int PATH_MAX;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int openat(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
size_t readlink(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(void) {
  int dir_fd;
  int dir_fd1;
  int dir_fd2;
  ssize_t status;
  char path1[PATH_MAX];
  char path2[PATH_MAX];
  char fd_link[64];
  dir_fd = open("/", O_RDONLY);
  if (dir_fd < 0) {
    perror("open(2)");
    exit(EXIT_FAILURE);
  }
  dir_fd1 = openat(dir_fd, ".", O_RDONLY);
  if (dir_fd1 < 0) {
    perror("openat(2)");
    exit(EXIT_FAILURE);
  }
  dir_fd2 = openat(dir_fd, "..", O_RDONLY);
  if (dir_fd2 < 0) {
    perror("openat(2)");
    exit(EXIT_FAILURE);
  }
  sprintf(fd_link, "/proc/self/fd/%d", dir_fd1);
  status = readlink(fd_link, path1, PATH_MAX - 1);
  if (status < 0) {
    perror("readlink(2)");
    exit(EXIT_FAILURE);
  }
  path1[status] = '\0';
  sprintf(fd_link, "/proc/self/fd/%d", dir_fd2);
  status = readlink(fd_link, path2, PATH_MAX - 1);
  if (status < 0) {
    perror("readlink(2)");
    exit(EXIT_FAILURE);
  }
  path2[status] = '\0';
  if (strcmp(path1, "/") != 0) {
    fprintf(stderr, "/. != /");
    exit(EXIT_FAILURE);
  }
  if (strcmp(path2, "/") != 0) {
    fprintf(stderr, "/.. != /");
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x80(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x28(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
lea    0xe55(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1218 <main+0x98>
lea    0xdfb(%rip),%rdi
call   1080 <perror@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    0x2dbe(%rip),%rax
mov    (%rax),%edx
lea    0xde8(%rip),%rsi
call   1040 <openat@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1257 <main+0xd7>
lea    0xdc4(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    0x2d7f(%rip),%rax
mov    (%rax),%edx
lea    0xda8(%rip),%rsi
call   1040 <openat@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1296 <main+0x116>
lea    0xd85(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x70(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xd71(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x80(%rbp),%rsi
lea    -0x70(%rbp),%rdi
mov    0x2d38(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
call   1030 <readlink@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jae    12eb <main+0x16b>
lea    0xd4e(%rip),%rdi
call   1080 <perror@plt>
mov    0x2ce4(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x80(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xd10(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x78(%rbp),%rsi
lea    -0x70(%rbp),%rdi
mov    0x2cd7(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
call   1030 <readlink@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jae    134c <main+0x1cc>
lea    0xced(%rip),%rdi
call   1080 <perror@plt>
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    0xcde(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1395 <main+0x215>
mov    0x2c57(%rip),%rax
mov    (%rax),%edi
lea    0xcb0(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2c3a(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x78(%rbp),%rdi
lea    0xca1(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     13d2 <main+0x252>
mov    0x2c1a(%rip),%rax
mov    (%rax),%edi
lea    0xc7b(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2bfd(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2be7(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
mov    0x2e25(%rip),%r15
mov    (%r15),%esi
lea    0xe70(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
jns    11d7 <main+0x57>
lea    0xe2b(%rip),%rdi
jmp    120d <main+0x8d>
mov    %eax,%ebx
mov    (%r15),%edx
lea    0xe30(%rip),%rsi
mov    %eax,%edi
call   1040 <openat@plt>
test   %eax,%eax
js     1206 <main+0x86>
mov    %eax,%r12d
mov    (%r15),%edx
lea    0xe17(%rip),%rsi
mov    %ebx,%edi
call   1040 <openat@plt>
test   %eax,%eax
jns    1220 <main+0xa0>
lea    0xdfb(%rip),%rdi
call   1080 <perror@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    %eax,%r15d
lea    0xdeb(%rip),%rsi
lea    -0x70(%rbp),%rbx
mov    %rbx,%rdi
mov    %r12d,%edx
call   1090 <sprintf@plt>
mov    0x2db0(%rip),%r12
mov    (%r12),%edx
add    $0xffffffff,%edx
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <readlink@plt>
movb   $0x0,0x0(%r13,%rax,1)
mov    %rbx,%rdi
lea    0xdb3(%rip),%rsi
mov    %r15d,%edx
call   1090 <sprintf@plt>
mov    (%r12),%edx
add    $0xffffffff,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <readlink@plt>
movb   $0x0,(%r14,%rax,1)
lea    0xdad(%rip),%rsi
mov    %r13,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    12b7 <main+0x137>
lea    0xd99(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    12d1 <main+0x151>
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
lea    0xd5f(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1212 <main+0x92>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
lea    0xd4d(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1212 <main+0x92>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [2 x i8] c"/\00"
@O_RDONLY = global i32 0
@.str.1 = [8 x i8] c"open(2)\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [10 x i8] c"openat(2)\00"
@.str.4 = [3 x i8] c"..\00"
@.str.5 = [17 x i8] c"/proc/self/fd/%d\00"
@.str.6 = [12 x i8] c"readlink(2)\00"
@stderr = global i32 0
@.str.7 = [8 x i8] c"/. != /\00"
@.str.8 = [9 x i8] c"/.. != /\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca [64 x i8]
store i32 0, i32* %1
%10 = load i32, i32* @PATH_MAX
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i8, i64 %11
store i64 %11, i64* %7
%14 = load i32, i32* @PATH_MAX
%15 = zext i32 %14 to i64
%16 = alloca i8, i64 %15
store i64 %15, i64* %8
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %17)
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %0
%22 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %0
%26 = load i32, i32* %2
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @openat(i32 %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %27)
store i32 %28, i32* %3
%29 = load i32, i32* %3
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %25
%36 = load i32, i32* %2
%37 = load i32, i32* @O_RDONLY
%38 = call i32 @openat(i32 %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %37)
store i32 %38, i32* %4
%39 = load i32, i32* %4
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %35
%42 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %35
%46 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%47 = load i32, i32* %3
%48 = call i32 @sprintf(i8* %46, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %47)
%49 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%50 = load i32, i32* @PATH_MAX
%51 = sub nsw i32 %50, 1
%52 = call i64 @readlink(i8* %49, i8* %13, i32 %51)
store i64 %52, i64* %5
%53 = load i64, i64* %5
%54 = icmp ult i64 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %45
%56 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %45
%60 = load i64, i64* %5
%61 = getelementptr inbounds i8, i8* %13, i64 %60
store i8 0, i8* %61
%62 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%63 = load i32, i32* %4
%64 = call i32 @sprintf(i8* %62, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %63)
%65 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%66 = load i32, i32* @PATH_MAX
%67 = sub nsw i32 %66, 1
%68 = call i64 @readlink(i8* %65, i8* %16, i32 %67)
store i64 %68, i64* %5
%69 = load i64, i64* %5
%70 = icmp ult i64 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %59
%72 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %59
%76 = load i64, i64* %5
%77 = getelementptr inbounds i8, i8* %16, i64 %76
store i8 0, i8* %77
%78 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%79 = icmp ne i64 %78, 0
br i1 %79, label %80, label %85
80: ; preds = %75
%81 = load i32, i32* @stderr
%82 = call i32 @fprintf(i32 %81, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%83 = load i32, i32* @EXIT_FAILURE
%84 = call i32 @exit(i32 %83)
unreachable
85: ; preds = %75
%86 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%87 = icmp ne i64 %86, 0
br i1 %87, label %88, label %93
88: ; preds = %85
%89 = load i32, i32* @stderr
%90 = call i32 @fprintf(i32 %89, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%91 = load i32, i32* @EXIT_FAILURE
%92 = call i32 @exit(i32 %91)
unreachable
93: ; preds = %85
%94 = load i32, i32* @EXIT_SUCCESS
%95 = call i32 @exit(i32 %94)
unreachable
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [2 x i8] c"/\00"
@O_RDONLY = global i32 0
@.str.1 = [8 x i8] c"open(2)\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [10 x i8] c"openat(2)\00"
@.str.4 = [3 x i8] c"..\00"
@.str.5 = [17 x i8] c"/proc/self/fd/%d\00"
@stderr = global i32 0
@.str.7 = [8 x i8] c"/. != /\00"
@.str.8 = [9 x i8] c"/.. != /\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [64 x i8]
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = alloca i8, i64 %3
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%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 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 @openat(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %14
%23 = load i32, i32* @O_RDONLY
%24 = tail call i32 @openat(i32 %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %22
%31 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%32 = load i32, i32* @PATH_MAX
%33 = add nsw i32 %32, -1
%34 = call i64 @readlink(i8* %6, i8* %4, i32 %33)
%35 = getelementptr inbounds i8, i8* %4, i64 %34
store i8 0, i8* %35
%36 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %24)
%37 = load i32, i32* @PATH_MAX
%38 = add nsw i32 %37, -1
%39 = call i64 @readlink(i8* %6, i8* %5, i32 %38)
%40 = getelementptr inbounds i8, i8* %5, i64 %39
store i8 0, i8* %40
%41 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %48, label %43
43: ; preds = %30
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %30
%49 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %56, label %51
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %48
%57 = load i32, i32* @EXIT_SUCCESS
%58 = call i32 @exit(i32 %57)
unreachable
}