#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 errno;
int /*<<< orphan*/ free(char *);
char *getcwd(char *, int);
int /*<<< orphan*/ perror(char *);
size_t strlen(char *);
int /*<<< orphan*/ write(int, char *, size_t);
int main(int argc, char *argv[]) {
  char *path = NULL;
  path = getcwd(path, 255);
  if (path == NULL) {
    perror("pwd: getcwd");
    return errno;
  }
  path[strlen(path)] = '\n';
  write(1, path, strlen(path));
  free(path);
  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)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0xff,%esi
call   1060 <getcwd@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a8 <main+0x58>
lea    0xe6e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11f6 <main+0xa6>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
movb   $0xa,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
mov    $0x1,%edi
call   1040 <write@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %edi,%edi
mov    $0xff,%esi
call   1060 <getcwd@plt>
test   %rax,%rax
je     11a2 <main+0x52>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
movb   $0xa,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <write@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe57(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%r14d
jmp    1197 <main+0x47>

LLVM IR (-O0):
@.str = [12 x i8] c"pwd: getcwd\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%7 = load i8*, i8** %6
%8 = call i8* @getcwd(i8* %7, i32 255)
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @errno
store i32 %13, i32* %3
br label %25
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = load i8*, i8** %6
%17 = call i64 @strlen(i8* %16)
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8 10, i8* %18
%19 = load i8*, i8** %6
%20 = load i8*, i8** %6
%21 = call i64 @strlen(i8* %20)
%22 = call i32 @write(i32 1, i8* %19, i64 %21)
%23 = load i8*, i8** %6
%24 = call i32 @free(i8* %23)
store i32 0, i32* %3
br label %25
25: ; preds = %14, %11
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [12 x i8] c"pwd: getcwd\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i8* @getcwd(i8* null, i32 255)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @errno
br label %14
8: ; preds = %2
%9 = tail call i64 @strlen(i8* %3)
%10 = getelementptr inbounds i8, i8* %3, i64 %9
store i8 10, i8* %10
%11 = tail call i64 @strlen(i8* %3)
%12 = tail call i32 @write(i32 1, i8* %3, i64 %11)
%13 = tail call i32 @free(i8* %3)
br label %14
14: ; preds = %8, %5
%15 = phi i32 [ %7, %5 ], [ 0, %8 ]
ret i32 %15
}