#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*/ OM_Printf(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
void NW_ShellExc(char *cmd) {
  FILE *fp = NULL;
  int lRet = 0;
  char buf[(1011)] = {0};
  fp = popen(cmd, "r");
  if (NULL != fp) {
    while ((lRet = fread(buf, (1), (1011) - 1, fp)) != 0) {
      buf[lRet + 1] = '\0';
      OM_Printf("%s", buf);
    };
    pclose(fp);
  }
}


x86 assembly (clang, -O0):
<NW_ShellExc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x3f3,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     11fd <NW_ShellExc+0xad>
jmp    11a6 <NW_ShellExc+0x56>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3f2,%edx
call   1030 <fread@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     11f4 <NW_ShellExc+0xa4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rsi
lea    0xe18(%rip),%rdi
call   1060 <OM_Printf@plt>
jmp    11a6 <NW_ShellExc+0x56>
mov    -0x10(%rbp),%rdi
call   1040 <pclose@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NW_ShellExc>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x3f3,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1070 <popen@plt>
test   %rax,%rax
je     11e3 <NW_ShellExc+0x93>
mov    %rax,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x3f2,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %eax,%eax
je     11db <NW_ShellExc+0x8b>
lea    0xe5a(%rip),%r15
nopl   0x0(%rax,%rax,1)
cltq
movb   $0x0,0x1(%rax,%rbx,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <OM_Printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x3f2,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jne    11b0 <NW_ShellExc+0x60>
mov    %r14,%rdi
call   1040 <pclose@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
define void @NW_ShellExc(i8* nocapture %0) {
%2 = alloca [1011 x i8]
%3 = getelementptr inbounds [1011 x i8], [1011 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @popen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %19, label %6
6: ; preds = %1
%7 = call i32 @fread(i8* %3, i32 1, i32 1010, i32* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %6, %9
%10 = phi i32 [ %15, %9 ], [ %7, %6 ]
%11 = add nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [1011 x i8], [1011 x i8]* %2, i64 0, i64 %12
store i8 0, i8* %13
%14 = call i32 @OM_Printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%15 = call i32 @fread(i8* %3, i32 1, i32 1010, i32* %4)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %9
17: ; preds = %9, %6
%18 = call i32 @pclose(i32* %4)
br label %19
19: ; preds = %17, %1
ret void
}