char *dir(path, full)
char *path;
int full;
{
  char cmd[128];
  static char name[32];
  tmpnam(name);
  if (full)
    sprintf(cmd, "ls -l %s > %s", path, name);
  else
    sprintf(cmd, "ls %s > %s", path, name);
  system(cmd);
  return (name);
}


x86 assembly (clang, -O0):
<dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0x2f07(%rip),%rdi
mov    $0x0,%al
call   1050 <tmpnam@plt>
cmpl   $0x0,-0xc(%rbp)
je     117f <dir+0x4f>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe94(%rip),%rsi
lea    0x2edd(%rip),%rcx
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    119f <dir+0x6f>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe7d(%rip),%rsi
lea    0x2eb8(%rip),%rcx
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x90(%rbp),%rdi
mov    $0x0,%al
call   1030 <system@plt>
lea    0x2e9c(%rip),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
lea    0x2f08(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <tmpnam@plt>
test   %ebx,%ebx
lea    0xeb3(%rip),%rax
lea    0xe9e(%rip),%rsi
cmove  %rax,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <system@plt>
mov    %r15,%rax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@dir.name = internal global [32 x i8] zeroinitializer
@.str = [14 x i8] c"ls -l %s > %s\00"
@.str.1 = [11 x i8] c"ls %s > %s\00"
define i8* @dir(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [128 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = call i32 (i8*, ...) bitcast (i32 (...)* @tmpnam to i32 (i8*, ...)*)(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @dir.name, i64 0, i64 0))
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%11 = load i8*, i8** %3
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %10, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %11, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @dir.name, i64 0, i64 0))
br label %17
13: ; preds = %2
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%15 = load i8*, i8** %3
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @dir.name, i64 0, i64 0))
br label %17
17: ; preds = %13, %9
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%19 = call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* %18)
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @dir.name, i64 0, i64 0)
}

LLVM IR (-O2):
@dir.name = internal global [32 x i8] zeroinitializer
@.str = [14 x i8] c"ls -l %s > %s\00"
@.str.1 = [11 x i8] c"ls %s > %s\00"
define i8* @dir(i8* %0, i32 %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (i8*, ...) bitcast (i32 (...)* @tmpnam to i32 (i8*, ...)*)(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @dir.name, i64 0, i64 0))
%6 = icmp eq i32 %1, 0
%7 = select i1 %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0)
%8 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) %7, i8* %0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @dir.name, i64 0, i64 0))
%9 = call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* %4)
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @dir.name, i64 0, i64 0)
}