#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*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ system(char *);
void _list_directory(const char *path) {
  char line[256];
  if (path && *path)
    sprintf(line, "ls %s", path);
  else
    sprintf(line, "ls");
  system(line);
}


x86 assembly (clang, -O0):
<_list_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1168 <_list_directory+0x48>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1168 <_list_directory+0x48>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xea4(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    117d <_list_directory+0x5d>
lea    -0x110(%rbp),%rdi
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <system@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_list_directory>:
sub    $0x108,%rsp
test   %rdi,%rdi
je     1147 <_list_directory+0x27>
mov    %rdi,%rdx
cmpb   $0x0,(%rdi)
je     1147 <_list_directory+0x27>
lea    0xec5(%rip),%rsi
mov    %rsp,%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
jmp    1152 <_list_directory+0x32>
movb   $0x0,0x2(%rsp)
movw   $0x736c,(%rsp)
mov    %rsp,%rdi
call   1030 <system@plt>
add    $0x108,%rsp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"ls %s\00"
@.str.1 = [3 x i8] c"ls\00"
define void @_list_directory(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %15
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%13 = load i8*, i8** %2
%14 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %18
15: ; preds = %6, %1
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %15, %11
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%20 = call i32 @system(i8* %19)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"ls %s\00"
@.str.1 = [3 x i8] c"ls\00"
define void @_list_directory(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = call i32 (i8*, i8*, ...) @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %11
10: ; preds = %5, %1
br label %11
11: ; preds = %10, %8
%12 = call i32 @system(i8* %3)
ret void
}