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

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ malloc(scalar_t__);
int pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int runCommand(char *command, char **output) {
  int result = 0;
  FILE *fp;
  int status;
  char path[1024];
  char temp_output[2048];
  temp_output[0] = 0;
  fp = popen(command, "r");
  if (fp == NULL) {
    printf("failed \n");
    return 1;
  }
  while (fgets(path, sizeof(path) - 1, fp) != NULL) {
    strcat(temp_output, path);
  }
  *output = (char *)malloc(strlen(temp_output) + 1);
  strcpy(*output, temp_output);
  result = pclose(fp) / 256;
  return result;
}


x86 assembly (clang, -O0):
<runCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movb   $0x0,-0xc30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d8 <runCommand+0x58>
lea    0xe3b(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1263 <runCommand+0xe3>
jmp    11dd <runCommand+0x5d>
lea    -0x430(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x3ff,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1214 <runCommand+0x94>
lea    -0xc30(%rbp),%rdi
lea    -0x430(%rbp),%rsi
call   10a0 <strcat@plt>
jmp    11dd <runCommand+0x5d>
lea    -0xc30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    -0xc30(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
call   1060 <pclose@plt>
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runCommand>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xc08,%rsp
mov    %rsi,%r14
movb   $0x0,0x400(%rsp)
lea    0xe60(%rip),%rsi
call   1090 <popen@plt>
test   %rax,%rax
je     1241 <runCommand+0xc1>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x3ff,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1200 <runCommand+0x80>
lea    0x400(%rsp),%r15
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
mov    $0x3ff,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    11e0 <runCommand+0x60>
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1080 <malloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
call   1060 <pclose@plt>
mov    %eax,%ecx
lea    0xff(%rcx),%eax
test   %ecx,%ecx
cmovns %ecx,%eax
sar    $0x8,%eax
jmp    1252 <runCommand+0xd2>
lea    0xdba(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0xc08,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [9 x i8] c"failed \0A\00"
define i32 @runCommand(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = alloca [2048 x i8]
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
store i8 0, i8* %11
%12 = load i8*, i8** %4
%13 = call i32* @popen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %7
%14 = load i32*, i32** %7
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %43
18: ; preds = %2
br label %19
19: ; preds = %24, %18
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%21 = load i32*, i32** %7
%22 = call i32* @fgets(i8* %20, i32 1023, i32* %21)
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%27 = call i32 @strcat(i8* %25, i8* %26)
br label %19
28: ; preds = %19
%29 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%30 = call i64 @strlen(i8* %29)
%31 = add nsw i64 %30, 1
%32 = call i64 @malloc(i64 %31)
%33 = inttoptr i64 %32 to i8*
%34 = load i8**, i8*** %5
store i8* %33, i8** %34
%35 = load i8**, i8*** %5
%36 = load i8*, i8** %35
%37 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%38 = call i32 @strcpy(i8* %36, i8* %37)
%39 = load i32*, i32** %7
%40 = call i32 @pclose(i32* %39)
%41 = sdiv i32 %40, 256
store i32 %41, i32* %6
%42 = load i32, i32* %6
store i32 %42, i32* %3
br label %43
43: ; preds = %28, %16
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@str = [8 x i8] c"failed \00"
define i32 @runCommand(i8* nocapture %0, i8** nocapture writeonly %1) {
%3 = alloca [1024 x i8]
%4 = alloca [2048 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
store i8 0, i8* %6
%7 = tail call i32* @popen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = call i32* @fgets(i8* %5, i32 1023, i32* %7)
%11 = icmp eq i32* %10, null
br i1 %11, label %18, label %14
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %26
14: ; preds = %9, %14
%15 = call i32 @strcat(i8* %6, i8* %5)
%16 = call i32* @fgets(i8* %5, i32 1023, i32* %7)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %14
18: ; preds = %14, %9
%19 = call i64 @strlen(i8* %6)
%20 = add nsw i64 %19, 1
%21 = call i64 @malloc(i64 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %1
%23 = call i32 @strcpy(i8* %22, i8* %6)
%24 = call i32 @pclose(i32* %7)
%25 = sdiv i32 %24, 256
br label %26
26: ; preds = %18, %12
%27 = phi i32 [ 1, %12 ], [ %25, %18 ]
ret i32 %27
}