#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int PATH_MAX;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *const argv[]) {
  char pathname[PATH_MAX];
  ((void)argc);
  ((void)argv);
  if (getcwd(pathname, PATH_MAX) == NULL) {
    fprintf(stderr, "pwd: cannot getcwd\n");
    return (EXIT_FAILURE);
  }
  printf("%s\n", pathname);
  return (EXIT_SUCCESS);
}


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    11b7 <main+0x87>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    11da <main+0xaa>
mov    -0x30(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-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   %rbx
push   %rax
mov    0x2eb3(%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     1178 <main+0x48>
lea    0xead(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x2e52(%rip),%rax
jmp    1194 <main+0x64>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"pwd: cannot getcwd\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
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* %4
%14 = load i8**, i8*** %5
%15 = load i32, i32* @PATH_MAX
%16 = call i32* @getcwd(i8* %12, i32 %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
store i32 %21, i32* %3
store i32 1, i32* %8
br label %25
22: ; preds = %2
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%24 = load i32, i32* @EXIT_SUCCESS
store i32 %24, i32* %3
store i32 1, i32* %8
br label %25
25: ; preds = %22, %18
%26 = load i8*, i8** %6
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"pwd: cannot getcwd\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %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 %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %13
13: ; preds = %11, %8
%14 = phi i32* [ @EXIT_FAILURE, %8 ], [ @EXIT_SUCCESS, %11 ]
%15 = load i32, i32* %14
ret i32 %15
}