#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 /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ getenv(char *);
int /*<<< orphan*/ sscanf(int /*<<< orphan*/, char *, int *);
int /*<<< orphan*/ stdin;
scalar_t__ strcasecmp(int /*<<< orphan*/, char *);
int ReadPost(char *cBuffer, int dSize) {
  int dPostSize = 0;
  if (strcasecmp(getenv("REQUEST_METHOD"), "POST") != 0) {
    return -1;
  }
  sscanf(getenv("CONTENT_LENGTH"), "%d", &dPostSize);
  if (dPostSize >= dSize) {
    return -1;
  }
  dPostSize++;
  fgets(cBuffer, dPostSize, stdin);
  return dPostSize;
}


x86 assembly (clang, -O0):
<ReadPost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xea3(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
lea    0xea4(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     1186 <ReadPost+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <ReadPost+0xa0>
lea    0xe87(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
lea    0xe88(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11bc <ReadPost+0x7c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <ReadPost+0xa0>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadPost>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
movl   $0x0,0xc(%rsp)
lea    0xea4(%rip),%rdi
call   1030 <getenv@plt>
lea    0xea7(%rip),%rsi
mov    %eax,%edi
call   1040 <strcasecmp@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    11bc <ReadPost+0x7c>
lea    0xe94(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe97(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %eax,%edi
call   1060 <sscanf@plt>
mov    0xc(%rsp),%esi
cmp    %ebp,%esi
jge    11bc <ReadPost+0x7c>
add    $0x1,%esi
mov    %esi,0xc(%rsp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
call   1050 <fgets@plt>
mov    0xc(%rsp),%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
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"
@.str.3 = [3 x i8] c"%d\00"
@stdin = global i32 0
define i32 @ReadPost(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
%7 = call i32 @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = call i64 @strcasecmp(i32 %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %26
11: ; preds = %2
%12 = call i32 @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @sscanf(i32 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = icmp sge i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %11
store i32 -1, i32* %3
br label %26
18: ; preds = %11
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
%21 = load i8*, i8** %4
%22 = load i32, i32* %6
%23 = load i32, i32* @stdin
%24 = call i32 @fgets(i8* %21, i32 %22, i32 %23)
%25 = load i32, i32* %6
store i32 %25, i32* %3
br label %26
26: ; preds = %18, %17, %10
%27 = load i32, i32* %3
ret i32 %27
}

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"
@.str.3 = [3 x i8] c"%d\00"
@stdin = global i32 0
define i32 @ReadPost(i8* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = tail call i32 @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = tail call i64 @strcasecmp(i32 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = tail call i32 @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @sscanf(i32 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, %1
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = add nsw i32 %11, 1
store i32 %14, i32* %3
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* %0, i32 %14, i32 %15)
%17 = load i32, i32* %3
br label %18
18: ; preds = %8, %2, %13
%19 = phi i32 [ %17, %13 ], [ -1, %2 ], [ -1, %8 ]
ret i32 %19
}