#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
char *strchr(char *, char);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int ExecProg(char *line) {
  char command[256];
  char *chpos;
  FILE *fp;
  char buf[4096];
  if (strncmp(line, "<!--#exec=\"", 11) != 0)
    return 0;
  if ((chpos = strchr(line + 11, '"')) == NULL)
    return 0;
  strncpy(command, line + 11, chpos - (line + 11));
  command[chpos - line - 11] = '\0';
  if ((fp = popen(command, "r")) != NULL) {
    while (fgets(buf, 4096, fp) != NULL) {
      if (strncmp(buf, "Content-type: ", 14) == 0)
        continue;
      (void)printf("%s", buf);
    }
  } else
    return 0;
  pclose(fp);
  return 1;
}


x86 assembly (clang, -O0):
<ExecProg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1120,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe76(%rip),%rsi
mov    $0xb,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     11aa <ExecProg+0x3a>
movl   $0x0,-0x4(%rbp)
jmp    12c9 <ExecProg+0x159>
mov    -0x10(%rbp),%rdi
add    $0xb,%rdi
mov    $0x22,%esi
call   1050 <strchr@plt>
mov    %rax,-0x118(%rbp)
cmp    $0x0,%rax
jne    11d9 <ExecProg+0x69>
movl   $0x0,-0x4(%rbp)
jmp    12c9 <ExecProg+0x159>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0xb,%rsi
mov    -0x118(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    $0xb,%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x118(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
sub    $0xb,%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
lea    0xde3(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x120(%rbp)
cmp    $0x0,%rax
je     12aa <ExecProg+0x13a>
jmp    1244 <ExecProg+0xd4>
lea    -0x1120(%rbp),%rdi
mov    -0x120(%rbp),%rdx
mov    $0x1000,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     12a5 <ExecProg+0x135>
lea    -0x1120(%rbp),%rdi
lea    0xd9a(%rip),%rsi
mov    $0xe,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    128d <ExecProg+0x11d>
jmp    1244 <ExecProg+0xd4>
lea    -0x1120(%rbp),%rsi
lea    0xd82(%rip),%rdi
call   1060 <printf@plt>
jmp    1244 <ExecProg+0xd4>
jmp    12b6 <ExecProg+0x146>
movl   $0x0,-0x4(%rbp)
jmp    12c9 <ExecProg+0x159>
mov    -0x120(%rbp),%rdi
call   1070 <pclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ExecProg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1100,%rsp
mov    %rdi,%rbx
lea    0xe77(%rip),%rsi
mov    $0xb,%edx
call   1040 <strncmp@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     11ae <ExecProg+0x3e>
mov    %r15d,%eax
add    $0x1100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb(%rbx),%r14
mov    %r14,%rdi
mov    $0x22,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     119b <ExecProg+0x2b>
mov    %rax,%rbp
mov    %ebp,%edx
sub    %r14d,%edx
mov    %rsp,%r12
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <strncpy@plt>
sub    %rbx,%rbp
movb   $0x0,-0xb(%rbp,%r12,1)
lea    0xe22(%rip),%rsi
mov    %r12,%rdi
call   1090 <popen@plt>
test   %rax,%rax
je     119b <ExecProg+0x2b>
mov    %rax,%rbx
lea    0x100(%rsp),%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1267 <ExecProg+0xf7>
lea    0xdf3(%rip),%r14
lea    0x100(%rsp),%rbp
lea    0xdf3(%rip),%r15
jmp    1245 <ExecProg+0xd5>
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1267 <ExecProg+0xf7>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    $0xe,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1230 <ExecProg+0xc0>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1060 <printf@plt>
jmp    1230 <ExecProg+0xc0>
mov    %rbx,%rdi
call   1070 <pclose@plt>
mov    $0x1,%r15d
jmp    119b <ExecProg+0x2b>

LLVM IR (-O0):
@.str = [12 x i8] c"<!--#exec=\22\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"Content-type: \00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @ExecProg(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [256 x i8]
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [4096 x i8]
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %59
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 11
%15 = call i8* @strchr(i8* %14, i8 signext 34)
store i8* %15, i8** %5
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 0, i32* %2
br label %59
18: ; preds = %12
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 11
%22 = load i8*, i8** %5
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 11
%25 = ptrtoint i8* %22 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
%29 = call i32 @strncpy(i8* %19, i8* %21, i32 %28)
%30 = load i8*, i8** %5
%31 = load i8*, i8** %3
%32 = ptrtoint i8* %30 to i64
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %32, %33
%35 = sub nsw i64 %34, 11
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %35
store i8 0, i8* %36
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%38 = call i32* @popen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %38, i32** %6
%39 = icmp ne i32* %38, null
br i1 %39, label %40, label %55
40: ; preds = %18
br label %41
41: ; preds = %51, %50, %40
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%43 = load i32*, i32** %6
%44 = call i32* @fgets(i8* %42, i32 4096, i32* %43)
%45 = icmp ne i32* %44, null
br i1 %45, label %46, label %54
46: ; preds = %41
%47 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%48 = call i64 @strncmp(i8* %47, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 14)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %46
br label %41
51: ; preds = %46
%52 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%53 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %52)
br label %41
54: ; preds = %41
br label %56
55: ; preds = %18
store i32 0, i32* %2
br label %59
56: ; preds = %54
%57 = load i32*, i32** %6
%58 = call i32 @pclose(i32* %57)
store i32 1, i32* %2
br label %59
59: ; preds = %56, %55, %17, %11
%60 = load i32, i32* %2
ret i32 %60
}

LLVM IR (-O2):
@.str = [12 x i8] c"<!--#exec=\22\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"Content-type: \00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @ExecProg(i8* %0) {
%2 = alloca [256 x i8]
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%6 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %37
8: ; preds = %1
%9 = getelementptr inbounds i8, i8* %0, i64 11
%10 = tail call i8* @strchr(i8* %9, i8 signext 34)
%11 = icmp eq i8* %10, null
br i1 %11, label %37, label %12
12: ; preds = %8
%13 = ptrtoint i8* %10 to i64
%14 = ptrtoint i8* %9 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
%17 = call i32 @strncpy(i8* %4, i8* %9, i32 %16)
%18 = ptrtoint i8* %0 to i64
%19 = sub i64 -11, %18
%20 = add i64 %19, %13
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i32* @popen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %37, label %24
24: ; preds = %12
%25 = call i32* @fgets(i8* %5, i32 4096, i32* %22)
%26 = icmp eq i32* %25, null
br i1 %26, label %35, label %27
27: ; preds = %24, %32
%28 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 14)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %5)
br label %32
32: ; preds = %30, %27
%33 = call i32* @fgets(i8* %5, i32 4096, i32* %22)
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %27
35: ; preds = %32, %24
%36 = call i32 @pclose(i32* %22)
br label %37
37: ; preds = %12, %8, %1, %35
%38 = phi i32 [ 1, %35 ], [ 0, %1 ], [ 0, %8 ], [ 0, %12 ]
ret i32 %38
}