#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *FP_strdup(char *);
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, 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;
  FILE *fp;
  fp = fopen(getenv("CGI_POST_TMPFILE"), "r");
  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 (fp) {
      if ((ts = fread(result, sizeof(char), length, fp)) < length) {
        fprintf(
            stderr,
            "proccgi -- error reading post data, %d bytes read, %d expedted\n",
            ts, length);
      }
      fclose(fp);
    } else {
      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    0xe61(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
lea    0xe63(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
lea    0xe55(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11de <LoadInput+0x4e>
movq   $0x0,-0x8(%rbp)
jmp    1383 <LoadInput+0x1f3>
mov    -0x18(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1231 <LoadInput+0xa1>
lea    0xe27(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    121f <LoadInput+0x8f>
movq   $0x0,-0x8(%rbp)
jmp    1383 <LoadInput+0x1f3>
mov    -0x20(%rbp),%rdi
call   1080 <FP_strdup@plt>
mov    %rax,-0x10(%rbp)
jmp    137b <LoadInput+0x1eb>
mov    -0x18(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1369 <LoadInput+0x1d9>
lea    0xde6(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jne    1278 <LoadInput+0xe8>
movq   $0x0,-0x8(%rbp)
jmp    1383 <LoadInput+0x1f3>
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    12b8 <LoadInput+0x128>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xda3(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1383 <LoadInput+0x1f3>
cmpq   $0x0,-0x30(%rbp)
je     130f <LoadInput+0x17f>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x28(%rbp)
cmp    -0x24(%rbp),%eax
jge    1301 <LoadInput+0x171>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xd7b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1358 <LoadInput+0x1c8>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    0x2ccb(%rip),%rax
mov    (%rax),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x28(%rbp)
cmp    -0x24(%rbp),%eax
jge    1353 <LoadInput+0x1c3>
mov    0x2c9b(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xd29(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1358 <LoadInput+0x1c8>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1376 <LoadInput+0x1e6>
movq   $0x0,-0x8(%rbp)
jmp    1383 <LoadInput+0x1f3>
jmp    137b <LoadInput+0x1eb>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LoadInput>:
push   %r15
push   %r14
push   %rbx
lea    0xe64(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe69(%rip),%rsi
mov    %rax,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r15
lea    0xe59(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     128f <LoadInput+0xff>
mov    %rax,%rbx
lea    0xe50(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1271 <LoadInput+0xe1>
lea    0xe49(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    128f <LoadInput+0xff>
lea    0xe36(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   10b0 <atoi@plt>
test   %eax,%eax
je     128f <LoadInput+0xff>
mov    %eax,%r14d
lea    0x1(%r14),%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     129a <LoadInput+0x10a>
mov    %rax,%rbx
test   %r15,%r15
je     12b8 <LoadInput+0x128>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
cmp    %r14d,%eax
jge    1264 <LoadInput+0xd4>
mov    0x2d89(%rip),%rcx
mov    (%rcx),%edi
lea    0xe1d(%rip),%rsi
mov    %eax,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
jmp    12f3 <LoadInput+0x163>
lea    0xdae(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     128f <LoadInput+0xff>
mov    %rax,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <FP_strdup@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
lea    0xd9d(%rip),%rsi
xor    %ebx,%ebx
mov    %r14d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1291 <LoadInput+0x101>
mov    0x2d29(%rip),%rax
mov    (%rax),%rcx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
call   1040 <fread@plt>
cmp    %r14d,%eax
jge    12f3 <LoadInput+0x163>
mov    0x2cfa(%rip),%rcx
mov    (%rcx),%edi
lea    0xd8e(%rip),%rsi
mov    %eax,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
movslq %r14d,%rax
movb   $0x0,(%rbx,%rax,1)
jmp    1291 <LoadInput+0x101>

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

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