#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__ EOF;
int /*<<< orphan*/ exit(int);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
scalar_t__ popen(char *, char *);
void exec_command(char *command, char *reply) {
  FILE *fpipe;
  if (0 == (fpipe = (FILE *)popen(command, "r"))) {
    perror("popen() failed.");
    exit(1);
  }
  while (fscanf(fpipe, "%s", reply) != EOF) {
  }
  pclose(fpipe);
}


x86 assembly (clang, -O0):
<exec_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    1198 <exec_command+0x48>
lea    0xe79(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    119d <exec_command+0x4d>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe66(%rip),%rsi
call   1040 <fscanf@plt>
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%rax
je     11c6 <exec_command+0x76>
jmp    119d <exec_command+0x4d>
mov    -0x18(%rbp),%rdi
call   1030 <pclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_command>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xe9e(%rip),%rsi
call   1050 <popen@plt>
test   %rax,%rax
je     11a7 <exec_command+0x57>
mov    %rax,%rbx
lea    0xe9c(%rip),%r15
mov    0x2e6b(%rip),%r12
nopl   (%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <fscanf@plt>
cmp    (%r12),%rax
jne    1180 <exec_command+0x30>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <pclose@plt>
lea    0xe54(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [16 x i8] c"popen() failed.\00"
@.str.2 = [3 x i8] c"%s\00"
@EOF = global i64 0
define void @exec_command(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 i64 @popen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = inttoptr i64 %7 to i32*
store i32* %8, i32** %5
%9 = icmp eq i32* null, %8
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
br label %14
14: ; preds = %20, %13
%15 = load i32*, i32** %5
%16 = load i8*, i8** %4
%17 = call i64 @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i64, i64* @EOF
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %14
br label %14
21: ; preds = %14
%22 = load i32*, i32** %5
%23 = call i32 @pclose(i32* %22)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [16 x i8] c"popen() failed.\00"
@.str.2 = [3 x i8] c"%s\00"
@EOF = global i64 0
define void @exec_command(i8* %0, i8* %1) {
%3 = tail call i64 @popen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = inttoptr i64 %3 to i32*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2, %9
%10 = tail call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%11 = load i64, i64* @EOF
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %9
13: ; preds = %9
%14 = tail call i32 @pclose(i32* %4)
ret void
}