#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *stderr;
char *strdup(char *);
void execute_cmd(char *cmd, char *name, int enlog, FILE *logfp) {
  char *stdout_d[4096];
  int stdout_n = 0;
  char stdout_b[1024];
  int i;
  int child_ret = -2017;
  if (enlog)
    fprintf(logfp, "%s Stage\nCommand line : %s\n>>>>BEGIN\n", name, cmd);
  FILE *fp = popen(cmd, "r");
  while (fp && fgets(stdout_b, 1024, fp)) {
    stdout_d[stdout_n] = strdup(stdout_b);
    if (enlog)
      fputs(stdout_d[stdout_n], logfp);
    stdout_n++;
  }
  if (!fp || (child_ret = pclose(fp)) != 0) {
    if (child_ret != -2017)
      fprintf(stderr, "%s Returned %d\n", name, child_ret);
    else
      fprintf(stderr, "%s execute failed\n", name);
    fprintf(stderr, "%s execute stage failed.\n", name);
    fprintf(stderr, "stdout :\n");
    for (i = 0; i < stdout_n; i++)
      printf(stdout_d[i]);
    if (enlog) {
      fprintf(logfp, "%s Returned %d\n", name, child_ret);
      fprintf(logfp, ">>>>END(FAILED)\n\n");
      fclose(logfp);
    }
    exit(-1);
  }
  if (enlog)
    fprintf(logfp, ">>>>END\n\n");
}


