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

/* Variables and functions */
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int mshell_pwd(char **args) {
  if (args[1] != NULL) {
    char cwd[1024];
    getcwd(cwd, sizeof(cwd));
    printf("Current Working dir: %s\n", cwd);
  } else {
    char cwd[1024];
    getcwd(cwd, sizeof(cwd));
    printf("Current Working dir: %s\n", cwd);
  }
}


x86 assembly (clang, -O0):
<mshell_pwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     1167 <mshell_pwd+0x47>
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   1040 <getcwd@plt>
lea    -0x410(%rbp),%rsi
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
jmp    118b <mshell_pwd+0x6b>
lea    -0x810(%rbp),%rdi
mov    $0x400,%esi
call   1040 <getcwd@plt>
lea    -0x810(%rbp),%rsi
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mshell_pwd>:
push   %rbx
sub    $0x400,%rsp
cmpq   $0x0,0x8(%rdi)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1040 <getcwd@plt>
lea    0xebc(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Current Working dir: %s\0A\00"
define i32 @mshell_pwd(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
store i8** %0, i8*** %3
%6 = load i8**, i8*** %3
%7 = getelementptr inbounds i8*, i8** %6, i64 1
%8 = load i8*, i8** %7
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%12 = call i32 @getcwd(i8* %11, i32 1024)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %20
15: ; preds = %1
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%17 = call i32 @getcwd(i8* %16, i32 1024)
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%19 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %15, %10
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@.str = [25 x i8] c"Current Working dir: %s\0A\00"
define i32 @mshell_pwd(i8** nocapture %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds i8*, i8** %0, i64 1
%5 = load i8*, i8** %4
%6 = icmp eq i8* %5, null
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%9 = call i32 @getcwd(i8* %8, i32 1024)
%10 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %15
11: ; preds = %1
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%13 = call i32 @getcwd(i8* %12, i32 1024)
%14 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %15
15: ; preds = %11, %7
ret i32 undef
}