#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*/ _PC_PATH_MAX;
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ fchdir(int);
char *getcwd(int /*<<< orphan*/ *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pathconf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int getCwdTest() {
  char *cwd;
  cwd = getcwd(NULL, pathconf(".", _PC_PATH_MAX));
  puts(cwd);
  int dskr = open(cwd, O_RDONLY);
  printf("Deskriptorius: %d\n", dskr);
  chdir("/tmp");
  cwd = getcwd(NULL, pathconf(".", _PC_PATH_MAX));
  puts(cwd);
  fchdir(dskr);
  cwd = getcwd(NULL, pathconf(".", _PC_PATH_MAX));
  puts(cwd);
  return 1;
}


x86 assembly (clang, -O0):
<getCwdTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1040 <pathconf@plt>
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edi
call   1070 <getcwd@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe3e(%rip),%rdi
call   1060 <printf@plt>
lea    0xe45(%rip),%rdi
call   1050 <chdir@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
lea    0xe1b(%rip),%rdi
call   1040 <pathconf@plt>
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edi
call   1070 <getcwd@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <puts@plt>
mov    -0xc(%rbp),%edi
call   1080 <fchdir@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
lea    0xde6(%rip),%rdi
call   1040 <pathconf@plt>
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edi
call   1070 <getcwd@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCwdTest>:
push   %r15
push   %r14
push   %rbx
mov    0x2e5c(%rip),%r15
mov    (%r15),%esi
lea    0xe7a(%rip),%r14
mov    %r14,%rdi
call   1040 <pathconf@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1070 <getcwd@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <puts@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
mov    %eax,%ebx
lea    0xe46(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
lea    0xe4b(%rip),%rdi
call   1050 <chdir@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1040 <pathconf@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1070 <getcwd@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1080 <fchdir@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1040 <pathconf@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1070 <getcwd@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@_PC_PATH_MAX = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"Deskriptorius: %d\0A\00"
@.str.2 = [5 x i8] c"/tmp\00"
define i32 @getCwdTest() {
%1 = alloca i8*
%2 = alloca i32
%3 = load i32, i32* @_PC_PATH_MAX
%4 = call i32 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i8* @getcwd(i32* null, i32 %4)
store i8* %5, i8** %1
%6 = load i8*, i8** %1
%7 = call i32 @puts(i8* %6)
%8 = load i8*, i8** %1
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = call i32 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @_PC_PATH_MAX
%15 = call i32 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = call i8* @getcwd(i32* null, i32 %15)
store i8* %16, i8** %1
%17 = load i8*, i8** %1
%18 = call i32 @puts(i8* %17)
%19 = load i32, i32* %2
%20 = call i32 @fchdir(i32 %19)
%21 = load i32, i32* @_PC_PATH_MAX
%22 = call i32 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = call i8* @getcwd(i32* null, i32 %22)
store i8* %23, i8** %1
%24 = load i8*, i8** %1
%25 = call i32 @puts(i8* %24)
ret i32 1
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@_PC_PATH_MAX = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"Deskriptorius: %d\0A\00"
@.str.2 = [5 x i8] c"/tmp\00"
define i32 @getCwdTest() {
%1 = load i32, i32* @_PC_PATH_MAX
%2 = tail call i32 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i8* @getcwd(i32* null, i32 %2)
%4 = tail call i32 @puts(i8* dereferenceable(1) %3)
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %3, i32 %5)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = tail call i32 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @_PC_PATH_MAX
%10 = tail call i32 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = tail call i8* @getcwd(i32* null, i32 %10)
%12 = tail call i32 @puts(i8* dereferenceable(1) %11)
%13 = tail call i32 @fchdir(i32 %6)
%14 = load i32, i32* @_PC_PATH_MAX
%15 = tail call i32 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = tail call i8* @getcwd(i32* null, i32 %15)
%17 = tail call i32 @puts(i8* dereferenceable(1) %16)
ret i32 1
}