#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char const *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char run_command(const char *cmd, char **message) {
  FILE *fp;
  int status;
  char msg_res[1024];
  fp = popen(cmd, "r");
  if (!fp) {
    return 0;
  }
  *message = (char *)calloc(65536, sizeof(char));
  if (!message)
    return 0;
  while ((fgets(msg_res, 1024, fp) != NULL) && (strlen(*message) < 65000))
    strcat(*message, msg_res);
  status = pclose(fp);
  return (status == -1) ? 0 : 1;
}


x86 assembly (clang, -O0):
<run_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119b <run_command+0x3b>
movb   $0x0,-0x1(%rbp)
jmp    125b <run_command+0xfb>
mov    $0x10000,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x18(%rbp)
jne    11c8 <run_command+0x68>
movb   $0x0,-0x1(%rbp)
jmp    125b <run_command+0xfb>
jmp    11cd <run_command+0x6d>
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x431(%rbp)
je     1211 <run_command+0xb1>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
cmp    $0xfde8,%eax
setl   %al
mov    %al,-0x431(%rbp)
mov    -0x431(%rbp),%al
test   $0x1,%al
jne    1224 <run_command+0xc4>
jmp    123c <run_command+0xdc>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    -0x430(%rbp),%rsi
call   1080 <strcat@plt>
jmp    11cd <run_command+0x6d>
mov    -0x20(%rbp),%rdi
call   1040 <pclose@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0xffffffff,%edx
cmove  %ecx,%eax
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_command>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%rbx
lea    0xe8a(%rip),%rsi
call   1070 <popen@plt>
test   %rax,%rax
je     11ef <run_command+0x8f>
mov    %rax,%r14
mov    $0x10000,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,(%rbx)
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11df <run_command+0x7f>
mov    %rsp,%r15
nopl   (%rax)
mov    (%rbx),%rdi
call   1030 <strlen@plt>
cmp    $0xfde7,%eax
jg     11df <run_command+0x7f>
mov    (%rbx),%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11b0 <run_command+0x50>
mov    %r14,%rdi
call   1040 <pclose@plt>
cmp    $0xffffffff,%eax
setne  %al
jmp    11f1 <run_command+0x91>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define signext i8 @run_command(i8* %0, i8** %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [1024 x i8]
store i8* %0, i8** %4
store i8** %1, i8*** %5
%9 = load i8*, i8** %4
%10 = call i32* @popen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
store i8 0, i8* %3
br label %47
14: ; preds = %2
%15 = call i64 @calloc(i32 65536, i32 1)
%16 = inttoptr i64 %15 to i8*
%17 = load i8**, i8*** %5
store i8* %16, i8** %17
%18 = load i8**, i8*** %5
%19 = icmp ne i8** %18, null
br i1 %19, label %21, label %20
20: ; preds = %14
store i8 0, i8* %3
br label %47
21: ; preds = %14
br label %22
22: ; preds = %34, %21
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%24 = load i32*, i32** %6
%25 = call i32* @fgets(i8* %23, i32 1024, i32* %24)
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i8**, i8*** %5
%29 = load i8*, i8** %28
%30 = call i32 @strlen(i8* %29)
%31 = icmp slt i32 %30, 65000
br label %32
32: ; preds = %27, %22
%33 = phi i1 [ false, %22 ], [ %31, %27 ]
br i1 %33, label %34, label %39
34: ; preds = %32
%35 = load i8**, i8*** %5
%36 = load i8*, i8** %35
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%38 = call i32 @strcat(i8* %36, i8* %37)
br label %22
39: ; preds = %32
%40 = load i32*, i32** %6
%41 = call i32 @pclose(i32* %40)
store i32 %41, i32* %7
%42 = load i32, i32* %7
%43 = icmp eq i32 %42, -1
%44 = zext i1 %43 to i64
%45 = select i1 %43, i32 0, i32 1
%46 = trunc i32 %45 to i8
store i8 %46, i8* %3
br label %47
47: ; preds = %39, %20, %13
%48 = load i8, i8* %3
ret i8 %48
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define signext i8 @run_command(i8* nocapture %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 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 %25, label %7
7: ; preds = %2
%8 = tail call i64 @calloc(i32 65536, i32 1)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %1
%10 = call i32* @fgets(i8* %4, i32 1024, i32* %5)
%11 = icmp eq i32* %10, null
br i1 %11, label %21, label %12
12: ; preds = %7, %16
%13 = load i8*, i8** %1
%14 = call i32 @strlen(i8* %13)
%15 = icmp slt i32 %14, 65000
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i8*, i8** %1
%18 = call i32 @strcat(i8* %17, i8* %4)
%19 = call i32* @fgets(i8* %4, i32 1024, i32* %5)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %12
21: ; preds = %12, %16, %7
%22 = call i32 @pclose(i32* %5)
%23 = icmp ne i32 %22, -1
%24 = zext i1 %23 to i8
br label %25
25: ; preds = %2, %21
%26 = phi i8 [ %24, %21 ], [ 0, %2 ]
ret i8 %26
}