#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*/ GetParsedBuf(char *, char **);
int /*<<< orphan*/ GetProgArgv(char *, char *, char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strlen(char *);
void IncludeCGI(char *szCmd, FILE *ofp) {
  char *p, *a, *qs = NULL;
  char *prog, *argv;
  char szLine[1024];
  FILE *fp;
  prog = (char *)malloc(strlen(szCmd) + 1);
  if (prog == NULL)
    return;
  argv = (char *)malloc(strlen(szCmd) + 1);
  if (argv == NULL) {
    free(prog);
    return;
  }
  GetProgArgv(szCmd, prog, argv);
  if (prog[0] == '\0') {
    free(prog);
    free(argv);
    return;
  }
  GetParsedBuf(prog, &p);
  if (argv[0]) {
    GetParsedBuf(argv, &a);
    qs = (char *)malloc(strlen(a) + 20);
    sprintf(qs, "QUERY_STRING=%s", a);
    putenv(qs);
  } else {
    putenv("QUERY_STRING=");
  }
  putenv("REQUEST_METHOD=GET");
  fp = popen(p, "r");
  if (fp) {
    while (fgets(szLine, 1023, fp)) {
      if (ofp) {
        fputs(szLine, ofp);
      } else {
        puts(szLine);
      }
    }
    pclose(fp);
  }
  free(p);
  if (argv[0]) {
    free(a);
    free(qs);
  }
  free(prog);
  free(argv);
}


x86 assembly (clang, -O0):
<IncludeCGI>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1204 <IncludeCGI+0x44>
jmp    13ab <IncludeCGI+0x1eb>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1236 <IncludeCGI+0x76>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    13ab <IncludeCGI+0x1eb>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   10e0 <GetProgArgv@plt>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    126e <IncludeCGI+0xae>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    13ab <IncludeCGI+0x1eb>
mov    -0x30(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   10c0 <GetParsedBuf@plt>
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     12d0 <IncludeCGI+0x110>
mov    -0x38(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10c0 <GetParsedBuf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x14,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd43(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1090 <putenv@plt>
jmp    12dc <IncludeCGI+0x11c>
lea    0xd39(%rip),%rdi
call   1090 <putenv@plt>
lea    0xd3b(%rip),%rdi
call   1090 <putenv@plt>
mov    -0x18(%rbp),%rdi
lea    0xd3e(%rip),%rsi
call   10b0 <popen@plt>
mov    %rax,-0x448(%rbp)
cmpq   $0x0,-0x448(%rbp)
je     1371 <IncludeCGI+0x1b1>
jmp    1312 <IncludeCGI+0x152>
lea    -0x440(%rbp),%rdi
mov    -0x448(%rbp),%rdx
mov    $0x3ff,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1365 <IncludeCGI+0x1a5>
cmpq   $0x0,-0x10(%rbp)
je     1354 <IncludeCGI+0x194>
lea    -0x440(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <fputs@plt>
jmp    1360 <IncludeCGI+0x1a0>
lea    -0x440(%rbp),%rdi
call   1040 <puts@plt>
jmp    1312 <IncludeCGI+0x152>
mov    -0x448(%rbp),%rdi
call   1060 <pclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     1399 <IncludeCGI+0x1d9>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IncludeCGI>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%r13
mov    %rdi,%rbx
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   10a0 <malloc@plt>
test   %rax,%rax
je     1355 <IncludeCGI+0x195>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   10a0 <malloc@plt>
test   %rax,%rax
je     1269 <IncludeCGI+0xa9>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   10e0 <GetProgArgv@plt>
cmpb   $0x0,(%r15)
je     126e <IncludeCGI+0xae>
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
call   10c0 <GetParsedBuf@plt>
cmpb   $0x0,(%r14)
je     128f <IncludeCGI+0xcf>
mov    %rsp,%rsi
mov    %r14,%rdi
call   10c0 <GetParsedBuf@plt>
mov    (%rsp),%rdi
call   1050 <strlen@plt>
lea    0x14(%rax),%rdi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    (%rsp),%rdx
lea    0xda4(%rip),%rsi
mov    %rax,%rdi
call   10d0 <sprintf@plt>
mov    %rbx,%r12
jmp    1299 <IncludeCGI+0xd9>
mov    %r15,%rdi
jmp    1279 <IncludeCGI+0xb9>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
lea    0xd7a(%rip),%rbx
xor    %r12d,%r12d
mov    %rbx,%rdi
call   1090 <putenv@plt>
lea    0xd76(%rip),%rdi
call   1090 <putenv@plt>
mov    0x8(%rsp),%rdi
lea    0xd78(%rip),%rsi
call   10b0 <popen@plt>
test   %rax,%rax
je     1324 <IncludeCGI+0x164>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x3ff,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     131c <IncludeCGI+0x15c>
lea    0x10(%rsp),%rbp
jmp    130a <IncludeCGI+0x14a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1040 <puts@plt>
mov    %rbp,%rdi
mov    $0x3ff,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     131c <IncludeCGI+0x15c>
mov    %rbp,%rdi
test   %r13,%r13
je     12f0 <IncludeCGI+0x130>
mov    %r13,%rsi
call   1070 <fputs@plt>
jmp    12f5 <IncludeCGI+0x135>
mov    %rbx,%rdi
call   1060 <pclose@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
cmpb   $0x0,(%r14)
je     1345 <IncludeCGI+0x185>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"QUERY_STRING=%s\00"
@.str.1 = [14 x i8] c"QUERY_STRING=\00"
@.str.2 = [19 x i8] c"REQUEST_METHOD=GET\00"
@.str.3 = [2 x i8] c"r\00"
define void @IncludeCGI(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [1024 x i8]
%11 = alloca i32*
store i8* %0, i8** %3
store i32* %1, i32** %4
store i8* null, i8** %7
%12 = load i8*, i8** %3
%13 = call i64 @strlen(i8* %12)
%14 = add nsw i64 %13, 1
%15 = call i64 @malloc(i64 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %2
br label %111
20: ; preds = %2
%21 = load i8*, i8** %3
%22 = call i64 @strlen(i8* %21)
%23 = add nsw i64 %22, 1
%24 = call i64 @malloc(i64 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %9
%26 = load i8*, i8** %9
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %20
%29 = load i8*, i8** %8
%30 = call i32 @free(i8* %29)
br label %111
31: ; preds = %20
%32 = load i8*, i8** %3
%33 = load i8*, i8** %8
%34 = load i8*, i8** %9
%35 = call i32 @GetProgArgv(i8* %32, i8* %33, i8* %34)
%36 = load i8*, i8** %8
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %31
%42 = load i8*, i8** %8
%43 = call i32 @free(i8* %42)
%44 = load i8*, i8** %9
%45 = call i32 @free(i8* %44)
br label %111
46: ; preds = %31
%47 = load i8*, i8** %8
%48 = call i32 @GetParsedBuf(i8* %47, i8** %5)
%49 = load i8*, i8** %9
%50 = getelementptr inbounds i8, i8* %49, i64 0
%51 = load i8, i8* %50
%52 = icmp ne i8 %51, 0
br i1 %52, label %53, label %66
53: ; preds = %46
%54 = load i8*, i8** %9
%55 = call i32 @GetParsedBuf(i8* %54, i8** %6)
%56 = load i8*, i8** %6
%57 = call i64 @strlen(i8* %56)
%58 = add nsw i64 %57, 20
%59 = call i64 @malloc(i64 %58)
%60 = inttoptr i64 %59 to i8*
store i8* %60, i8** %7
%61 = load i8*, i8** %7
%62 = load i8*, i8** %6
%63 = call i32 @sprintf(i8* %61, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %62)
%64 = load i8*, i8** %7
%65 = call i32 @putenv(i8* %64)
br label %68
66: ; preds = %46
%67 = call i32 @putenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %68
68: ; preds = %66, %53
%69 = call i32 @putenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%70 = load i8*, i8** %5
%71 = call i32* @popen(i8* %70, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %71, i32** %11
%72 = load i32*, i32** %11
%73 = icmp ne i32* %72, null
br i1 %73, label %74, label %94
74: ; preds = %68
br label %75
75: ; preds = %90, %74
%76 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%77 = load i32*, i32** %11
%78 = call i64 @fgets(i8* %76, i32 1023, i32* %77)
%79 = icmp ne i64 %78, 0
br i1 %79, label %80, label %91
80: ; preds = %75
%81 = load i32*, i32** %4
%82 = icmp ne i32* %81, null
br i1 %82, label %83, label %87
83: ; preds = %80
%84 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%85 = load i32*, i32** %4
%86 = call i32 @fputs(i8* %84, i32* %85)
br label %90
87: ; preds = %80
%88 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%89 = call i32 @puts(i8* %88)
br label %90
90: ; preds = %87, %83
br label %75
91: ; preds = %75
%92 = load i32*, i32** %11
%93 = call i32 @pclose(i32* %92)
br label %94
94: ; preds = %91, %68
%95 = load i8*, i8** %5
%96 = call i32 @free(i8* %95)
%97 = load i8*, i8** %9
%98 = getelementptr inbounds i8, i8* %97, i64 0
%99 = load i8, i8* %98
%100 = icmp ne i8 %99, 0
br i1 %100, label %101, label %106
101: ; preds = %94
%102 = load i8*, i8** %6
%103 = call i32 @free(i8* %102)
%104 = load i8*, i8** %7
%105 = call i32 @free(i8* %104)
br label %106
106: ; preds = %101, %94
%107 = load i8*, i8** %8
%108 = call i32 @free(i8* %107)
%109 = load i8*, i8** %9
%110 = call i32 @free(i8* %109)
br label %111
111: ; preds = %106, %41, %28, %19
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"QUERY_STRING=%s\00"
@.str.1 = [14 x i8] c"QUERY_STRING=\00"
@.str.2 = [19 x i8] c"REQUEST_METHOD=GET\00"
@.str.3 = [2 x i8] c"r\00"
define void @IncludeCGI(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = bitcast i8** %3 to i8*
%7 = bitcast i8** %4 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%10 = add nsw i64 %9, 1
%11 = tail call i64 @malloc(i64 %10)
%12 = inttoptr i64 %11 to i8*
%13 = icmp eq i64 %11, 0
br i1 %13, label %77, label %14
14: ; preds = %2
%15 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%16 = add nsw i64 %15, 1
%17 = tail call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
%19 = icmp eq i64 %17, 0
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = tail call i32 @free(i8* %12)
br label %77
22: ; preds = %14
%23 = tail call i32 @GetProgArgv(i8* %0, i8* %12, i8* %18)
%24 = load i8, i8* %12
%25 = icmp eq i8 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = tail call i32 @free(i8* %12)
%28 = tail call i32 @free(i8* %18)
br label %77
29: ; preds = %22
%30 = call i32 @GetParsedBuf(i8* %12, i8** %3)
%31 = load i8, i8* %18
%32 = icmp eq i8 %31, 0
br i1 %32, label %42, label %33
33: ; preds = %29
%34 = call i32 @GetParsedBuf(i8* %18, i8** %4)
%35 = load i8*, i8** %4
%36 = call i64 @strlen(i8* dereferenceable(1) %35)
%37 = add nsw i64 %36, 20
%38 = call i64 @malloc(i64 %37)
%39 = inttoptr i64 %38 to i8*
%40 = load i8*, i8** %4
%41 = call i32 @sprintf(i8* dereferenceable(1) %39, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %29, %33
%43 = phi i8* [ %39, %33 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), %29 ]
%44 = phi i8* [ %39, %33 ], [ null, %29 ]
%45 = call i32 @putenv(i8* %43)
%46 = call i32 @putenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%47 = load i8*, i8** %3
%48 = call i32* @popen(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%49 = icmp eq i32* %48, null
br i1 %49, label %65, label %50
50: ; preds = %42
%51 = call i64 @fgets(i8* %8, i32 1023, i32* %48)
%52 = icmp eq i64 %51, 0
br i1 %52, label %63, label %53
53: ; preds = %50
%54 = icmp eq i32* %1, null
br label %55
55: ; preds = %53, %60
br i1 %54, label %58, label %56
56: ; preds = %55
%57 = call i32 @fputs(i8* %8, i32* %1)
br label %60
58: ; preds = %55
%59 = call i32 @puts(i8* %8)
br label %60
60: ; preds = %58, %56
%61 = call i64 @fgets(i8* %8, i32 1023, i32* %48)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %55
63: ; preds = %60, %50
%64 = call i32 @pclose(i32* %48)
br label %65
65: ; preds = %63, %42
%66 = load i8*, i8** %3
%67 = call i32 @free(i8* %66)
%68 = load i8, i8* %18
%69 = icmp eq i8 %68, 0
br i1 %69, label %74, label %70
70: ; preds = %65
%71 = load i8*, i8** %4
%72 = call i32 @free(i8* %71)
%73 = call i32 @free(i8* %44)
br label %74
74: ; preds = %70, %65
%75 = call i32 @free(i8* %12)
%76 = call i32 @free(i8* %18)
br label %77
77: ; preds = %2, %74, %26, %20
ret void
}