#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 fread(char *, int, int, int /*<<< orphan*/);
char *getenv(char *);
scalar_t__ rfx_alloc(int);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
char *swf_postread() {
  char *buf = NULL;
  int size = 0, sofar = 0, got;
  buf = getenv("CONTENT_TYPE");
  if ((!buf) || strcmp(buf, "application/x-www-form-urlencoded"))
    return NULL;
  buf = getenv("CONTENT_LENGTH");
  if (!buf)
    return NULL;
  size = atoi(buf);
  buf = (char *)rfx_alloc(size + 1);
  if (buf) {
    do {
      got = fread(buf + sofar, 1, size - sofar, stdin);
      sofar += got;
    } while (got && sofar < size);
    buf[sofar] = 0;
  }
  return buf;
}


x86 assembly (clang, -O0):
<swf_postread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe8b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a3 <swf_postread+0x53>
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11b0 <swf_postread+0x60>
movq   $0x0,-0x8(%rbp)
jmp    126d <swf_postread+0x11d>
lea    0xe78(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d8 <swf_postread+0x88>
movq   $0x0,-0x8(%rbp)
jmp    126d <swf_postread+0x11d>
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1060 <rfx_alloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1265 <swf_postread+0x115>
jmp    1203 <swf_postread+0xb3>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x14(%rbp),%edx
sub    -0x18(%rbp),%edx
mov    0x2dcd(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
je     124e <swf_postread+0xfe>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1203 <swf_postread+0xb3>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swf_postread>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     117d <swf_postread+0x2d>
lea    0xe9d(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     118f <swf_postread+0x3f>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe99(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     117d <swf_postread+0x2d>
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    %eax,%r15d
lea    0x1(%r15),%edi
call   1060 <rfx_alloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     1180 <swf_postread+0x30>
xor    %ebx,%ebx
mov    0x2e23(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
movslq %ebx,%rbx
lea    (%r14,%rbx,1),%rdi
mov    %r15d,%edx
sub    %ebx,%edx
mov    (%r12),%ecx
mov    $0x1,%esi
call   1040 <fread@plt>
add    %eax,%ebx
test   %eax,%eax
je     11f5 <swf_postread+0xa5>
cmp    %r15d,%ebx
jl     11d0 <swf_postread+0x80>
movslq %ebx,%rax
movb   $0x0,(%r14,%rax,1)
jmp    1180 <swf_postread+0x30>

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

LLVM IR (-O2):
@.str = [13 x i8] c"CONTENT_TYPE\00"
@.str.1 = [34 x i8] c"application/x-www-form-urlencoded\00"
@.str.2 = [15 x i8] c"CONTENT_LENGTH\00"
@stdin = global i32 0
define i8* @swf_postread() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %29, label %3
3: ; preds = %0
%4 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %29
6: ; preds = %3
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %29, label %9
9: ; preds = %6
%10 = tail call i32 @atoi(i8* %7)
%11 = add nsw i32 %10, 1
%12 = tail call i64 @rfx_alloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
%14 = icmp eq i64 %12, 0
br i1 %14, label %29, label %15
15: ; preds = %9, %15
%16 = phi i32 [ %22, %15 ], [ 0, %9 ]
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %13, i64 %17
%19 = sub nsw i32 %10, %16
%20 = load i32, i32* @stdin
%21 = tail call i32 @fread(i8* %18, i32 1, i32 %19, i32 %20)
%22 = add nsw i32 %21, %16
%23 = icmp ne i32 %21, 0
%24 = icmp slt i32 %22, %10
%25 = select i1 %23, i1 %24, i1 false
br i1 %25, label %15, label %26
26: ; preds = %15
%27 = sext i32 %22 to i64
%28 = getelementptr inbounds i8, i8* %13, i64 %27
store i8 0, i8* %28
br label %29
29: ; preds = %9, %26, %6, %0, %3
%30 = phi i8* [ null, %3 ], [ null, %0 ], [ null, %6 ], [ %13, %26 ], [ %13, %9 ]
ret i8* %30
}