#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 /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ _PC_PATH_MAX;
char *getcwd(char *, size_t);
char *malloc(int);
long pathconf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int /*<<< orphan*/);
main(int argc, char *argv[]) {
  char *currDir = NULL;
  if (argc == 1) {
    long size;
    char *buf;
    size = pathconf(".", _PC_PATH_MAX);
    if ((buf = (char *)malloc((size_t)size)) != NULL)
      currDir = getcwd(buf, (size_t)size);
    char *print = malloc(1024 * sizeof(char));
    *print = '\0';
    strcat(print, currDir);
    strcat(print, "\n");
    write(STDOUT_FILENO, print, strlen(print));
  } else {
    char *print = malloc(200 * sizeof(char));
    *print = '\0';
    strcat(print, argv[0]);
    strcat(print, ": illegal parameter to command: pwd\n");
    write(STDERR_FILENO, print, strlen(print));
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    122d <main+0xcd>
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdi
call   1040 <pathconf@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11cb <main+0x6b>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <getcwd@plt>
mov    %rax,-0x18(%rbp)
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x30(%rbp),%rdi
lea    0xe2d(%rip),%rsi
call   1080 <strcat@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    128d <main+0x12d>
mov    $0xc8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1080 <strcat@plt>
mov    -0x38(%rbp),%rdi
lea    0xda5(%rip),%rsi
call   1080 <strcat@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x1,%edi
jne    119d <main+0x3d>
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
call   1040 <pathconf@plt>
mov    %rax,%rbx
mov    %ebx,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11d3 <main+0x73>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1060 <getcwd@plt>
mov    %rax,%r14
jmp    11d6 <main+0x76>
mov    %rsi,%r14
mov    $0xc8,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    (%r14),%rsi
mov    %rax,%rdi
call   1080 <strcat@plt>
lea    0xe40(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    0x2dff(%rip),%rax
jmp    1207 <main+0xa7>
xor    %r14d,%r14d
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %rax,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
lea    0xe2d(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@_PC_PATH_MAX = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [37 x i8] c": illegal parameter to command: pwd\0A\00"
@STDERR_FILENO = 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 i8*
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %37
13: ; preds = %2
%14 = load i32, i32* @_PC_PATH_MAX
%15 = call i64 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %14)
store i64 %15, i64* %7
%16 = load i64, i64* %7
%17 = trunc i64 %16 to i32
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %8
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = load i8*, i8** %8
%22 = load i64, i64* %7
%23 = call i8* @getcwd(i8* %21, i64 %22)
store i8* %23, i8** %6
br label %24
24: ; preds = %20, %13
%25 = call i8* @malloc(i32 1024)
store i8* %25, i8** %9
%26 = load i8*, i8** %9
store i8 0, i8* %26
%27 = load i8*, i8** %9
%28 = load i8*, i8** %6
%29 = call i32 @strcat(i8* %27, i8* %28)
%30 = load i8*, i8** %9
%31 = call i32 @strcat(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @STDOUT_FILENO
%33 = load i8*, i8** %9
%34 = load i8*, i8** %9
%35 = call i32 @strlen(i8* %34)
%36 = call i32 @write(i32 %32, i8* %33, i32 %35)
br label %52
37: ; preds = %2
%38 = call i8* @malloc(i32 200)
store i8* %38, i8** %10
%39 = load i8*, i8** %10
store i8 0, i8* %39
%40 = load i8*, i8** %10
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = call i32 @strcat(i8* %40, i8* %43)
%45 = load i8*, i8** %10
%46 = call i32 @strcat(i8* %45, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%47 = load i32, i32* @STDERR_FILENO
%48 = load i8*, i8** %10
%49 = load i8*, i8** %10
%50 = call i32 @strlen(i8* %49)
%51 = call i32 @write(i32 %47, i8* %48, i32 %50)
br label %52
52: ; preds = %37, %24
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@_PC_PATH_MAX = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [37 x i8] c": illegal parameter to command: pwd\0A\00"
@STDERR_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %17
4: ; preds = %2
%5 = load i32, i32* @_PC_PATH_MAX
%6 = tail call i64 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = trunc i64 %6 to i32
%8 = tail call i8* @malloc(i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %4
%11 = tail call i8* @getcwd(i8* %8, i64 %6)
br label %12
12: ; preds = %10, %4
%13 = phi i8* [ %11, %10 ], [ null, %4 ]
%14 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
store i8 0, i8* %14
%15 = tail call i32 @strcat(i8* %14, i8* %13)
%16 = tail call i32 @strcat(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %22
17: ; preds = %2
%18 = tail call dereferenceable_or_null(200) i8* @malloc(i32 200)
store i8 0, i8* %18
%19 = load i8*, i8** %1
%20 = tail call i32 @strcat(i8* %18, i8* %19)
%21 = tail call i32 @strcat(i8* %18, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %17, %12
%23 = phi i32* [ @STDERR_FILENO, %17 ], [ @STDOUT_FILENO, %12 ]
%24 = phi i8* [ %18, %17 ], [ %14, %12 ]
%25 = load i32, i32* %23
%26 = tail call i32 @strlen(i8* %24)
%27 = tail call i32 @write(i32 %25, i8* %24, i32 %26)
ret i32 0
}