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

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
scalar_t__ popen(char const *, char *);
int /*<<< orphan*/ printf(char *, char const *);
bool exec_cmd_print_output(const char *cmd) {
  FILE *fpipe;
  char line[256];
  if (!(fpipe = (FILE *)popen(cmd, "r"))) {
    perror("Error - popen failed::");
    return false;
  }
  printf("Info - Executing '%s' in CWD\n", cmd);
  while (fgets(line, sizeof(line), fpipe)) {
    printf("%s", line);
  }
  pclose(fpipe);
  return true;
}


x86 assembly (clang, -O0):
<exec_cmd_print_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1195 <exec_cmd_print_output+0x45>
lea    0xe7e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ec <exec_cmd_print_output+0x9c>
mov    -0x10(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11dc <exec_cmd_print_output+0x8c>
lea    -0x120(%rbp),%rsi
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
jmp    11a5 <exec_cmd_print_output+0x55>
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_cmd_print_output>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbx
lea    0xe9a(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     11ea <exec_cmd_print_output+0x9a>
mov    %rax,%r15
lea    0xe9f(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11d0 <exec_cmd_print_output+0x80>
lea    0xe99(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11b0 <exec_cmd_print_output+0x60>
mov    %r15,%rdi
call   1040 <pclose@plt>
mov    $0x1,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe11(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
jmp    11dd <exec_cmd_print_output+0x8d>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"Error - popen failed::\00"
@.str.2 = [30 x i8] c"Info - Executing '%s' in CWD\0A\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @exec_cmd_print_output(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [256 x i8]
store i8* %0, i8** %3
%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** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %26
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %20, %12
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%17 = load i32*, i32** %4
%18 = call i64 @fgets(i8* %16, i32 256, i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%22 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %21)
br label %15
23: ; preds = %15
%24 = load i32*, i32** %4
%25 = call i32 @pclose(i32* %24)
store i32 1, i32* %2
br label %26
26: ; preds = %23, %10
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"Error - popen failed::\00"
@.str.2 = [30 x i8] c"Info - Executing '%s' in CWD\0A\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @exec_cmd_print_output(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @popen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = inttoptr i64 %4 to i32*
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %19
9: ; preds = %1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%11 = call i64 @fgets(i8* %3, i32 256, i32* %5)
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %9, %13
%14 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%15 = call i64 @fgets(i8* %3, i32 256, i32* %5)
%16 = icmp eq i64 %15, 0
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, %17 ], [ 0, %7 ]
ret i32 %20
}