#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ *getcwd(char *, int);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, const char *argv[]) {
  char buf[512];
  if (getcwd(buf, sizeof(buf)) == NULL) {
    write(2, "pwd: cannot get current directory\n", 34);
    return 1;
  }
  write(1, buf, strlen(buf));
  write(1, "\n", 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x210(%rbp),%rdi
mov    $0x200,%esi
call   1050 <getcwd@plt>
cmp    $0x0,%rax
jne    1186 <main+0x56>
mov    $0x2,%edi
lea    0xe90(%rip),%rsi
mov    $0x22,%edx
call   1030 <write@plt>
movl   $0x1,-0x4(%rbp)
jmp    11cd <main+0x9d>
lea    -0x210(%rbp),%rax
mov    %rax,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x218(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    $0x1,%edx
lea    0xe62(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x200,%rsp
mov    %rsp,%rdi
mov    $0x200,%esi
call   1050 <getcwd@plt>
test   %rax,%rax
je     117e <main+0x4e>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xeb6(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %eax,%eax
jmp    1199 <main+0x69>
lea    0xe7b(%rip),%rsi
mov    $0x2,%edi
mov    $0x22,%edx
call   1030 <write@plt>
mov    $0x1,%eax
add    $0x200,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [35 x i8] c"pwd: cannot get current directory\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%8 = call i32* @getcwd(i8* %7, i32 512)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @write(i32 2, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 34)
store i32 1, i32* %3
br label %18
12: ; preds = %2
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = call i32 @write(i32 1, i8* %13, i32 %15)
%17 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
store i32 0, i32* %3
br label %18
18: ; preds = %12, %10
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@.str = [35 x i8] c"pwd: cannot get current directory\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = call i32* @getcwd(i8* %4, i32 512)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = call i32 @write(i32 2, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 34)
br label %13
9: ; preds = %2
%10 = call i32 @strlen(i8* %4)
%11 = call i32 @write(i32 1, i8* %4, i32 %10)
%12 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %13
13: ; preds = %9, %7
%14 = phi i32 [ 1, %7 ], [ 0, %9 ]
ret i32 %14
}