x86 assembly (clang, -O0):
<execute_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8450,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x8024(%rbp)
movl   $0xfffff81f,-0x8438(%rbp)
f8 ff ff
cmpl   $0x0,-0x14(%rbp)
je     11e2 <execute_cmd+0x52>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe25(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x8440(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8440(%rbp)
mov    %al,-0x8441(%rbp)
je     1234 <execute_cmd+0xa4>
lea    -0x8430(%rbp),%rdi
mov    -0x8440(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x8441(%rbp)
mov    -0x8441(%rbp),%al
test   $0x1,%al
jne    1247 <execute_cmd+0xb7>
jmp    129b <execute_cmd+0x10b>
lea    -0x8430(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,%rcx
movslq -0x8024(%rbp),%rax
mov    %rcx,-0x8020(%rbp,%rax,8)
ff
cmpl   $0x0,-0x14(%rbp)
je     1287 <execute_cmd+0xf7>
movslq -0x8024(%rbp),%rax
mov    -0x8020(%rbp,%rax,8),%rdi
ff
mov    -0x20(%rbp),%rsi
call   1060 <fputs@plt>
mov    -0x8024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8024(%rbp)
jmp    11f9 <execute_cmd+0x69>
cmpq   $0x0,-0x8440(%rbp)
je     12c4 <execute_cmd+0x134>
mov    -0x8440(%rbp),%rdi
call   1050 <pclose@plt>
mov    %eax,-0x8438(%rbp)
cmp    $0x0,%eax
je     13da <execute_cmd+0x24a>
cmpl   $0xfffff81f,-0x8438(%rbp)
f8 ff ff
je     12fb <execute_cmd+0x16b>
mov    0x2d05(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8438(%rbp),%ecx
lea    0xd39(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1317 <execute_cmd+0x187>
mov    0x2cde(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd28(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2cc2(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd1f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2ca6(%rip),%rax
mov    (%rax),%rdi
lea    0xd21(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x8434(%rbp)
mov    -0x8434(%rbp),%eax
cmp    -0x8024(%rbp),%eax
jge    138f <execute_cmd+0x1ff>
movslq -0x8434(%rbp),%rax
mov    -0x8020(%rbp,%rax,8),%rdi
ff
call   1040 <printf@plt>
mov    -0x8434(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8434(%rbp)
jmp    1355 <execute_cmd+0x1c5>
cmpl   $0x0,-0x14(%rbp)
je     13d0 <execute_cmd+0x240>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8438(%rbp),%ecx
lea    0xc7a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xcaf(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
je     13f6 <execute_cmd+0x266>
mov    -0x20(%rbp),%rdi
lea    0xc92(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
add    $0x8450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute_cmd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8418,%rsp
mov    %rcx,%r12
mov    %edx,%r13d
mov    %rsi,%rbp
mov    %rdi,%rbx
test   %edx,%edx
je     11d8 <execute_cmd+0x38>
lea    0xe38(%rip),%rsi
mov    %r12,%rdi
mov    %rbp,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xe47(%rip),%rsi
mov    %rbx,%rdi
call   1090 <popen@plt>
test   %rax,%rax
mov    %rbp,0x8(%rsp)
je     12c3 <execute_cmd+0x123>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     125b <execute_cmd+0xbb>
lea    0x10(%rsp),%rbp
jmp    1239 <execute_cmd+0x99>
nopl   0x0(%rax)
add    $0x1,%r14
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     125b <execute_cmd+0xbb>
mov    %rbp,%rdi
call   10c0 <strdup@plt>
mov    %rax,0x410(%rsp,%r14,8)
test   %r13d,%r13d
je     1220 <execute_cmd+0x80>
mov    %rax,%rdi
mov    %r12,%rsi
call   1060 <fputs@plt>
jmp    1220 <execute_cmd+0x80>
mov    %rbx,%rdi
call   1050 <pclose@plt>
test   %eax,%eax
jne    1297 <execute_cmd+0xf7>
test   %r13d,%r13d
je     1285 <execute_cmd+0xe5>
lea    0xe0e(%rip),%rdi
mov    $0x9,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   10b0 <fwrite@plt>
add    $0x8418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r15d
cmp    $0xfffff81f,%eax
je     12c6 <execute_cmd+0x126>
mov    0x2d38(%rip),%rax
mov    (%rax),%rdi
lea    0xd76(%rip),%rsi
mov    0x8(%rsp),%rdx
mov    %r15d,%ecx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    12e9 <execute_cmd+0x149>
xor    %r14d,%r14d
mov    0x2d13(%rip),%rax
mov    (%rax),%rdi
lea    0xd61(%rip),%rsi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xfffff81f,%r15d
mov    0x2cf0(%rip),%rbx
mov    (%rbx),%rdi
lea    0xd51(%rip),%rsi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%rbx),%rcx
lea    0xd55(%rip),%rdi
mov    $0x9,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
test   %r14d,%r14d
je     1346 <execute_cmd+0x1a6>
mov    %r14d,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    0x410(%rsp,%rbp,8),%rdi
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1330 <execute_cmd+0x190>
test   %r13d,%r13d
je     1385 <execute_cmd+0x1e5>
lea    0xcd6(%rip),%rsi
mov    %r12,%rdi
mov    0x8(%rsp),%rdx
mov    %r15d,%ecx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xd04(%rip),%rdi
mov    $0x11,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   10b0 <fwrite@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"%s Stage\0ACommand line : %s\0A>>>>BEGIN\0A\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32* null
@.str.2 = [16 x i8] c"%s Returned %d\0A\00"
@.str.3 = [19 x i8] c"%s execute failed\0A\00"
@.str.4 = [26 x i8] c"%s execute stage failed.\0A\00"
@.str.5 = [10 x i8] c"stdout :\0A\00"
@.str.6 = [18 x i8] c">>>>END(FAILED)\0A\0A\00"
@.str.7 = [10 x i8] c">>>>END\0A\0A\00"
define void @execute_cmd(i8* %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca [4096 x i8*]
%10 = alloca i32
%11 = alloca [1024 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32* %3, i32** %8
store i32 0, i32* %10
store i32 -2017, i32* %13
%15 = load i32, i32* %7
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %4
%18 = load i32*, i32** %8
%19 = load i8*, i8** %6
%20 = load i8*, i8** %5
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %19, i8* %20)
br label %22
22: ; preds = %17, %4
%23 = load i8*, i8** %5
%24 = call i32* @popen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %14
br label %25
25: ; preds = %50, %22
%26 = load i32*, i32** %14
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%30 = load i32*, i32** %14
%31 = call i64 @fgets(i8* %29, i32 1024, i32* %30)
%32 = icmp ne i64 %31, 0
br label %33
33: ; preds = %28, %25
%34 = phi i1 [ false, %25 ], [ %32, %28 ]
br i1 %34, label %35, label %53
35: ; preds = %33
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%37 = call i8* @strdup(i8* %36)
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [4096 x i8*], [4096 x i8*]* %9, i64 0, i64 %39
store i8* %37, i8** %40
%41 = load i32, i32* %7
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %35
%44 = load i32, i32* %10
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [4096 x i8*], [4096 x i8*]* %9, i64 0, i64 %45
%47 = load i8*, i8** %46
%48 = load i32*, i32** %8
%49 = call i32 @fputs(i8* %47, i32* %48)
br label %50
50: ; preds = %43, %35
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
store i32 %52, i32* %10
br label %25
53: ; preds = %33
%54 = load i32*, i32** %14
%55 = icmp ne i32* %54, null
br i1 %55, label %56, label %60
56: ; preds = %53
%57 = load i32*, i32** %14
%58 = call i32 @pclose(i32* %57)
store i32 %58, i32* %13
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %105
60: ; preds = %56, %53
%61 = load i32, i32* %13
%62 = icmp ne i32 %61, -2017
br i1 %62, label %63, label %68
63: ; preds = %60
%64 = load i32*, i32** @stderr
%65 = load i8*, i8** %6
%66 = load i32, i32* %13
%67 = call i32 (i32*, i8*, ...) @fprintf(i32* %64, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %65, i32 %66)
br label %72
68: ; preds = %60
%69 = load i32*, i32** @stderr
%70 = load i8*, i8** %6
%71 = call i32 (i32*, i8*, ...) @fprintf(i32* %69, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %68, %63
%73 = load i32*, i32** @stderr
%74 = load i8*, i8** %6
%75 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %74)
%76 = load i32*, i32** @stderr
%77 = call i32 (i32*, i8*, ...) @fprintf(i32* %76, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %12
br label %78
78: ; preds = %88, %72
%79 = load i32, i32* %12
%80 = load i32, i32* %10
%81 = icmp slt i32 %79, %80
br i1 %81, label %82, label %91
82: ; preds = %78
%83 = load i32, i32* %12
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [4096 x i8*], [4096 x i8*]* %9, i64 0, i64 %84
%86 = load i8*, i8** %85
%87 = call i32 @printf(i8* %86)
br label %88
88: ; preds = %82
%89 = load i32, i32* %12
%90 = add nsw i32 %89, 1
store i32 %90, i32* %12
br label %78
91: ; preds = %78
%92 = load i32, i32* %7
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %103
94: ; preds = %91
%95 = load i32*, i32** %8
%96 = load i8*, i8** %6
%97 = load i32, i32* %13
%98 = call i32 (i32*, i8*, ...) @fprintf(i32* %95, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %96, i32 %97)
%99 = load i32*, i32** %8
%100 = call i32 (i32*, i8*, ...) @fprintf(i32* %99, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%101 = load i32*, i32** %8
%102 = call i32 @fclose(i32* %101)
br label %103
103: ; preds = %94, %91
%104 = call i32 @exit(i32 -1)
unreachable
105: ; preds = %56
%106 = load i32, i32* %7
%107 = icmp ne i32 %106, 0
br i1 %107, label %108, label %111
108: ; preds = %105
%109 = load i32*, i32** %8
%110 = call i32 (i32*, i8*, ...) @fprintf(i32* %109, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
br label %111
111: ; preds = %108, %105
ret void
}

LLVM IR (-O2):
@.str = [38 x i8] c"%s Stage\0ACommand line : %s\0A>>>>BEGIN\0A\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32* null
@.str.2 = [16 x i8] c"%s Returned %d\0A\00"
@.str.3 = [19 x i8] c"%s execute failed\0A\00"
@.str.4 = [26 x i8] c"%s execute stage failed.\0A\00"
@.str.5 = [10 x i8] c"stdout :\0A\00"
@.str.6 = [18 x i8] c">>>>END(FAILED)\0A\0A\00"
@.str.7 = [10 x i8] c">>>>END\0A\0A\00"
define void @execute_cmd(i8* %0, i8* %1, i32 %2, i32* nocapture %3) {
%5 = alloca [4096 x i8*]
%6 = alloca [1024 x i8]
%7 = bitcast [4096 x i8*]* %5 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%9 = icmp eq i32 %2, 0
br i1 %9, label %12, label %10
10: ; preds = %4
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %0)
br label %12
12: ; preds = %10, %4
%13 = tail call i32* @popen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %36, label %15
15: ; preds = %12
%16 = call i64 @fgets(i8* %8, i32 1024, i32* %13)
%17 = icmp eq i64 %16, 0
br i1 %17, label %30, label %18
18: ; preds = %15, %24
%19 = phi i64 [ %25, %24 ], [ 0, %15 ]
%20 = call i8* @strdup(i8* %8)
%21 = getelementptr inbounds [4096 x i8*], [4096 x i8*]* %5, i64 0, i64 %19
store i8* %20, i8** %21
br i1 %9, label %24, label %22
22: ; preds = %18
%23 = call i32 @fputs(i8* %20, i32* %3)
br label %24
24: ; preds = %22, %18
%25 = add nuw i64 %19, 1
%26 = call i64 @fgets(i8* %8, i32 1024, i32* %13)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %18
28: ; preds = %24
%29 = trunc i64 %25 to i32
br label %30
30: ; preds = %28, %15
%31 = phi i32 [ %29, %28 ], [ 0, %15 ]
%32 = call i32 @pclose(i32* %13)
switch i32 %32, label %33 [
i32 0, label %64
i32 -2017, label %36
]
33: ; preds = %30
%34 = load i32*, i32** @stderr
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %1, i32 %32)
br label %40
36: ; preds = %12, %30
%37 = phi i32 [ %31, %30 ], [ 0, %12 ]
%38 = load i32*, i32** @stderr
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %40
40: ; preds = %36, %33
%41 = phi i32 [ %37, %36 ], [ %31, %33 ]
%42 = phi i32 [ -2017, %36 ], [ %32, %33 ]
%43 = load i32*, i32** @stderr
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%45 = load i32*, i32** @stderr
%46 = call i64 @fwrite(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i64 9, i64 1, i32* %45)
%47 = icmp eq i32 %41, 0
br i1 %47, label %57, label %48
48: ; preds = %40
%49 = zext i32 %41 to i64
br label %50
50: ; preds = %48, %50
%51 = phi i64 [ 0, %48 ], [ %55, %50 ]
%52 = getelementptr inbounds [4096 x i8*], [4096 x i8*]* %5, i64 0, i64 %51
%53 = load i8*, i8** %52
%54 = call i32 @printf(i8* dereferenceable(1) %53)
%55 = add nuw nsw i64 %51, 1
%56 = icmp eq i64 %55, %49
br i1 %56, label %57, label %50
57: ; preds = %50, %40
br i1 %9, label %62, label %58
58: ; preds = %57
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %1, i32 %42)
%60 = call i64 @fwrite(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i64 17, i64 1, i32* %3)
%61 = call i32 @fclose(i32* %3)
br label %62
62: ; preds = %58, %57
%63 = call i32 @exit(i32 -1)
unreachable
64: ; preds = %30
br i1 %9, label %67, label %65
65: ; preds = %64
%66 = call i64 @fwrite(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i64 9, i64 1, i32* %3)
br label %67
67: ; preds = %65, %64
ret void
}