#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 */
scalar_t__ EEXIST;
int /*<<< orphan*/ assert(int);
scalar_t__ chdir(char *);
scalar_t__ errno;
int mkdir(char *, int /*<<< orphan*/);
int test_vfs_dot_dot_across_fs(void) {
  assert(chdir("/../../../../") == 0);
  assert(mkdir("dev", 0) == -1 && errno == EEXIST);
  assert(chdir("dev/../dev/../../../dev/../../dev") == 0);
  assert(mkdir("../dev", 0) == -1 && errno == EEXIST);
  assert(chdir("../") == 0);
  assert(mkdir("dev", 0) == -1 && errno == EEXIST);
  return 0;
}


x86 assembly (clang, -O0):
<test_vfs_dot_dot_across_fs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xed0(%rip),%rdi
xor    %esi,%esi
call   1030 <mkdir@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x1(%rbp)
jne    118d <test_vfs_dot_dot_across_fs+0x5d>
mov    0x2e5e(%rip),%rax
mov    (%rax),%rax
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x1(%rbp)
mov    -0x1(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xe6d(%rip),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xe6b(%rip),%rdi
xor    %esi,%esi
call   1030 <mkdir@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x2(%rbp)
jne    11ef <test_vfs_dot_dot_across_fs+0xbf>
mov    0x2dfc(%rip),%rax
mov    (%rax),%rax
mov    0x2dfa(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x2(%rbp)
mov    -0x2(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xe07(%rip),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xe0c(%rip),%rdi
xor    %esi,%esi
call   1030 <mkdir@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x3(%rbp)
jne    1251 <test_vfs_dot_dot_across_fs+0x121>
mov    0x2d9a(%rip),%rax
mov    (%rax),%rax
mov    0x2d98(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x3(%rbp)
mov    -0x3(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_vfs_dot_dot_across_fs>:
push   %r15
push   %r14
push   %rbx
lea    0xec4(%rip),%rdi
call   1040 <chdir@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
lea    0xed6(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    0x2e6b(%rip),%r15
mov    (%r15),%rcx
mov    0x2e69(%rip),%rbx
cmp    (%rbx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
lea    0xe80(%rip),%rdi
call   1040 <chdir@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
lea    0xe81(%rip),%rdi
xor    %esi,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    (%r15),%rcx
cmp    (%rbx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
lea    0xe3b(%rip),%rdi
call   1040 <chdir@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    (%r15),%rcx
cmp    (%rbx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/../../../../\00"
@.str.1 = [4 x i8] c"dev\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.2 = [34 x i8] c"dev/../dev/../../../dev/../../dev\00"
@.str.3 = [7 x i8] c"../dev\00"
@.str.4 = [4 x i8] c"../\00"
define i32 @test_vfs_dot_dot_across_fs() {
%1 = call i64 @chdir(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i64 %1, 0
%3 = zext i1 %2 to i32
%4 = call i32 @assert(i32 %3)
%5 = call i32 @mkdir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i64, i64* @errno
%9 = load i64, i64* @EEXIST
%10 = icmp eq i64 %8, %9
br label %11
11: ; preds = %7, %0
%12 = phi i1 [ false, %0 ], [ %10, %7 ]
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = call i64 @chdir(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = call i32 @mkdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %11
%22 = load i64, i64* @errno
%23 = load i64, i64* @EEXIST
%24 = icmp eq i64 %22, %23
br label %25
25: ; preds = %21, %11
%26 = phi i1 [ false, %11 ], [ %24, %21 ]
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = call i64 @chdir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = call i32 @mkdir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 0)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %39
35: ; preds = %25
%36 = load i64, i64* @errno
%37 = load i64, i64* @EEXIST
%38 = icmp eq i64 %36, %37
br label %39
39: ; preds = %35, %25
%40 = phi i1 [ false, %25 ], [ %38, %35 ]
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"/../../../../\00"
@.str.1 = [4 x i8] c"dev\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.2 = [34 x i8] c"dev/../dev/../../../dev/../../dev\00"
@.str.3 = [7 x i8] c"../dev\00"
@.str.4 = [4 x i8] c"../\00"
define i32 @test_vfs_dot_dot_across_fs() {
%1 = tail call i64 @chdir(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i64 %1, 0
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i32 @mkdir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 0)
%6 = icmp eq i32 %5, -1
%7 = load i64, i64* @errno
%8 = load i64, i64* @EEXIST
%9 = icmp eq i64 %7, %8
%10 = select i1 %6, i1 %9, i1 false
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = tail call i64 @chdir(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = tail call i32 @mkdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 0)
%18 = icmp eq i32 %17, -1
%19 = load i64, i64* @errno
%20 = load i64, i64* @EEXIST
%21 = icmp eq i64 %19, %20
%22 = select i1 %18, i1 %21, i1 false
%23 = zext i1 %22 to i32
%24 = tail call i32 @assert(i32 %23)
%25 = tail call i64 @chdir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
%27 = zext i1 %26 to i32
%28 = tail call i32 @assert(i32 %27)
%29 = tail call i32 @mkdir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 0)
%30 = icmp eq i32 %29, -1
%31 = load i64, i64* @errno
%32 = load i64, i64* @EEXIST
%33 = icmp eq i64 %31, %32
%34 = select i1 %30, i1 %33, i1 false
%35 = zext i1 %34 to i32
%36 = tail call i32 @assert(i32 %35)
ret i32 0
}