#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 PATH_MAX;
int chdir(char *);
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ pexit(char *);
int stat(char *, struct stat *);
void chdirOperation() {
  char cwd[PATH_MAX];
  if (getcwd(cwd, PATH_MAX) == NULL) {
    pexit("getcwd");
  }
  if (chdir("..") == -1) {
    pexit("chdir");
  }
  struct stat sBuf;
  if (stat(".", &sBuf) == -1) {
    pexit("stat");
  }
  if (chdir(cwd) == -1) {
    pexit("chdir");
  }
}


x86 assembly (clang, -O0):
<chdirOperation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x8(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x20(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x10(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
jne    1198 <chdirOperation+0x58>
lea    0xe6d(%rip),%rdi
call   1060 <pexit@plt>
lea    0xe68(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0xffffffff,%eax
jne    11b9 <chdirOperation+0x79>
lea    0xe56(%rip),%rdi
call   1060 <pexit@plt>
lea    0xe48(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    11de <chdirOperation+0x9e>
lea    0xe37(%rip),%rdi
call   1060 <pexit@plt>
mov    -0x20(%rbp),%rdi
call   1030 <chdir@plt>
cmp    $0xffffffff,%eax
jne    11fc <chdirOperation+0xbc>
lea    0xe13(%rip),%rdi
call   1060 <pexit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chdirOperation>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1040 <getcwd@plt>
test   %rax,%rax
jne    117c <chdirOperation+0x3c>
lea    0xe89(%rip),%rdi
call   1060 <pexit@plt>
lea    0xe84(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0xffffffff,%eax
jne    1199 <chdirOperation+0x59>
lea    0xe76(%rip),%rdi
call   1060 <pexit@plt>
lea    0xe68(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    11ba <chdirOperation+0x7a>
lea    0xe5b(%rip),%rdi
call   1060 <pexit@plt>
mov    %rbx,%rdi
call   1030 <chdir@plt>
cmp    $0xffffffff,%eax
jne    11d3 <chdirOperation+0x93>
lea    0xe3c(%rip),%rdi
call   1060 <pexit@plt>
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@.str = [7 x i8] c"getcwd\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [6 x i8] c"chdir\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [5 x i8] c"stat\00"
define void @chdirOperation() {
%1 = alloca %struct.stat
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i32* @getcwd(i8* %4, i32 %2)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @pexit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, 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.1, 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.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = bitcast %struct.stat* %1 to i8*
%16 = call i32 @stat(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), %struct.stat* %1)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @pexit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = call i32 @chdir(i8* %4)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @pexit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
ret void
}