#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 builtin_pwd(int argc, char *argv[]) {
  char buf[PATH_MAX];
  if (argc != 1) {
    fprintf(stderr, "%s: wrong argument\n", argv[0]);
    return 1;
  }
  if (!getcwd(buf, PATH_MAX)) {
    fprintf(stderr, "%s: cannot get working directory\n", argv[0]);
    return 1;
  }
  printf("%s\n", buf);
  return 0;
}


x86 assembly (clang, -O0):
<builtin_pwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2eaa(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     11a4 <builtin_pwd+0x74>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe74(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    120c <builtin_pwd+0xdc>
mov    -0x30(%rbp),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1040 <getcwd@plt>
cmp    $0x0,%eax
jne    11ee <builtin_pwd+0xbe>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe3e(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    120c <builtin_pwd+0xdc>
mov    -0x30(%rbp),%rsi
lea    0xe3d(%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):
<builtin_pwd>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    0x2eaf(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x1,%edi
jne    1178 <builtin_pwd+0x48>
mov    %rbx,%rdi
call   1040 <getcwd@plt>
test   %eax,%eax
je     118d <builtin_pwd+0x5d>
lea    0xeca(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
jmp    11aa <builtin_pwd+0x7a>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe75(%rip),%rsi
jmp    11a0 <builtin_pwd+0x70>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe74(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%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 = [20 x i8] c"%s: wrong argument\0A\00"
@.str.1 = [34 x i8] c"%s: cannot get working directory\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @builtin_pwd(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* %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 = icmp ne i32 %13, 1
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 1, i32* %3
store i32 1, i32* %8
br label %33
21: ; preds = %2
%22 = load i32, i32* @PATH_MAX
%23 = call i32 @getcwd(i8* %12, i32 %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %29)
store i32 1, i32* %3
store i32 1, i32* %8
br label %33
31: ; preds = %21
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %12)
store i32 0, i32* %3
store i32 1, i32* %8
br label %33
33: ; preds = %31, %25, %15
%34 = load i8*, i8** %6
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"%s: wrong argument\0A\00"
@.str.1 = [34 x i8] c"%s: cannot get working directory\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @builtin_pwd(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp eq i32 %0, 1
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %20
11: ; preds = %2
%12 = call i32 @getcwd(i8* %5, i32 %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %20
18: ; preds = %11
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %5)
br label %20
20: ; preds = %18, %14, %7
%21 = phi i32 [ 1, %7 ], [ 0, %18 ], [ 1, %14 ]
ret i32 %21
}