#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*/ fread(char *, int, int, int /*<<< orphan*/);
char *getenv(char *);
char *malloc(int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *GetStringFromWeb() {
  char method[10];
  char *outstring;
  int string_length = 0;
  strcpy(method, getenv("REQUEST_METHOD"));
  if (!strcmp(method, "POST")) {
    string_length = atoi(getenv("CONTENT_LENGTH"));
    if (string_length != 0) {
      outstring = malloc(sizeof(char) * string_length + 1);
      fread(outstring, sizeof(char), string_length, stdin);
    }
  } else if (!strcmp(method, "GET")) {
    if (NULL != getenv("QUERY_STRING")) {
      string_length = strlen(getenv("QUERY_STRING"));
      outstring = malloc(sizeof(char) * string_length + 1);
      strcpy(outstring, getenv("QUERY_STRING"));
      string_length = strlen(outstring);
    }
  }
  if (string_length == 0) {
    return NULL;
  }
  return outstring;
}


x86 assembly (clang, -O0):
<GetStringFromWeb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x24(%rbp)
lea    -0x12(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe72(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    -0x12(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    120f <GetStringFromWeb+0x9f>
lea    0xe55(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     120a <GetStringFromWeb+0x9a>
movslq -0x24(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    0x2dea(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1050 <fread@plt>
jmp    12a6 <GetStringFromWeb+0x136>
lea    -0x12(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    12a1 <GetStringFromWeb+0x131>
lea    0xdf8(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     129c <GetStringFromWeb+0x12c>
lea    0xdde(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xda8(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x24(%rbp)
jmp    12a1 <GetStringFromWeb+0x131>
jmp    12a6 <GetStringFromWeb+0x136>
cmpl   $0x0,-0x24(%rbp)
jne    12bd <GetStringFromWeb+0x14d>
movq   $0x0,-0x8(%rbp)
jmp    12c5 <GetStringFromWeb+0x155>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetStringFromWeb>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xe93(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe(%rsp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    $0x54534f50,%eax
xor    0xe(%rsp),%eax
movzbl 0x12(%rsp),%ecx
or     %eax,%ecx
je     11e8 <GetStringFromWeb+0x88>
cmpl   $0x544547,0xe(%rsp)
jne    1229 <GetStringFromWeb+0xc9>
lea    0xe81(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1229 <GetStringFromWeb+0xc9>
mov    %rax,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe5d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jne    122b <GetStringFromWeb+0xcb>
jmp    1229 <GetStringFromWeb+0xc9>
lea    0xe25(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1080 <atoi@plt>
test   %eax,%eax
je     1229 <GetStringFromWeb+0xc9>
mov    %eax,%ebp
mov    %eax,%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    0x2dd2(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   1050 <fread@plt>
jmp    122b <GetStringFromWeb+0xcb>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"REQUEST_METHOD\00"
@.str.1 = [5 x i8] c"POST\00"
@.str.2 = [15 x i8] c"CONTENT_LENGTH\00"
@stdin = global i32 0
@.str.3 = [4 x i8] c"GET\00"
@.str.4 = [13 x i8] c"QUERY_STRING\00"
define i8* @GetStringFromWeb() {
%1 = alloca i8*
%2 = alloca [10 x i8]
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %4
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%6 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @strcpy(i8* %5, i8* %6)
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%9 = call i32 @strcmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp ne i32 %9, 0
br i1 %10, label %28, label %11
11: ; preds = %0
%12 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @atoi(i8* %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %11
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = mul i64 1, %18
%20 = add i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = call i8* @malloc(i32 %21)
store i8* %22, i8** %3
%23 = load i8*, i8** %3
%24 = load i32, i32* %4
%25 = load i32, i32* @stdin
%26 = call i32 @fread(i8* %23, i32 1, i32 %24, i32 %25)
br label %27
27: ; preds = %16, %11
br label %51
28: ; preds = %0
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%30 = call i32 @strcmp(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %50, label %32
32: ; preds = %28
%33 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%34 = icmp ne i8* null, %33
br i1 %34, label %35, label %49
35: ; preds = %32
%36 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 @strlen(i8* %36)
store i32 %37, i32* %4
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = mul i64 1, %39
%41 = add i64 %40, 1
%42 = trunc i64 %41 to i32
%43 = call i8* @malloc(i32 %42)
store i8* %43, i8** %3
%44 = load i8*, i8** %3
%45 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%46 = call i32 @strcpy(i8* %44, i8* %45)
%47 = load i8*, i8** %3
%48 = call i32 @strlen(i8* %47)
store i32 %48, i32* %4
br label %49
49: ; preds = %35, %32
br label %50
50: ; preds = %49, %28
br label %51
51: ; preds = %50, %27
%52 = load i32, i32* %4
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %51
store i8* null, i8** %1
br label %57
55: ; preds = %51
%56 = load i8*, i8** %3
store i8* %56, i8** %1
br label %57
57: ; preds = %55, %54
%58 = load i8*, i8** %1
ret i8* %58
}

LLVM IR (-O2):
@.str = [15 x i8] c"REQUEST_METHOD\00"
@.str.1 = [5 x i8] c"POST\00"
@.str.2 = [15 x i8] c"CONTENT_LENGTH\00"
@stdin = global i32 0
@.str.3 = [4 x i8] c"GET\00"
@.str.4 = [13 x i8] c"QUERY_STRING\00"
define i8* @GetStringFromWeb() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @strcpy(i8* %2, i8* %3)
%5 = call i32 @bcmp(i8* dereferenceable(5) %2, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 5)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %0
%8 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @atoi(i8* %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %30, label %11
11: ; preds = %7
%12 = add i32 %9, 1
%13 = call i8* @malloc(i32 %12)
%14 = load i32, i32* @stdin
%15 = call i32 @fread(i8* %13, i32 1, i32 %9, i32 %14)
br label %31
16: ; preds = %0
%17 = call i32 @bcmp(i8* dereferenceable(4) %2, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 4)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %16
%20 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %30, label %22
22: ; preds = %19
%23 = call i32 @strlen(i8* %20)
%24 = add i32 %23, 1
%25 = call i8* @malloc(i32 %24)
%26 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 @strcpy(i8* %25, i8* %26)
%28 = call i32 @strlen(i8* %25)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %7, %19, %16, %22
br label %31
31: ; preds = %11, %22, %30
%32 = phi i8* [ null, %30 ], [ %25, %22 ], [ %13, %11 ]
ret i8* %32
}