#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 *);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
int main() {
  char buf[1024];
  char *cookie = getenv("HTTP_COOKIE");
  int len = atoi(getenv("CONTENT_LENGTH"));
  printf("Set-Cookie:user=helight.xu\r\n");
  printf("Content-type:text/html\r\n\r\n");
  printf(
      "<html><head><title>cgi post</title>                <meta "
      "http-equiv='Content-Type' content='text/html; charset=utf-8'/></head>");
  printf("<body><div width=900px><div align=center>                <h1>cgi "
         "post</h1></div><hr> <div>");
  read(0, buf, len);
  buf[len] = '\0';
  printf("buf:%s\n", buf);
  printf("cookie:%s len:%d\n", cookie, len);
  printf("<form action=spost.cgi method=post>");
  printf("<input type=text name=XY_wd  size=42 maxlength=100><br>");
  printf("<input type=text name=XY_ww  size=42 maxlength=100><br>");
  printf("<br><input type=submit value=配置 >                <input type=reset "
         "value=重置 ></form>                </div><hr></div></body></html>\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x418(%rbp)
lea    0xea0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1060 <atoi@plt>
mov    %eax,-0x41c(%rbp)
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x410(%rbp),%rsi
mov    -0x41c(%rbp),%edx
xor    %edi,%edi
call   1050 <read@plt>
movslq -0x41c(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rsi
lea    0xf45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x418(%rbp),%rsi
mov    -0x41c(%rbp),%edx
lea    0xf32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xfa0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
lea    0xe9e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
lea    0xe9b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
lea    0x101c(%rip),%rdi
call   1040 <puts@plt>
lea    0x102c(%rip),%rdi
call   1040 <puts@plt>
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeed(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rbx
xor    %edi,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <read@plt>
movslq %ebp,%rbp
movb   $0x0,(%rsp,%rbp,1)
lea    0xf24(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf1b(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf1a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf30(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf5a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xfba(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"HTTP_COOKIE\00"
@.str.1 = [15 x i8] c"CONTENT_LENGTH\00"
@.str.2 = [29 x i8] c"Set-Cookie:user=helight.xu\0D\0A\00"
@.str.3 = [27 x i8] c"Content-type:text/html\0D\0A\0D\0A\00"
@.str.4 = [127 x i8] c"<html><head><title>cgi post</title> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/></head>\00"
@.str.5 = [91 x i8] c"<body><div width=900px><div align=center> <h1>cgi post</h1></div><hr> <div>\00"
@.str.6 = [8 x i8] c"buf:%s\0A\00"
@.str.7 = [18 x i8] c"cookie:%s len:%d\0A\00"
@.str.8 = [36 x i8] c"<form action=spost.cgi method=post>\00"
@.str.9 = [56 x i8] c"<input type=text name=XY_wd size=42 maxlength=100><br>\00"
@.str.10 = [56 x i8] c"<input type=text name=XY_ww size=42 maxlength=100><br>\00"
@.str.11 = [140 x i8] c"<br><input type=submit value=\E9\85\8D\E7\BD\AE > <input type=reset value=\E9\87\8D\E7\BD\AE ></form> </div><hr></div></body></html>\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %3
%6 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @atoi(i8* %6)
store i32 %7, i32* %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([127 x i8], [127 x i8]* @.str.4, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.5, i64 0, i64 0))
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%13 = load i32, i32* %4
%14 = call i32 @read(i32 0, i8* %12, i32 %13)
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %16
store i8 0, i8* %17
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %3
%21 = load i32, i32* %4
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8* %20, i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.9, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.10, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.11, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"HTTP_COOKIE\00"
@.str.1 = [15 x i8] c"CONTENT_LENGTH\00"
@.str.4 = [127 x i8] c"<html><head><title>cgi post</title> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/></head>\00"
@.str.5 = [91 x i8] c"<body><div width=900px><div align=center> <h1>cgi post</h1></div><hr> <div>\00"
@.str.6 = [8 x i8] c"buf:%s\0A\00"
@.str.7 = [18 x i8] c"cookie:%s len:%d\0A\00"
@.str.8 = [36 x i8] c"<form action=spost.cgi method=post>\00"
@.str.9 = [56 x i8] c"<input type=text name=XY_wd size=42 maxlength=100><br>\00"
@.str.10 = [56 x i8] c"<input type=text name=XY_ww size=42 maxlength=100><br>\00"
@str = [28 x i8] c"Set-Cookie:user=helight.xu\0D\00"
@str.12 = [26 x i8] c"Content-type:text/html\0D\0A\0D\00"
@str.13 = [139 x i8] c"<br><input type=submit value=\E9\85\8D\E7\BD\AE > <input type=reset value=\E9\87\8D\E7\BD\AE ></form> </div><hr></div></body></html>\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @atoi(i8* %4)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.12, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([127 x i8], [127 x i8]* @.str.4, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([91 x i8], [91 x i8]* @.str.5, i64 0, i64 0))
%10 = call i32 @read(i32 0, i8* %2, i32 %5)
%11 = sext i32 %5 to i64
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %11
store i8 0, i8* %12
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %2)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8* %3, i32 %5)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.9, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.10, i64 0, i64 0))
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([139 x i8], [139 x i8]* @str.13, i64 0, i64 0))
ret i32 0
}