#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 */
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
int andysh_dir(char **args) {
  if (args[1] == NULL) {
    system("ls -alh");
  } else {
    char *s = malloc(sizeof(char) * strlen(args[1]) + sizeof(char) * 10);
    strcpy(s, "ls -alh ");
    strcat(s, args[1]);
    system(s);
  }
}


x86 assembly (clang, -O0):
<andysh_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    117c <andysh_dir+0x2c>
lea    0xe8e(%rip),%rdi
call   1050 <system@plt>
jmp    11c8 <andysh_dir+0x78>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0xa,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
call   1050 <system@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<andysh_dir>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x8(%rdi),%rdi
test   %rdi,%rdi
je     118d <andysh_dir+0x3d>
call   1040 <strlen@plt>
lea    0xa(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xe91(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
jmp    1194 <andysh_dir+0x44>
lea    0xe6c(%rip),%rbx
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <system@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"ls -alh\00"
@.str.1 = [9 x i8] c"ls -alh \00"
define i32 @andysh_dir(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i8*
store i8** %0, i8*** %3
%5 = load i8**, i8*** %3
%6 = getelementptr inbounds i8*, i8** %5, i64 1
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %30
11: ; preds = %1
%12 = load i8**, i8*** %3
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @strlen(i8* %14)
%16 = sext i32 %15 to i64
%17 = mul i64 1, %16
%18 = add i64 %17, 10
%19 = trunc i64 %18 to i32
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%23 = load i8*, i8** %4
%24 = load i8**, i8*** %3
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @strcat(i8* %23, i8* %26)
%28 = load i8*, i8** %4
%29 = call i32 @system(i8* %28)
br label %30
30: ; preds = %11, %9
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [8 x i8] c"ls -alh\00"
@.str.1 = [9 x i8] c"ls -alh \00"
define i32 @andysh_dir(i8** nocapture %0) {
%2 = getelementptr inbounds i8*, i8** %0, i64 1
%3 = load i8*, i8** %2
%4 = icmp eq i8* %3, null
br i1 %4, label %12, label %5
5: ; preds = %1
%6 = tail call i32 @strlen(i8* %3)
%7 = add i32 %6, 10
%8 = tail call i8* @malloc(i32 %7)
%9 = tail call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%10 = load i8*, i8** %2
%11 = tail call i32 @strcat(i8* %8, i8* %10)
br label %12
12: ; preds = %1, %5
%13 = phi i8* [ %8, %5 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %1 ]
%14 = tail call i32 @system(i8* %13)
ret i32 undef
}