#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*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ print_debug(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
void exec_shell(char *command) {
  FILE *shell_pipe;
  char output_buffer[81];
  char *postfix = " 2>&1";
  char total_command[strlen(command) + strlen(postfix) + 1];
  strcpy(total_command, command);
  strcat(total_command, postfix);
  shell_pipe = popen(total_command, "r");
  if (shell_pipe == NULL) {
    print_debug("exec_shell: process pipe creation failed!");
    exit(1);
  }
  while (fgets(output_buffer, 80, shell_pipe) != NULL) {
    printf("%s", output_buffer);
  }
  pclose(shell_pipe);
}


x86 assembly (clang, -O0):
<exec_shell>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe5a(%rip),%rax
mov    %rax,-0x78(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x98(%rbp)
mov    -0x78(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x98(%rbp),%rcx
mov    %rax,%rdx
lea    0x1(%rcx,%rdx,1),%rax
mov    %rsp,%rsi
mov    %rsi,-0x80(%rbp)
lea    0x10(%rcx,%rdx,1),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x90(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x88(%rbp)
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x90(%rbp),%rdi
mov    -0x78(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x90(%rbp),%rdi
lea    0xde6(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    124a <exec_shell+0xba>
lea    0xdcd(%rip),%rdi
call   10a0 <print_debug@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    124f <exec_shell+0xbf>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x50,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1280 <exec_shell+0xf0>
lea    -0x70(%rbp),%rsi
lea    0xdbc(%rip),%rdi
call   1050 <printf@plt>
jmp    124f <exec_shell+0xbf>
mov    -0x10(%rbp),%rdi
call   1060 <pclose@plt>
mov    -0x80(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_shell>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %rsp,%r12
mov    %rsp,%rbx
add    $0x15,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xe33(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
lea    0xe2a(%rip),%rsi
mov    %rbx,%rdi
call   1080 <popen@plt>
test   %rax,%rax
je     1248 <exec_shell+0xb8>
mov    %rax,%r15
lea    -0x80(%rbp),%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1230 <exec_shell+0xa0>
lea    0xe29(%rip),%r14
lea    -0x80(%rbp),%rbx
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    1210 <exec_shell+0x80>
mov    %r15,%rdi
call   1060 <pclose@plt>
mov    %r12,%rsp
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb9(%rip),%rdi
call   10a0 <print_debug@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c" 2>&1\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [42 x i8] c"exec_shell: process pipe creation failed!\00"
@.str.3 = [3 x i8] c"%s\00"
define void @exec_shell(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [81 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %5
%8 = load i8*, i8** %2
%9 = call i64 @strlen(i8* %8)
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %9, %11
%13 = add nsw i64 %12, 1
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
%16 = load i8*, i8** %2
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = load i8*, i8** %5
%19 = call i32 @strcat(i8* %15, i8* %18)
%20 = call i32* @popen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %3
%21 = load i32*, i32** %3
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %1
%24 = call i32 @print_debug(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %1
br label %27
27: ; preds = %32, %26
%28 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%29 = load i32*, i32** %3
%30 = call i32* @fgets(i8* %28, i32 80, i32* %29)
%31 = icmp ne i32* %30, null
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%34 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %33)
br label %27
35: ; preds = %27
%36 = load i32*, i32** %3
%37 = call i32 @pclose(i32* %36)
%38 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c" 2>&1\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [42 x i8] c"exec_shell: process pipe creation failed!\00"
@.str.3 = [3 x i8] c"%s\00"
define void @exec_shell(i8* %0) {
%2 = alloca [81 x i8]
%3 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add nsw i64 %4, 6
%6 = tail call i8* @llvm.stacksave()
%7 = alloca i8, i64 %5
%8 = call i32 @strcpy(i8* %7, i8* %0)
%9 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = call i32* @popen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = call i32* @fgets(i8* %3, i32 80, i32* %10)
%14 = icmp eq i32* %13, null
br i1 %14, label %22, label %18
15: ; preds = %1
%16 = call i32 @print_debug(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %12, %18
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%20 = call i32* @fgets(i8* %3, i32 80, i32* %10)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %18
22: ; preds = %18, %12
%23 = call i32 @pclose(i32* %10)
ret void
}