#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fchdir(int);
int /*<<< orphan*/ mkdir(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ rmdir(char *);
int main() {
  int fd;
  mkdir("foobar", 0765);
  chdir("foobar");
  chdir("..");
  fd = open("foobar", O_RDONLY);
  fchdir(fd);
  chdir("..");
  close(fd);
  rmdir("foobar");
  fd = open(".", O_RDONLY);
  close(fd);
  rmdir("xyzzy");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x1f5,%esi
call   1030 <mkdir@plt>
lea    0xe79(%rip),%rdi
call   1050 <chdir@plt>
lea    0xe74(%rip),%rdi
call   1050 <chdir@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
lea    0xe58(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <fchdir@plt>
lea    0xe48(%rip),%rdi
call   1050 <chdir@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
lea    0xe2d(%rip),%rdi
call   1040 <rmdir@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
lea    0xe20(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
lea    0xe0b(%rip),%rdi
call   1040 <rmdir@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe92(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1f5,%esi
call   1030 <mkdir@plt>
mov    %rbx,%rdi
call   1050 <chdir@plt>
lea    0xe7d(%rip),%r14
mov    %r14,%rdi
call   1050 <chdir@plt>
mov    0x2e4f(%rip),%r15
mov    (%r15),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1070 <fchdir@plt>
mov    %r14,%rdi
call   1050 <chdir@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %rbx,%rdi
call   1040 <rmdir@plt>
mov    (%r15),%esi
lea    0xe3a(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%edi
call   1060 <close@plt>
lea    0xe29(%rip),%rdi
call   1040 <rmdir@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"foobar\00"
@.str.1 = [3 x i8] c"..\00"
@O_RDONLY = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [6 x i8] c"xyzzy\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @mkdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 501)
%4 = call i32 @chdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = call i32 @fchdir(i32 %8)
%10 = call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* %2
%12 = call i32 @close(i32 %11)
%13 = call i32 @rmdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @O_RDONLY
%15 = call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %14)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = call i32 @close(i32 %16)
%18 = call i32 @rmdir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"foobar\00"
@.str.1 = [3 x i8] c"..\00"
@O_RDONLY = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [6 x i8] c"xyzzy\00"
define i32 @main() {
%1 = tail call i32 @mkdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 501)
%2 = tail call i32 @chdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = tail call i32 @fchdir(i32 %5)
%7 = tail call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @close(i32 %5)
%9 = tail call i32 @rmdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = tail call i32 @close(i32 %11)
%13 = tail call i32 @rmdir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}