#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__ chdir(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ *getcwd(char *, int);
char *path_alloc(int *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *p;
  int size;
  if (chdir("..") < 0) {
    fprintf(stderr, "chdir to '..' failed\n");
  }
  p = path_alloc(&size);
  if (getcwd(p, size) == NULL) {
    fprintf(stderr, "getcwd failed\n");
  }
  printf("cwd = %s\n", p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%rax
jge    1191 <main+0x41>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
call   1070 <fprintf@plt>
lea    -0x1c(%rbp),%rdi
call   1050 <path_alloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <getcwd@plt>
cmp    $0x0,%rax
jne    11c9 <main+0x79>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
call   1030 <chdir@plt>
test   %rax,%rax
jns    117b <main+0x2b>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xc(%rsp),%rdi
call   1050 <path_alloc@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%esi
mov    %rax,%rdi
call   1060 <getcwd@plt>
test   %rax,%rax
jne    11ae <main+0x5e>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xe73(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"..\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"chdir to '..' failed\0A\00"
@.str.2 = [15 x i8] c"getcwd failed\0A\00"
@.str.3 = [10 x i8] c"cwd = %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %10, %2
%14 = call i8* @path_alloc(i32* %7)
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = call i32* @getcwd(i8* %15, i32 %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %19, %13
%23 = load i8*, i8** %6
%24 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"..\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"chdir to '..' failed\0A\00"
@.str.2 = [15 x i8] c"getcwd failed\0A\00"
@.str.3 = [10 x i8] c"cwd = %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %7, %2
%11 = call i8* @path_alloc(i32* %3)
%12 = load i32, i32* %3
%13 = call i32* @getcwd(i8* %11, i32 %12)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %15, %10
%19 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %11)
ret i32 0
}