#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 */
char *FP_strdup(char *);
int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int fread(char *, int, int, int /*<<< orphan*/);
char *getenv(char *);
char *malloc(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
char *LoadInput(void) {
  char *result, *method, *p;
  int length, ts;
  if ((method = getenv("REQUEST_METHOD")) == NULL) {
    return NULL;
  }
  if (strcmp(method, "GET") == 0) {
    if ((p = getenv("QUERY_STRING")) == NULL)
      return NULL;
    else
      result = FP_strdup(p);
  } else if (strcmp(method, "POST") == 0) {
    if ((length = atoi(getenv("CONTENT_LENGTH"))) == 0)
      return NULL;
    if ((result = malloc(length + 1)) == NULL) {
      fprintf(stderr, "proccgi -- out of memory allocating %d bytes\n", length);
      return NULL;
    }
    if ((ts = fread(result, sizeof(char), length, stdin)) < length) {
      fprintf(
          stderr,
          "proccgi -- error reading post data, %d bytes read, %d expedted\n",
          ts, length);
    }
    result[length] = '\0';
  } else {
    return NULL;
  }
  return result;
}


x86 assembly (clang, -O0):
<LoadInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe81(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    119f <LoadInput+0x2f>
movq   $0x0,-0x8(%rbp)
jmp    12e7 <LoadInput+0x177>
mov    -0x18(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11f2 <LoadInput+0x82>
lea    0xe53(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11e0 <LoadInput+0x70>
movq   $0x0,-0x8(%rbp)
jmp    12e7 <LoadInput+0x177>
mov    -0x20(%rbp),%rdi
call   1070 <FP_strdup@plt>
mov    %rax,-0x10(%rbp)
jmp    12df <LoadInput+0x16f>
mov    -0x18(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12cd <LoadInput+0x15d>
lea    0xe12(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jne    1239 <LoadInput+0xc9>
movq   $0x0,-0x8(%rbp)
jmp    12e7 <LoadInput+0x177>
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1279 <LoadInput+0x109>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xdcf(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12e7 <LoadInput+0x177>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    0x2d61(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x28(%rbp)
cmp    -0x24(%rbp),%eax
jge    12bc <LoadInput+0x14c>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xdad(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    12da <LoadInput+0x16a>
movq   $0x0,-0x8(%rbp)
jmp    12e7 <LoadInput+0x177>
jmp    12df <LoadInput+0x16f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LoadInput>:
push   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     124b <LoadInput+0xdb>
mov    %rax,%rbx
lea    0xe7c(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     122b <LoadInput+0xbb>
lea    0xe75(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    124b <LoadInput+0xdb>
lea    0xe62(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1090 <atoi@plt>
test   %eax,%eax
je     124b <LoadInput+0xdb>
mov    %eax,%r14d
lea    0x1(%r14),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1258 <LoadInput+0xe8>
mov    %rax,%rbx
mov    0x2df9(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
call   1040 <fread@plt>
cmp    %r14d,%eax
jge    1222 <LoadInput+0xb2>
mov    0x2dcb(%rip),%rcx
mov    (%rcx),%edi
lea    0xe4c(%rip),%rsi
mov    %eax,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
movslq %r14d,%rax
movb   $0x0,(%rbx,%rax,1)
jmp    124d <LoadInput+0xdd>
lea    0xde1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     124b <LoadInput+0xdb>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <FP_strdup@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
xor    %ebx,%ebx
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    124d <LoadInput+0xdd>

LLVM IR (-O0):
@.str = [15 x i8] c"REQUEST_METHOD\00"
@.str.1 = [4 x i8] c"GET\00"
@.str.2 = [13 x i8] c"QUERY_STRING\00"
@.str.3 = [5 x i8] c"POST\00"
@.str.4 = [15 x i8] c"CONTENT_LENGTH\00"
@stderr = global i32 0
@.str.5 = [46 x i8] c"proccgi -- out of memory allocating %d bytes\0A\00"
@stdin = global i32 0
@.str.6 = [64 x i8] c"proccgi -- error reading post data, %d bytes read, %d expedted\0A\00"
define i8* @LoadInput() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %0
store i8* null, i8** %1
br label %61
10: ; preds = %0
%11 = load i8*, i8** %3
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i8* %15, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %14
store i8* null, i8** %1
br label %61
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = call i8* @FP_strdup(i8* %19)
store i8* %20, i8** %2
br label %21
21: ; preds = %18
br label %59
22: ; preds = %10
%23 = load i8*, i8** %3
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %57
26: ; preds = %22
%27 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %5
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26
store i8* null, i8** %1
br label %61
31: ; preds = %26
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
%34 = call i8* @malloc(i32 %33)
store i8* %34, i8** %2
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = load i32, i32* %5
%39 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i32 %38)
store i8* null, i8** %1
br label %61
40: ; preds = %31
%41 = load i8*, i8** %2
%42 = load i32, i32* %5
%43 = load i32, i32* @stdin
%44 = call i32 @fread(i8* %41, i32 1, i32 %42, i32 %43)
store i32 %44, i32* %6
%45 = load i32, i32* %5
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %52
47: ; preds = %40
%48 = load i32, i32* @stderr
%49 = load i32, i32* %6
%50 = load i32, i32* %5
%51 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.6, i64 0, i64 0), i32 %49, i32 %50)
br label %52
52: ; preds = %47, %40
%53 = load i8*, i8** %2
%54 = load i32, i32* %5
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
store i8 0, i8* %56
br label %58
57: ; preds = %22
store i8* null, i8** %1
br label %61
58: ; preds = %52
br label %59
59: ; preds = %58, %21
%60 = load i8*, i8** %2
store i8* %60, i8** %1
br label %61
61: ; preds = %59, %57, %36, %30, %17, %9
%62 = load i8*, i8** %1
ret i8* %62
}

LLVM IR (-O2):
@.str = [15 x i8] c"REQUEST_METHOD\00"
@.str.1 = [4 x i8] c"GET\00"
@.str.2 = [13 x i8] c"QUERY_STRING\00"
@.str.3 = [5 x i8] c"POST\00"
@.str.4 = [15 x i8] c"CONTENT_LENGTH\00"
@stderr = global i32 0
@.str.5 = [46 x i8] c"proccgi -- out of memory allocating %d bytes\0A\00"
@stdin = global i32 0
@.str.6 = [64 x i8] c"proccgi -- error reading post data, %d bytes read, %d expedted\0A\00"
define i8* @LoadInput() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %35, label %3
3: ; preds = %0
%4 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %35, label %9
9: ; preds = %6
%10 = tail call i8* @FP_strdup(i8* %7)
br label %35
11: ; preds = %3
%12 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %35
14: ; preds = %11
%15 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%16 = tail call i32 @atoi(i8* %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %35, label %18
18: ; preds = %14
%19 = add nsw i32 %16, 1
%20 = tail call i8* @malloc(i32 %19)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i32 %16)
br label %35
25: ; preds = %18
%26 = load i32, i32* @stdin
%27 = tail call i32 @fread(i8* %20, i32 1, i32 %16, i32 %26)
%28 = icmp slt i32 %27, %16
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.6, i64 0, i64 0), i32 %27, i32 %16)
br label %32
32: ; preds = %29, %25
%33 = sext i32 %16 to i64
%34 = getelementptr inbounds i8, i8* %20, i64 %33
store i8 0, i8* %34
br label %35
35: ; preds = %9, %32, %11, %14, %6, %0, %22
%36 = phi i8* [ null, %22 ], [ null, %0 ], [ null, %6 ], [ null, %14 ], [ null, %11 ], [ %10, %9 ], [ %20, %32 ]
ret i8* %36
}