#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char const *, char *);
int /*<<< orphan*/ removeNewLine(char *);
void runCommand(const char *command, char *result) {
  FILE *pipe;
  pipe = popen(command, "r");
  if (pipe == NULL) {
    result[0] = '\0';
  } else {
    if (NULL == fgets(result, 1024, pipe)) {
      result[0] = '\0';
    }
    pclose(pipe);
  }
  removeNewLine(result);
}


x86 assembly (clang, -O0):
<runCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117b <runCommand+0x3b>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    11ab <runCommand+0x6b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11a2 <runCommand+0x62>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <pclose@plt>
mov    -0x10(%rbp),%rdi
call   1050 <removeNewLine@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runCommand>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xeb2(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     117e <runCommand+0x3e>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1174 <runCommand+0x34>
movb   $0x0,(%r14)
mov    %rbx,%rdi
call   1030 <pclose@plt>
jmp    1182 <runCommand+0x42>
movb   $0x0,(%r14)
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <removeNewLine@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define void @runCommand(i8* nocapture %0, i8* %1) {
%3 = tail call i32* @popen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %6
5: ; preds = %2
store i8 0, i8* %1
br label %12
6: ; preds = %2
%7 = tail call i32* @fgets(i8* %1, i32 1024, i32* %3)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %6
store i8 0, i8* %1
br label %10
10: ; preds = %9, %6
%11 = tail call i32 @pclose(i32* %3)
br label %12
12: ; preds = %10, %5
%13 = tail call i32 @removeNewLine(i8* %1)
ret void
}