#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 */
typedef int /*<<< orphan*/ cwd;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
void current_working_directory() {
  char cwd[256] = {'\0'};
  if (getcwd(cwd, sizeof(cwd)) != NULL)
    fprintf(stdout, "Current working dir: %s\n", cwd);
  else
    perror("getcwd() error");
}


x86 assembly (clang, -O0):
<current_working_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
lea    -0x100(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1030 <memset@plt>
lea    -0x100(%rbp),%rdi
mov    $0x100,%esi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
je     119a <current_working_directory+0x5a>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    -0x100(%rbp),%rdx
lea    0xe70(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11a6 <current_working_directory+0x66>
lea    0xe78(%rip),%rdi
call   1060 <perror@plt>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<current_working_directory>:
sub    $0x108,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x100,%esi
call   1030 <getcwd@plt>
test   %rax,%rax
je     11d3 <current_working_directory+0xa3>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
mov    %rsp,%rdx
call   1040 <fprintf@plt>
add    $0x108,%rsp
ret
lea    0xe3f(%rip),%rdi
call   1050 <perror@plt>
add    $0x108,%rsp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [25 x i8] c"Current working dir: %s\0A\00"
@.str.1 = [15 x i8] c"getcwd() error\00"
define void @current_working_directory() {
%1 = alloca [256 x i8]
%2 = bitcast [256 x i8]* %1 to i8*
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = call i32* @getcwd(i8* %3, i32 256)
%5 = icmp ne i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @stdout
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%9 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %6
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [25 x i8] c"Current working dir: %s\0A\00"
@.str.1 = [15 x i8] c"getcwd() error\00"
define void @current_working_directory() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = call i32* @getcwd(i8* %2, i32 256)
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = load i32, i32* @stdout
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
ret void
}