#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int PATH_MAX;
int /*<<< orphan*/ SYS_getcwd;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int syscall(int /*<<< orphan*/, char *, int);
int main(void) {
  char path[PATH_MAX];
  int status;
  status = syscall(SYS_getcwd, path, PATH_MAX);
  if (status < 0) {
    perror("getcwd()");
    exit(EXIT_FAILURE);
  }
  puts(path);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x28(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
call   1040 <syscall@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11b9 <main+0x79>
lea    0xe5a(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1030 <puts@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    0x2ea3(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1040 <syscall@plt>
test   %eax,%eax
jns    1192 <main+0x52>
lea    0xe81(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@SYS_getcwd = global i32 0
@.str = [9 x i8] c"getcwd()\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
store i8* %7, i8** %2
%8 = alloca i8, i64 %6
store i64 %6, i64* %3
%9 = load i32, i32* @SYS_getcwd
%10 = load i32, i32* @PATH_MAX
%11 = call i32 @syscall(i32 %9, i8* %8, i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %0
%19 = call i32 @puts(i8* %8)
%20 = load i32, i32* @EXIT_SUCCESS
%21 = call i32 @exit(i32 %20)
unreachable
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@SYS_getcwd = global i32 0
@.str = [9 x i8] c"getcwd()\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = load i32, i32* @PATH_MAX
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = load i32, i32* @SYS_getcwd
%5 = call i32 @syscall(i32 %4, i8* %3, i32 %1)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = call i32 @puts(i8* %3)
%13 = load i32, i32* @EXIT_SUCCESS
%14 = call i32 @exit(i32 %13)
unreachable
}