#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 fread(char *, int, int, int /*<<< orphan*/);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main(void) {
  char buf[4096] = {0};
  char *query_string = NULL;
  char *content_type = NULL;
  char *content_length = NULL;
  int len = 0;
  printf("Content-type: text/plain\n");
  printf("\n");
  query_string = getenv("QUERY_STRING");
  printf("query_string: %s\n", query_string);
  content_type = getenv("CONTENT_TYPE");
  printf("Content-type: %s\n", content_type);
  content_length = getenv("CONTENT_LENGTH");
  printf("Content-length: %s\n", content_length);
  len = fread(buf, sizeof(char), 4096, stdin);
  printf("len: %d\n", len);
  printf("-----\n");
  printf("%s\n", buf);
  printf("-----\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x1010(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
movq   $0x0,-0x1018(%rbp)
movq   $0x0,-0x1020(%rbp)
movq   $0x0,-0x1028(%rbp)
movl   $0x0,-0x102c(%rbp)
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xee4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe67(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x1018(%rbp)
mov    -0x1018(%rbp),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe5e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x1020(%rbp)
mov    -0x1020(%rbp),%rsi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe55(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x1028(%rbp)
mov    -0x1028(%rbp),%rsi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x1010(%rbp),%rdi
mov    0x2db6(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1040 <fread@plt>
mov    %eax,-0x102c(%rbp)
mov    -0x102c(%rbp),%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x1010(%rbp),%rsi
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rsp,%r14
mov    $0x1000,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xee7(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xe67(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe68(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe69(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe6a(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe6b(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe6e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
call   1060 <fread@plt>
lea    0xe56(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe68(%rip),%rbx
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Content-type: text/plain\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [13 x i8] c"QUERY_STRING\00"
@.str.3 = [18 x i8] c"query_string: %s\0A\00"
@.str.4 = [13 x i8] c"CONTENT_TYPE\00"
@.str.5 = [18 x i8] c"Content-type: %s\0A\00"
@.str.6 = [15 x i8] c"CONTENT_LENGTH\00"
@.str.7 = [20 x i8] c"Content-length: %s\0A\00"
@stdin = global i32 0
@.str.8 = [9 x i8] c"len: %d\0A\00"
@.str.9 = [7 x i8] c"-----\0A\00"
@.str.10 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4096 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [4096 x i8]* %2 to i8*
store i8* null, i8** %3
store i8* null, i8** %4
store i8* null, i8** %5
store i32 0, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%13 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %14)
%16 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%20 = load i32, i32* @stdin
%21 = call i32 @fread(i8* %19, i32 1, i32 4096, i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [13 x i8] c"QUERY_STRING\00"
@.str.3 = [18 x i8] c"query_string: %s\0A\00"
@.str.4 = [13 x i8] c"CONTENT_TYPE\00"
@.str.5 = [18 x i8] c"Content-type: %s\0A\00"
@.str.6 = [15 x i8] c"CONTENT_LENGTH\00"
@.str.7 = [20 x i8] c"Content-length: %s\0A\00"
@stdin = global i32 0
@.str.8 = [9 x i8] c"len: %d\0A\00"
@str = [25 x i8] c"Content-type: text/plain\00"
@str.12 = [6 x i8] c"-----\00"
define i32 @main() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @putchar(i32 10)
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %7)
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @stdin
%12 = call i32 @fread(i8* %2, i32 1, i32 4096, i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %12)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.12, i64 0, i64 0))
%15 = call i32 @puts(i8* %2)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.12, i64 0, i64 0))
ret i32 0
}