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

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int run_command(char *command, char *result) {
  FILE *fstream = NULL;
  char buff[81];
  if ((fstream = popen(command, "r")) == NULL) {
    perror("execute command failed : ");
    return -1;
  }
  memset(buff, 0, sizeof(buff));
  while (fgets(buff, sizeof(buff), fstream) != NULL) {
    strcat(result, buff);
  }
  pclose(fstream);
  return 0;
}


x86 assembly (clang, -O0):
<run_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11b1 <run_command+0x51>
lea    0xe62(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <run_command+0x9f>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x51,%edx
call   1040 <memset@plt>
lea    -0x80(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x51,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11ef <run_command+0x8f>
mov    -0x18(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1080 <strcat@plt>
jmp    11c1 <run_command+0x61>
mov    -0x20(%rbp),%rdi
call   1030 <pclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_command>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r15
lea    0xe8c(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     11e6 <run_command+0x86>
mov    %rax,%rbp
mov    %rsp,%rbx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x51,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    $0x51,%esi
mov    %rbp,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11d0 <run_command+0x70>
mov    %rsp,%rbx
xchg   %ax,%ax
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rdi
mov    $0x51,%esi
mov    %rbp,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11b0 <run_command+0x50>
mov    %rbp,%rdi
call   1030 <pclose@plt>
mov    %r14d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe15(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%r14d
jmp    11d8 <run_command+0x78>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"execute command failed : \00"
define i32 @run_command(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [81 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* null, i32** %6
%8 = load i8*, i8** %4
%9 = call i32* @popen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %28
13: ; preds = %2
%14 = getelementptr inbounds [81 x i8], [81 x i8]* %7, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 81)
br label %16
16: ; preds = %21, %13
%17 = getelementptr inbounds [81 x i8], [81 x i8]* %7, i64 0, i64 0
%18 = load i32*, i32** %6
%19 = call i32* @fgets(i8* %17, i32 81, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = getelementptr inbounds [81 x i8], [81 x i8]* %7, i64 0, i64 0
%24 = call i32 @strcat(i8* %22, i8* %23)
br label %16
25: ; preds = %16
%26 = load i32*, i32** %6
%27 = call i32 @pclose(i32* %26)
store i32 0, i32* %3
br label %28
28: ; preds = %25, %11
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"execute command failed : \00"
define i32 @run_command(i8* nocapture %0, i8* %1) {
%3 = alloca [81 x i8]
%4 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @popen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %19
9: ; preds = %2
%10 = call i32 @memset(i8* %4, i32 0, i32 81)
%11 = call i32* @fgets(i8* %4, i32 81, i32* %5)
%12 = icmp eq i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %9, %13
%14 = call i32 @strcat(i8* %1, i8* %4)
%15 = call i32* @fgets(i8* %4, i32 81, i32* %5)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %13
17: ; preds = %13, %9
%18 = call i32 @pclose(i32* %5)
br label %19
19: ; preds = %17, %7
%20 = phi i32 [ -1, %7 ], [ 0, %17 ]
ret i32 %20
}