#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 */
scalar_t__ cgi_get_filename(char *, int /*<<< orphan*/);
int /*<<< orphan*/ cgi_get_length(char *, int /*<<< orphan*/);
char *cgi_get_value(char *, int);
int cgi_get_values_qty(char *);
int /*<<< orphan*/ cgi_show_footer();
int /*<<< orphan*/ cgi_show_header(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(scalar_t__, char *);
int /*<<< orphan*/ fwrite(char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/ *);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
void show_post_form(void) {
  int counter = 0;
  FILE *out;
  if (cgi_get_value("file", 0) && cgi_get_filename("file", 0)) {
    out = fopen(cgi_get_filename("file", 0), "w");
    fwrite(cgi_get_value("file", 0), sizeof(char), cgi_get_length("file", 0),
           out);
    fclose(out);
  }
  cgi_show_header("#ffffff");
  printf("<center><table width=100%% height=100%% border=0><tr><td "
         "align=center valign=center>\n");
  printf(
      "This page generated after using POST form submit method.</td></tr>\n");
  printf("<tr><td align=left valign=top><pre>\n");
  for (counter = 0; counter != cgi_get_values_qty("text"); counter++)
    printf("variable name: text value[%2d]: %s\n", counter,
           cgi_get_value("text", counter));
  printf("</pre></td></tr>\n");
  printf("<tr><td align=center valign=center><form method=get action=%s>\n",
         getenv("SCRIPT_NAME"));
  printf("<input type=submit value='Return to main "
         "page'></form></td></tr></table>\n");
  cgi_show_footer();
}


x86 assembly (clang, -O0):
<show_post_form>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe3a(%rip),%rdi
xor    %esi,%esi
call   10a0 <cgi_get_value@plt>
cmp    $0x0,%rax
je     124d <show_post_form+0x9d>
lea    0xe22(%rip),%rdi
xor    %esi,%esi
call   1080 <cgi_get_filename@plt>
cmp    $0x0,%rax
je     124d <show_post_form+0x9d>
lea    0xe0a(%rip),%rdi
xor    %esi,%esi
call   1080 <cgi_get_filename@plt>
mov    %rax,%rdi
lea    0xdfe(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xde9(%rip),%rdi
xor    %esi,%esi
call   10a0 <cgi_get_value@plt>
mov    %rax,-0x18(%rbp)
lea    0xdd7(%rip),%rdi
xor    %esi,%esi
call   1090 <cgi_get_length@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xdb3(%rip),%rdi
call   1070 <cgi_show_header@plt>
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    0xe37(%rip),%rdi
call   1040 <cgi_get_values_qty@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
je     12e0 <show_post_form+0x130>
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe15(%rip),%rdi
call   10a0 <cgi_get_value@plt>
mov    -0x20(%rbp),%esi
mov    %rax,%rdx
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    128a <show_post_form+0xda>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe54(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10d0 <cgi_show_footer@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_post_form>:
push   %rbp
push   %r14
push   %rbx
lea    0xe35(%rip),%rdi
xor    %esi,%esi
call   10b0 <cgi_get_value@plt>
test   %rax,%rax
je     123e <show_post_form+0x7e>
lea    0xe22(%rip),%rdi
xor    %esi,%esi
call   1090 <cgi_get_filename@plt>
test   %rax,%rax
je     123e <show_post_form+0x7e>
lea    0xe0f(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <cgi_get_filename@plt>
lea    0xe03(%rip),%rsi
mov    %rax,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbp
mov    %r14,%rdi
xor    %esi,%esi
call   10b0 <cgi_get_value@plt>
mov    %rax,%rbx
mov    %r14,%rdi
xor    %esi,%esi
call   10a0 <cgi_get_length@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbp,%rcx
call   10d0 <fwrite@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
lea    0xdc2(%rip),%rdi
call   1080 <cgi_show_header@plt>
lea    0xdbe(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe7b(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb2(%rip),%rdi
call   1040 <puts@plt>
lea    0xdee(%rip),%rdi
call   1050 <cgi_get_values_qty@plt>
test   %eax,%eax
je     12b8 <show_post_form+0xf8>
lea    0xdde(%rip),%rbx
lea    0xddc(%rip),%r14
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   10b0 <cgi_get_value@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1050 <cgi_get_values_qty@plt>
cmp    %eax,%ebp
jne    1290 <show_post_form+0xd0>
lea    0xe82(%rip),%rdi
call   1040 <puts@plt>
lea    0xe03(%rip),%rdi
call   1030 <getenv@plt>
lea    0xdb7(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe6a(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    10e0 <cgi_show_footer@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"file\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [8 x i8] c"#ffffff\00"
@.str.3 = [86 x i8] c"<center><table width=100%% height=100%% border=0><tr><td align=center valign=center>\0A\00"
@.str.4 = [68 x i8] c"This page generated after using POST form submit method.</td></tr>\0A\00"
@.str.5 = [37 x i8] c"<tr><td align=left valign=top><pre>\0A\00"
@.str.6 = [5 x i8] c"text\00"
@.str.7 = [36 x i8] c"variable name: text value[%2d]: %s\0A\00"
@.str.8 = [18 x i8] c"</pre></td></tr>\0A\00"
@.str.9 = [64 x i8] c"<tr><td align=center valign=center><form method=get action=%s>\0A\00"
@.str.10 = [12 x i8] c"SCRIPT_NAME\00"
@.str.11 = [74 x i8] c"<input type=submit value='Return to main page'></form></td></tr></table>\0A\00"
define void @show_post_form() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i8* @cgi_get_value(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0)
%4 = icmp ne i8* %3, null
br i1 %4, label %5, label %17
5: ; preds = %0
%6 = call i64 @cgi_get_filename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = call i64 @cgi_get_filename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0)
%10 = call i32* @fopen(i64 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %2
%11 = call i8* @cgi_get_value(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0)
%12 = call i32 @cgi_get_length(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0)
%13 = load i32*, i32** %2
%14 = call i32 @fwrite(i8* %11, i32 1, i32 %12, i32* %13)
%15 = load i32*, i32** %2
%16 = call i32 @fclose(i32* %15)
br label %17
17: ; preds = %8, %5, %0
%18 = call i32 @cgi_show_header(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %22
22: ; preds = %31, %17
%23 = load i32, i32* %1
%24 = call i32 @cgi_get_values_qty(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %34
26: ; preds = %22
%27 = load i32, i32* %1
%28 = load i32, i32* %1
%29 = call i8* @cgi_get_value(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i32 %27, i8* %29)
br label %31
31: ; preds = %26
%32 = load i32, i32* %1
%33 = add nsw i32 %32, 1
store i32 %33, i32* %1
br label %22
34: ; preds = %22
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
%36 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.9, i64 0, i64 0), i8* %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.11, i64 0, i64 0))
%39 = call i32 (...) @cgi_show_footer()
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"file\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [8 x i8] c"#ffffff\00"
@.str.3 = [86 x i8] c"<center><table width=100%% height=100%% border=0><tr><td align=center valign=center>\0A\00"
@.str.6 = [5 x i8] c"text\00"
@.str.7 = [36 x i8] c"variable name: text value[%2d]: %s\0A\00"
@.str.9 = [64 x i8] c"<tr><td align=center valign=center><form method=get action=%s>\0A\00"
@.str.10 = [12 x i8] c"SCRIPT_NAME\00"
@str = [67 x i8] c"This page generated after using POST form submit method.</td></tr>\00"
@str.12 = [36 x i8] c"<tr><td align=left valign=top><pre>\00"
@str.13 = [17 x i8] c"</pre></td></tr>\00"
@str.14 = [73 x i8] c"<input type=submit value='Return to main page'></form></td></tr></table>\00"
define void @show_post_form() {
%1 = tail call i8* @cgi_get_value(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0)
%2 = icmp eq i8* %1, null
br i1 %2, label %13, label %3
3: ; preds = %0
%4 = tail call i64 @cgi_get_filename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = tail call i64 @cgi_get_filename(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0)
%8 = tail call i32* @fopen(i64 %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i8* @cgi_get_value(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0)
%10 = tail call i32 @cgi_get_length(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0)
%11 = tail call i32 @fwrite(i8* %9, i32 1, i32 %10, i32* %8)
%12 = tail call i32 @fclose(i32* %8)
br label %13
13: ; preds = %6, %3, %0
%14 = tail call i32 @cgi_show_header(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([86 x i8], [86 x i8]* @.str.3, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.12, i64 0, i64 0))
%18 = tail call i32 @cgi_get_values_qty(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %13, %20
%21 = phi i32 [ %24, %20 ], [ 0, %13 ]
%22 = tail call i8* @cgi_get_value(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %21)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i32 %21, i8* %22)
%24 = add nuw nsw i32 %21, 1
%25 = tail call i32 @cgi_get_values_qty(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %20
27: ; preds = %20, %13
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.13, i64 0, i64 0))
%29 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.9, i64 0, i64 0), i8* %29)
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str.14, i64 0, i64 0))
%32 = tail call i32 (...) @cgi_show_footer()
ret void
}