#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*/ resp;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *show_dir_with_system(char *path) {
  char *command = (char *)malloc(sizeof(char) * 200);
  strcpy(command, "/bin/ls -Al ");
  strcat(command, path);
  strcat(command, " | awk '{print $9}' ");
  FILE *fp;
  char *resp = (char *)malloc(sizeof(char) * 1000);
  fp = popen(command, "r");
  if (fp == NULL) {
    printf("Failed to run command\n");
    exit(1);
  }
  char *buf = (char *)malloc(sizeof(char) * 1000);
  strcpy(buf, "DIRECTORIO COMPARTIDO: ");
  strcat(buf, path);
  strcat(buf, "\n\n");
  while (fgets(resp, sizeof(resp) - 1, fp) != NULL) {
    strcat(buf, resp);
  }
  pclose(fp);
  return buf;
}


x86 assembly (clang, -O0):
<show_dir_with_system>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0xc8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1090 <strcat@plt>
mov    $0x3e8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    120a <show_dir_with_system+0x8a>
lea    0xe29(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x3e8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    0xe13(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x7,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1273 <show_dir_with_system+0xf3>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <strcat@plt>
jmp    1245 <show_dir_with_system+0xc5>
mov    -0x18(%rbp),%rdi
call   1050 <pclose@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_dir_with_system>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    $0xc8,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe61(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
lea    0xe54(%rip),%rsi
mov    %r14,%rdi
call   1090 <strcat@plt>
mov    $0x3e8,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe4d(%rip),%rsi
mov    %r14,%rdi
call   1080 <popen@plt>
test   %rax,%rax
je     1259 <show_dir_with_system+0xd9>
mov    %rax,%r14
mov    $0x3e8,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
lea    0xe2b(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
lea    0xe29(%rip),%rsi
mov    %r12,%rdi
cs nopw 0x0(%rax,%rax,1)
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1242 <show_dir_with_system+0xc2>
mov    %r12,%rdi
mov    %rbx,%rsi
jmp    1220 <show_dir_with_system+0xa0>
mov    %r14,%rdi
call   1050 <pclose@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xddf(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/bin/ls -Al \00"
@.str.1 = [21 x i8] c" | awk '{print $9}' \00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [23 x i8] c"Failed to run command\0A\00"
@.str.4 = [24 x i8] c"DIRECTORIO COMPARTIDO: \00"
@.str.5 = [3 x i8] c"\0A\0A\00"
define i8* @show_dir_with_system(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
%7 = call i64 @malloc(i32 200)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %3
%12 = load i8*, i8** %2
%13 = call i32 @strcat(i8* %11, i8* %12)
%14 = load i8*, i8** %3
%15 = call i32 @strcat(i8* %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%16 = call i64 @malloc(i32 1000)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %5
%18 = load i8*, i8** %3
%19 = call i32* @popen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %19, i32** %4
%20 = load i32*, i32** %4
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %1
%23 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %1
%26 = call i64 @malloc(i32 1000)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %6
%28 = load i8*, i8** %6
%29 = call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%30 = load i8*, i8** %6
%31 = load i8*, i8** %2
%32 = call i32 @strcat(i8* %30, i8* %31)
%33 = load i8*, i8** %6
%34 = call i32 @strcat(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %35
35: ; preds = %40, %25
%36 = load i8*, i8** %5
%37 = load i32*, i32** %4
%38 = call i32* @fgets(i8* %36, i32 7, i32* %37)
%39 = icmp ne i32* %38, null
br i1 %39, label %40, label %44
40: ; preds = %35
%41 = load i8*, i8** %6
%42 = load i8*, i8** %5
%43 = call i32 @strcat(i8* %41, i8* %42)
br label %35
44: ; preds = %35
%45 = load i32*, i32** %4
%46 = call i32 @pclose(i32* %45)
%47 = load i8*, i8** %6
ret i8* %47
}

LLVM IR (-O2):
@.str = [13 x i8] c"/bin/ls -Al \00"
@.str.1 = [21 x i8] c" | awk '{print $9}' \00"
@.str.2 = [2 x i8] c"r\00"
@.str.4 = [24 x i8] c"DIRECTORIO COMPARTIDO: \00"
@.str.5 = [3 x i8] c"\0A\0A\00"
@str = [22 x i8] c"Failed to run command\00"
define i8* @show_dir_with_system(i8* %0) {
%2 = tail call i64 @malloc(i32 200)
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @strcat(i8* %3, i8* %0)
%6 = tail call i32 @strcat(i8* %3, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i64 @malloc(i32 1000)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32* @popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = tail call i64 @malloc(i32 1000)
%16 = inttoptr i64 %15 to i8*
%17 = tail call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%18 = tail call i32 @strcat(i8* %16, i8* %0)
%19 = tail call i32 @strcat(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%20 = tail call i32* @fgets(i8* %8, i32 7, i32* %9)
%21 = icmp eq i32* %20, null
br i1 %21, label %26, label %22
22: ; preds = %14, %22
%23 = tail call i32 @strcat(i8* %16, i8* %8)
%24 = tail call i32* @fgets(i8* %8, i32 7, i32* %9)
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %22
26: ; preds = %22, %14
%27 = tail call i32 @pclose(i32* %9)
ret i8* %16
}