#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 */

/* Variables and functions */
int /*<<< orphan*/ addTitleElement(char *);
int /*<<< orphan*/ printf(char *, ...);
int template_page(char **postvars, int form_method) {
  int i;
  addTitleElement("Demo CGI");
  if (form_method == 1) {
    for (i = 0; postvars[i]; i += 2) {
      printf("<li>DEBUG: [%s] = [%s]\n", postvars[i], postvars[i + 1]);
    }
  }
  printf("<FORM ACTION=\"%s\" METHOD=POST>", "/cgi-bin/cgi_demo");
  printf("<SELECT NAME=\"port\">");
  printf("<OPTION>COM 1");
  printf("<OPTION>COM 2");
  printf("</SELECT>");
  printf("</TD></TR>");
  printf("<BR><INPUT TYPE=submit VALUE=\"Submit\">");
  printf("<INPUT TYPE=reset VALUE=\"Reset\">");
  printf("</FORM>");
  return 0;
}


x86 assembly (clang, -O0):
<template_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeca(%rip),%rdi
call   1040 <addTitleElement@plt>
cmpl   $0x1,-0xc(%rbp)
jne    119d <template_page+0x7d>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1198 <template_page+0x78>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
jmp    114c <template_page+0x2c>
jmp    119d <template_page+0x7d>
lea    0xe7d(%rip),%rdi
lea    0xe95(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<template_page>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xed0(%rip),%rdi
call   1040 <addTitleElement@plt>
cmp    $0x1,%ebp
jne    116a <template_page+0x4a>
mov    (%rbx),%rsi
test   %rsi,%rsi
je     116a <template_page+0x4a>
add    $0x10,%rbx
lea    0xebc(%rip),%r14
nopl   (%rax)
mov    -0x8(%rbx),%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rbx),%rsi
add    $0x10,%rbx
test   %rsi,%rsi
jne    1150 <template_page+0x30>
lea    0xeb0(%rip),%rdi
lea    0xec8(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xecc(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed3(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed3(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed3(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xecf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xecc(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xef8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"Demo CGI\00"
@.str.1 = [24 x i8] c"<li>DEBUG: [%s] = [%s]\0A\00"
@.str.2 = [31 x i8] c"<FORM ACTION=\22%s\22 METHOD=POST>\00"
@.str.3 = [18 x i8] c"/cgi-bin/cgi_demo\00"
@.str.4 = [21 x i8] c"<SELECT NAME=\22port\22>\00"
@.str.5 = [14 x i8] c"<OPTION>COM 1\00"
@.str.6 = [14 x i8] c"<OPTION>COM 2\00"
@.str.7 = [10 x i8] c"</SELECT>\00"
@.str.8 = [11 x i8] c"</TD></TR>\00"
@.str.9 = [39 x i8] c"<BR><INPUT TYPE=submit VALUE=\22Submit\22>\00"
@.str.10 = [33 x i8] c"<INPUT TYPE=reset VALUE=\22Reset\22>\00"
@.str.11 = [8 x i8] c"</FORM>\00"
define i32 @template_page(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
%6 = call i32 @addTitleElement(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %34
9: ; preds = %2
store i32 0, i32* %5
br label %10
10: ; preds = %30, %9
%11 = load i8**, i8*** %3
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %11, i64 %13
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %33
17: ; preds = %10
%18 = load i8**, i8*** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = load i8**, i8*** %3
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %23, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %28)
br label %30
30: ; preds = %17
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 2
store i32 %32, i32* %5
br label %10
33: ; preds = %10
br label %34
34: ; preds = %33, %2
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0))
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"Demo CGI\00"
@.str.1 = [24 x i8] c"<li>DEBUG: [%s] = [%s]\0A\00"
@.str.2 = [31 x i8] c"<FORM ACTION=\22%s\22 METHOD=POST>\00"
@.str.3 = [18 x i8] c"/cgi-bin/cgi_demo\00"
@.str.4 = [21 x i8] c"<SELECT NAME=\22port\22>\00"
@.str.5 = [14 x i8] c"<OPTION>COM 1\00"
@.str.6 = [14 x i8] c"<OPTION>COM 2\00"
@.str.7 = [10 x i8] c"</SELECT>\00"
@.str.8 = [11 x i8] c"</TD></TR>\00"
@.str.9 = [39 x i8] c"<BR><INPUT TYPE=submit VALUE=\22Submit\22>\00"
@.str.10 = [33 x i8] c"<INPUT TYPE=reset VALUE=\22Reset\22>\00"
@.str.11 = [8 x i8] c"</FORM>\00"
define i32 @template_page(i8** nocapture %0, i32 %1) {
%3 = tail call i32 @addTitleElement(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %1, 1
br i1 %4, label %5, label %19
5: ; preds = %2
%6 = load i8*, i8** %0
%7 = icmp eq i8* %6, null
br i1 %7, label %19, label %8
8: ; preds = %5, %8
%9 = phi i64 [ %15, %8 ], [ 0, %5 ]
%10 = phi i8* [ %17, %8 ], [ %6, %5 ]
%11 = or i64 %9, 1
%12 = getelementptr inbounds i8*, i8** %0, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %10, i8* %13)
%15 = add nuw i64 %9, 2
%16 = getelementptr inbounds i8*, i8** %0, i64 %15
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %8
19: ; preds = %8, %5, %2
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0))
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
ret i32 0
}