#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 PATH_MAX;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char pwd[PATH_MAX];
  if (getcwd(pwd, PATH_MAX) == NULL) {
    fprintf(stderr, "%s: cannot determine current directory!\n", argv[0]);
    return 2;
  }
  printf("%s\n", pwd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
jne    11b9 <main+0x89>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe5f(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    11d7 <main+0xa7>
mov    -0x30(%rbp),%rsi
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    0x2eaf(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1040 <getcwd@plt>
test   %rax,%rax
je     1177 <main+0x47>
lea    0xebe(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
jmp    1194 <main+0x64>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe76(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [41 x i8] c"%s: cannot determine current directory!\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32* @getcwd(i8* %5, i32 %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %14
14: ; preds = %12, %8
%15 = phi i32 [ 2, %8 ], [ 0, %12 ]
ret i32 %15
}