#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 atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char getchar();
char *getenv(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int main(int argc, char **argv) {
  char *env;
  int length, i;
  char a;
  env = getenv("CONTENT_LENGTH");
  length = atoi(env);
  printf("Content-type: text/html\r\n\r\n");
  printf("<html><head><title>TEST PAGE</title></head>\n");
  printf("<body><pre>\n");
  printf("POST QUERY STRING: ");
  for (i = 0; i < length; i++) {
    a = getchar();
    putchar(a);
  }
  printf("</pre></body></html>");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe76(%rip),%rdi
call   1050 <printf@plt>
lea    0xe86(%rip),%rdi
call   1050 <printf@plt>
lea    0xea7(%rip),%rdi
call   1050 <printf@plt>
lea    0xea8(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11f6 <main+0x96>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%edi
call   1040 <putchar@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c9 <main+0x69>
lea    0xe7c(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xe88(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
lea    0xeaa(%rip),%rdi
call   1050 <puts@plt>
lea    0xeb9(%rip),%rdi
call   1050 <puts@plt>
lea    0xed9(%rip),%rdi
call   1050 <puts@plt>
lea    0xe5d(%rip),%rdi
call   1060 <printf@plt>
test   %ebx,%ebx
jle    11d4 <main+0x64>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <getchar@plt>
movsbl %al,%edi
call   1040 <putchar@plt>
add    $0xffffffff,%ebx
jne    11c0 <main+0x50>
lea    0xe48(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"CONTENT_LENGTH\00"
@.str.1 = [28 x i8] c"Content-type: text/html\0D\0A\0D\0A\00"
@.str.2 = [45 x i8] c"<html><head><title>TEST PAGE</title></head>\0A\00"
@.str.3 = [13 x i8] c"<body><pre>\0A\00"
@.str.4 = [20 x i8] c"POST QUERY STRING: \00"
@.str.5 = [21 x i8] c"</pre></body></html>\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = call i32 @atoi(i8* %11)
store i32 %12, i32* %7
%13 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %8
br label %17
17: ; preds = %25, %2
%18 = load i32, i32* %8
%19 = load i32, i32* %7
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = call signext i8 (...) @getchar()
store i8 %22, i8* %9
%23 = load i8, i8* %9
%24 = call i32 @putchar(i8 signext %23)
br label %25
25: ; preds = %21
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %17
28: ; preds = %17
%29 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [15 x i8] c"CONTENT_LENGTH\00"
@.str.4 = [20 x i8] c"POST QUERY STRING: \00"
@.str.5 = [21 x i8] c"</pre></body></html>\00"
@str = [27 x i8] c"Content-type: text/html\0D\0A\0D\00"
@str.6 = [44 x i8] c"<html><head><title>TEST PAGE</title></head>\00"
@str.7 = [12 x i8] c"<body><pre>\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @atoi(i8* %3)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.6, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.7, i64 0, i64 0))
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%9 = icmp sgt i32 %4, 0
br i1 %9, label %10, label %16
10: ; preds = %2, %10
%11 = phi i32 [ %14, %10 ], [ 0, %2 ]
%12 = tail call signext i8 (...) @getchar()
%13 = tail call i32 @putchar(i8 signext %12)
%14 = add nuw nsw i32 %11, 1
%15 = icmp eq i32 %14, %4
br i1 %15, label %16, label %10
16: ; preds = %10, %2
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%18 = tail call i32 @exit(i32 0)
unreachable
}