#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int chdir(char *);
int close(int);
int fchdir(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pexit(char *);
int stat(char *, struct stat *);
void fchdirOperation() {
  int fd;
  fd = open(".", O_RDONLY);
  if (fd == -1) {
    pexit("open");
  }
  if (chdir("..") == -1) {
    pexit("chdir");
  }
  struct stat sBuf;
  if (stat(".", &sBuf) == -1) {
    pexit("stat");
  }
  if (fchdir(fd) == -1) {
    pexit("chdir");
  }
  if (close(fd) == -1) {
    pexit("close");
  }
}


x86 assembly (clang, -O0):
<fchdirOperation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
lea    0xe8e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    1196 <fchdirOperation+0x36>
lea    0xe6f(%rip),%rdi
call   1080 <pexit@plt>
lea    0xe68(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0xffffffff,%eax
jne    11b7 <fchdirOperation+0x57>
lea    0xe56(%rip),%rdi
call   1080 <pexit@plt>
lea    0xe48(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    11dc <fchdirOperation+0x7c>
lea    0xe37(%rip),%rdi
call   1080 <pexit@plt>
mov    -0x4(%rbp),%edi
call   1060 <fchdir@plt>
cmp    $0xffffffff,%eax
jne    11f9 <fchdirOperation+0x99>
lea    0xe14(%rip),%rdi
call   1080 <pexit@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    1216 <fchdirOperation+0xb6>
lea    0xe02(%rip),%rdi
call   1080 <pexit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fchdirOperation>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    118d <fchdirOperation+0x2d>
lea    0xe78(%rip),%rdi
call   1080 <pexit@plt>
lea    0xe71(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0xffffffff,%eax
jne    11aa <fchdirOperation+0x4a>
lea    0xe63(%rip),%rdi
call   1080 <pexit@plt>
lea    0xe55(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    11cc <fchdirOperation+0x6c>
lea    0xe47(%rip),%rdi
call   1080 <pexit@plt>
mov    %ebx,%edi
call   1060 <fchdir@plt>
cmp    $0xffffffff,%eax
jne    11e4 <fchdirOperation+0x84>
lea    0xe29(%rip),%rdi
call   1080 <pexit@plt>
mov    %ebx,%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
je     11f6 <fchdirOperation+0x96>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe16(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1080 <pexit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c".\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [6 x i8] c"chdir\00"
@.str.4 = [5 x i8] c"stat\00"
@.str.5 = [6 x i8] c"close\00"
define void @fchdirOperation() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = load i32, i32* @O_RDONLY
%4 = call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @pexit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @pexit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = call i32 @stat(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @pexit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = load i32, i32* %1
%21 = call i32 @fchdir(i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @pexit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
%26 = load i32, i32* %1
%27 = call i32 @close(i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @pexit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %31
31: ; preds = %29, %25
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c".\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [6 x i8] c"chdir\00"
@.str.4 = [5 x i8] c"stat\00"
@.str.5 = [6 x i8] c"close\00"
define void @fchdirOperation() {
%1 = alloca %struct.stat
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @pexit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = tail call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @pexit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = bitcast %struct.stat* %1 to i8*
%14 = call i32 @stat(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 @pexit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = tail call i32 @fchdir(i32 %3)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @pexit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = tail call i32 @close(i32 %3)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = tail call i32 @pexit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
ret void
}