#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__ EINVAL;
scalar_t__ ENOENT;
scalar_t__ ERANGE;
int /*<<< orphan*/ assert(int);
int chdir(char *);
scalar_t__ errno;
int /*<<< orphan*/ *getcwd(char *, int);
scalar_t__ strcmp(char *, char *);
int test_getcwd(void) {
  {
    char buffer[256];
    assert(getcwd(buffer, 256) != NULL);
    assert(strcmp("/", buffer) == 0);
  }
  {
    char buffer[256];
    assert(chdir("/") == 0);
    assert(getcwd(buffer, 256) != NULL);
    assert(strcmp("/", buffer) == 0);
    assert(chdir("/bin") == 0);
    assert(getcwd(buffer, 256) != NULL);
    assert(strcmp("/bin", buffer) == 0);
    assert(chdir("/dev/") == 0);
    assert(getcwd(buffer, 256) != NULL);
    assert(strcmp("/dev", buffer) == 0);
  }
  {
    char buffer[5];
    assert(chdir("/") == 0);
    assert(getcwd(buffer, 2) != NULL);
    assert(strcmp("/", buffer) == 0);
    assert(getcwd(buffer, 1) == NULL);
    assert(errno == ERANGE);
    assert(getcwd(buffer, 0) == NULL);
    assert(errno == EINVAL);
    assert(chdir("/dev") == 0);
    assert(getcwd(buffer, 5) != NULL);
    assert(strcmp("/dev", buffer) == 0);
    assert(getcwd(buffer, 4) == NULL);
    assert(errno == ERANGE);
    assert(getcwd(buffer, 0) == NULL);
    assert(errno == EINVAL);
  }
  {
    char buffer[256];
    assert(chdir("/") == 0);
    assert(chdir("/directory/that/doesnt/exist") == -1);
    assert(errno == ENOENT);
    assert(getcwd(buffer, 256) != NULL);
    assert(strcmp("/", buffer) == 0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_getcwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x310,%rsp
lea    -0x100(%rbp),%rdi
mov    $0x100,%esi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x100(%rbp),%rsi
lea    0xe8e(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    0xe71(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x200(%rbp),%rdi
mov    $0x100,%esi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x200(%rbp),%rsi
lea    0xe2c(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    0xe06(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x200(%rbp),%rdi
mov    $0x100,%esi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x200(%rbp),%rsi
lea    0xdc1(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    0xda9(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x200(%rbp),%rdi
mov    $0x100,%esi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x200(%rbp),%rsi
lea    0xd6a(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    0xd4b(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x205(%rbp),%rdi
mov    $0x2,%esi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x205(%rbp),%rsi
lea    0xd06(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x205(%rbp),%rdi
mov    $0x1,%esi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    0x2c96(%rip),%rax
mov    (%rax),%rax
mov    0x2c9c(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x205(%rbp),%rdi
xor    %esi,%esi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    0x2c56(%rip),%rax
mov    (%rax),%rax
mov    0x2c44(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    0xc68(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x205(%rbp),%rdi
mov    $0x5,%esi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x205(%rbp),%rsi
lea    0xc23(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x205(%rbp),%rdi
mov    $0x4,%esi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    0x2bb1(%rip),%rax
mov    (%rax),%rax
mov    0x2bb7(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x205(%rbp),%rdi
xor    %esi,%esi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    0x2b71(%rip),%rax
mov    (%rax),%rax
mov    0x2b5f(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    0xb81(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    0xb6c(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    0x2b18(%rip),%rax
mov    (%rax),%rax
mov    0x2af6(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x310(%rbp),%rdi
mov    $0x100,%esi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x310(%rbp),%rsi
lea    0xaff(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x310,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_getcwd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1040 <getcwd@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
lea    0xe93(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
mov    %r14,%rdi
call   1030 <chdir@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x100,%esi
call   1040 <getcwd@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
lea    0xe1e(%rip),%rbx
mov    %rbx,%rdi
call   1030 <chdir@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
mov    %r12,%rdi
mov    $0x100,%esi
call   1040 <getcwd@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
lea    0xdd3(%rip),%rdi
call   1030 <chdir@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
mov    %r12,%rdi
mov    $0x100,%esi
call   1040 <getcwd@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
lea    0xda5(%rip),%r15
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
mov    %r14,%rdi
call   1030 <chdir@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1040 <getcwd@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <getcwd@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
mov    0x2ceb(%rip),%r12
mov    (%r12),%rax
mov    0x2cf0(%rip),%r13
xor    %edi,%edi
cmp    0x0(%r13),%rax
sete   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <getcwd@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
mov    (%r12),%rax
mov    0x2ca6(%rip),%rbp
xor    %edi,%edi
cmp    0x0(%rbp),%rax
sete   %dil
call   1060 <assert@plt>
mov    %r15,%rdi
call   1030 <chdir@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1040 <getcwd@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1040 <getcwd@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
mov    (%r12),%rax
xor    %edi,%edi
cmp    0x0(%r13),%rax
sete   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <getcwd@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
mov    (%r12),%rax
xor    %edi,%edi
cmp    0x0(%rbp),%rax
sete   %dil
call   1060 <assert@plt>
mov    %r14,%rdi
call   1030 <chdir@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
lea    0xc19(%rip),%rdi
call   1030 <chdir@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1060 <assert@plt>
mov    (%r12),%rax
mov    0x2bab(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%rax
sete   %dil
call   1060 <assert@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1040 <getcwd@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [5 x i8] c"/bin\00"
@.str.2 = [6 x i8] c"/dev/\00"
@.str.3 = [5 x i8] c"/dev\00"
@errno = global i64 0
@ERANGE = global i64 0
@EINVAL = global i64 0
@.str.4 = [29 x i8] c"/directory/that/doesnt/exist\00"
@ENOENT = global i64 0
define i32 @test_getcwd() {
%1 = alloca [256 x i8]
%2 = alloca [256 x i8]
%3 = alloca [5 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%6 = call i32* @getcwd(i8* %5, i32 256)
%7 = icmp ne i32* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%11 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%20 = call i32* @getcwd(i8* %19, i32 256)
%21 = icmp ne i32* %20, null
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%25 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = icmp eq i64 %25, 0
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = call i32 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%34 = call i32* @getcwd(i8* %33, i32 256)
%35 = icmp ne i32* %34, null
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%39 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = icmp eq i64 %39, 0
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = call i32 @chdir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%44 = icmp eq i32 %43, 0
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%48 = call i32* @getcwd(i8* %47, i32 256)
%49 = icmp ne i32* %48, null
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%53 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %52)
%54 = icmp eq i64 %53, 0
%55 = zext i1 %54 to i32
%56 = call i32 @assert(i32 %55)
%57 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%58 = icmp eq i32 %57, 0
%59 = zext i1 %58 to i32
%60 = call i32 @assert(i32 %59)
%61 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%62 = call i32* @getcwd(i8* %61, i32 2)
%63 = icmp ne i32* %62, null
%64 = zext i1 %63 to i32
%65 = call i32 @assert(i32 %64)
%66 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%67 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %66)
%68 = icmp eq i64 %67, 0
%69 = zext i1 %68 to i32
%70 = call i32 @assert(i32 %69)
%71 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%72 = call i32* @getcwd(i8* %71, i32 1)
%73 = icmp eq i32* %72, null
%74 = zext i1 %73 to i32
%75 = call i32 @assert(i32 %74)
%76 = load i64, i64* @errno
%77 = load i64, i64* @ERANGE
%78 = icmp eq i64 %76, %77
%79 = zext i1 %78 to i32
%80 = call i32 @assert(i32 %79)
%81 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%82 = call i32* @getcwd(i8* %81, i32 0)
%83 = icmp eq i32* %82, null
%84 = zext i1 %83 to i32
%85 = call i32 @assert(i32 %84)
%86 = load i64, i64* @errno
%87 = load i64, i64* @EINVAL
%88 = icmp eq i64 %86, %87
%89 = zext i1 %88 to i32
%90 = call i32 @assert(i32 %89)
%91 = call i32 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%92 = icmp eq i32 %91, 0
%93 = zext i1 %92 to i32
%94 = call i32 @assert(i32 %93)
%95 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%96 = call i32* @getcwd(i8* %95, i32 5)
%97 = icmp ne i32* %96, null
%98 = zext i1 %97 to i32
%99 = call i32 @assert(i32 %98)
%100 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%101 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %100)
%102 = icmp eq i64 %101, 0
%103 = zext i1 %102 to i32
%104 = call i32 @assert(i32 %103)
%105 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%106 = call i32* @getcwd(i8* %105, i32 4)
%107 = icmp eq i32* %106, null
%108 = zext i1 %107 to i32
%109 = call i32 @assert(i32 %108)
%110 = load i64, i64* @errno
%111 = load i64, i64* @ERANGE
%112 = icmp eq i64 %110, %111
%113 = zext i1 %112 to i32
%114 = call i32 @assert(i32 %113)
%115 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%116 = call i32* @getcwd(i8* %115, i32 0)
%117 = icmp eq i32* %116, null
%118 = zext i1 %117 to i32
%119 = call i32 @assert(i32 %118)
%120 = load i64, i64* @errno
%121 = load i64, i64* @EINVAL
%122 = icmp eq i64 %120, %121
%123 = zext i1 %122 to i32
%124 = call i32 @assert(i32 %123)
%125 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%126 = icmp eq i32 %125, 0
%127 = zext i1 %126 to i32
%128 = call i32 @assert(i32 %127)
%129 = call i32 @chdir(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%130 = icmp eq i32 %129, -1
%131 = zext i1 %130 to i32
%132 = call i32 @assert(i32 %131)
%133 = load i64, i64* @errno
%134 = load i64, i64* @ENOENT
%135 = icmp eq i64 %133, %134
%136 = zext i1 %135 to i32
%137 = call i32 @assert(i32 %136)
%138 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%139 = call i32* @getcwd(i8* %138, i32 256)
%140 = icmp ne i32* %139, null
%141 = zext i1 %140 to i32
%142 = call i32 @assert(i32 %141)
%143 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%144 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %143)
%145 = icmp eq i64 %144, 0
%146 = zext i1 %145 to i32
%147 = call i32 @assert(i32 %146)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [5 x i8] c"/bin\00"
@.str.2 = [6 x i8] c"/dev/\00"
@.str.3 = [5 x i8] c"/dev\00"
@errno = global i64 0
@ERANGE = global i64 0
@EINVAL = global i64 0
@.str.4 = [29 x i8] c"/directory/that/doesnt/exist\00"
@ENOENT = global i64 0
define i32 @test_getcwd() {
%1 = alloca [256 x i8]
%2 = alloca [256 x i8]
%3 = alloca [5 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%6 = call i32* @getcwd(i8* %5, i32 256)
%7 = icmp ne i32* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %5)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%15 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = call i32* @getcwd(i8* %14, i32 256)
%20 = icmp ne i32* %19, null
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %14)
%24 = icmp eq i64 %23, 0
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = call i32 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i32 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = call i32* @getcwd(i8* %14, i32 256)
%32 = icmp ne i32* %31, null
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%36 = icmp eq i64 %35, 0
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = call i32 @chdir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%40 = icmp eq i32 %39, 0
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = call i32* @getcwd(i8* %14, i32 256)
%44 = icmp ne i32* %43, null
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %14)
%48 = icmp eq i64 %47, 0
%49 = zext i1 %48 to i32
%50 = call i32 @assert(i32 %49)
%51 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%52 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%53 = icmp eq i32 %52, 0
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
%56 = call i32* @getcwd(i8* %51, i32 2)
%57 = icmp ne i32* %56, null
%58 = zext i1 %57 to i32
%59 = call i32 @assert(i32 %58)
%60 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %51)
%61 = icmp eq i64 %60, 0
%62 = zext i1 %61 to i32
%63 = call i32 @assert(i32 %62)
%64 = call i32* @getcwd(i8* %51, i32 1)
%65 = icmp eq i32* %64, null
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
%68 = load i64, i64* @errno
%69 = load i64, i64* @ERANGE
%70 = icmp eq i64 %68, %69
%71 = zext i1 %70 to i32
%72 = call i32 @assert(i32 %71)
%73 = call i32* @getcwd(i8* %51, i32 0)
%74 = icmp eq i32* %73, null
%75 = zext i1 %74 to i32
%76 = call i32 @assert(i32 %75)
%77 = load i64, i64* @errno
%78 = load i64, i64* @EINVAL
%79 = icmp eq i64 %77, %78
%80 = zext i1 %79 to i32
%81 = call i32 @assert(i32 %80)
%82 = call i32 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%83 = icmp eq i32 %82, 0
%84 = zext i1 %83 to i32
%85 = call i32 @assert(i32 %84)
%86 = call i32* @getcwd(i8* %51, i32 5)
%87 = icmp ne i32* %86, null
%88 = zext i1 %87 to i32
%89 = call i32 @assert(i32 %88)
%90 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %51)
%91 = icmp eq i64 %90, 0
%92 = zext i1 %91 to i32
%93 = call i32 @assert(i32 %92)
%94 = call i32* @getcwd(i8* %51, i32 4)
%95 = icmp eq i32* %94, null
%96 = zext i1 %95 to i32
%97 = call i32 @assert(i32 %96)
%98 = load i64, i64* @errno
%99 = load i64, i64* @ERANGE
%100 = icmp eq i64 %98, %99
%101 = zext i1 %100 to i32
%102 = call i32 @assert(i32 %101)
%103 = call i32* @getcwd(i8* %51, i32 0)
%104 = icmp eq i32* %103, null
%105 = zext i1 %104 to i32
%106 = call i32 @assert(i32 %105)
%107 = load i64, i64* @errno
%108 = load i64, i64* @EINVAL
%109 = icmp eq i64 %107, %108
%110 = zext i1 %109 to i32
%111 = call i32 @assert(i32 %110)
%112 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%113 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%114 = icmp eq i32 %113, 0
%115 = zext i1 %114 to i32
%116 = call i32 @assert(i32 %115)
%117 = call i32 @chdir(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%118 = icmp eq i32 %117, -1
%119 = zext i1 %118 to i32
%120 = call i32 @assert(i32 %119)
%121 = load i64, i64* @errno
%122 = load i64, i64* @ENOENT
%123 = icmp eq i64 %121, %122
%124 = zext i1 %123 to i32
%125 = call i32 @assert(i32 %124)
%126 = call i32* @getcwd(i8* %112, i32 256)
%127 = icmp ne i32* %126, null
%128 = zext i1 %127 to i32
%129 = call i32 @assert(i32 %128)
%130 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %112)
%131 = icmp eq i64 %130, 0
%132 = zext i1 %131 to i32
%133 = call i32 @assert(i32 %132)
ret i32 0
}