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

/* Variables and functions */
int atoi(char *);
int calculateHeaderSize(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ *memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ realloc(char *, int);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int /*<<< orphan*/ stderr;
char *strstr(char *, char *);
void doprocessing(int sock) {
  char *pData = NULL, *pTempData = NULL;
  char recvBuffer[1024];
  int recvSize = 0, dataSize = 0, DataLength = 0;
  while (1) {
    memset(recvBuffer, '\0', sizeof(recvBuffer));
    recvSize = recv(sock, recvBuffer, sizeof(recvBuffer), 0);
    if (recvSize > 0) {
      char sContentLength[16];
      char *pch = NULL;
      int headerSize = 0, contentLength = 0;
      memset(sContentLength, '\0', sizeof(sContentLength));
      pch = strstr(recvBuffer, "Content-Length:");
      if (pch == NULL) {
        pTempData = (char *)malloc(DataLength);
        if (pTempData == NULL) {
          perror("allocate memory to temp data buffer");
          break;
        }
        if (memcpy(pTempData, pData, DataLength) == NULL) {
          perror("copy data buffer to temp data buffer");
          break;
        }
        pData = (char *)realloc((char *)pData, DataLength + recvSize + 1);
        if (pData == NULL) {
          perror("allocate memory to data buffer");
          break;
        }
        if (memcpy(pData, pTempData, DataLength) == NULL) {
          perror("copy temp data buffer to data buffer");
          break;
        }
        if (memcpy(pData + DataLength, recvBuffer, recvSize) == NULL) {
          perror("copy receive buffer to data buffer");
          break;
        }
        DataLength += recvSize;
        if (pTempData != NULL) {
          free(pTempData);
          pTempData = NULL;
        }
        dataSize += recvSize;
        if (dataSize >= contentLength) {
          break;
        } else {
          continue;
        }
      }
      sscanf(pch, "%*s%[^\r]\r\n", sContentLength);
      if (sContentLength == NULL) {
        perror("Parsing HTTP header failed!");
        break;
      }
      contentLength = atoi(sContentLength);
      headerSize = calculateHeaderSize(recvBuffer);
      dataSize = recvSize - headerSize;
      if (dataSize >= contentLength) {
        break;
      }
      pData = (char *)malloc(recvSize + 1);
      if (pData == NULL) {
        perror("allocate memory to data buffer");
        break;
      }
      DataLength = recvSize;
      if (memcpy(pData, recvBuffer, recvSize) == NULL) {
        perror("copy receive buffer to data buffer");
        break;
      }
    } else if (recvSize == 0) {
      fprintf(stderr,
              "Client is closing connection or the connection time out\n");
      close(sock);
      break;
    }
  }
  pData[DataLength] = '\0';
  if (pData != NULL) {
    free(pData);
    pData = NULL;
  }
  if (pTempData != NULL) {
    free(pTempData);
    pTempData = NULL;
  }
}


x86 assembly (clang, -O0):
<doprocessing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x424(%rbp)
movl   $0x0,-0x428(%rbp)
movl   $0x0,-0x42c(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
jle    14cf <doprocessing+0x2ff>
movq   $0x0,-0x448(%rbp)
movl   $0x0,-0x44c(%rbp)
movl   $0x0,-0x450(%rbp)
lea    -0x440(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    -0x420(%rbp),%rdi
lea    0xd78(%rip),%rsi
call   10f0 <strstr@plt>
mov    %rax,-0x448(%rbp)
cmpq   $0x0,-0x448(%rbp)
jne    13f8 <doprocessing+0x228>
mov    -0x42c(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12cd <doprocessing+0xfd>
lea    0xd4d(%rip),%rdi
call   10c0 <perror@plt>
jmp    1508 <doprocessing+0x338>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x42c(%rbp),%edx
call   1080 <memcpy@plt>
cmp    $0x0,%rax
jne    12fb <doprocessing+0x12b>
lea    0xd43(%rip),%rdi
call   10c0 <perror@plt>
jmp    1508 <doprocessing+0x338>
mov    -0x10(%rbp),%rdi
mov    -0x42c(%rbp),%esi
add    -0x424(%rbp),%esi
add    $0x1,%esi
call   10b0 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1333 <doprocessing+0x163>
lea    0xd30(%rip),%rdi
call   10c0 <perror@plt>
jmp    1508 <doprocessing+0x338>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x42c(%rbp),%edx
call   1080 <memcpy@plt>
cmp    $0x0,%rax
jne    1361 <doprocessing+0x191>
lea    0xd21(%rip),%rdi
call   10c0 <perror@plt>
jmp    1508 <doprocessing+0x338>
mov    -0x10(%rbp),%rdi
movslq -0x42c(%rbp),%rax
add    %rax,%rdi
lea    -0x420(%rbp),%rsi
mov    -0x424(%rbp),%edx
call   1080 <memcpy@plt>
cmp    $0x0,%rax
jne    139c <doprocessing+0x1cc>
lea    0xd0b(%rip),%rdi
call   10c0 <perror@plt>
jmp    1508 <doprocessing+0x338>
mov    -0x424(%rbp),%eax
add    -0x42c(%rbp),%eax
mov    %eax,-0x42c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     13ca <doprocessing+0x1fa>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x424(%rbp),%eax
add    -0x428(%rbp),%eax
mov    %eax,-0x428(%rbp)
mov    -0x428(%rbp),%eax
cmp    -0x450(%rbp),%eax
jl     13f3 <doprocessing+0x223>
jmp    1508 <doprocessing+0x338>
jmp    120c <doprocessing+0x3c>
mov    -0x448(%rbp),%rdi
lea    -0x440(%rbp),%rdx
lea    0xcb3(%rip),%rsi
call   10a0 <sscanf@plt>
lea    -0x440(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x450(%rbp)
lea    -0x420(%rbp),%rdi
call   10e0 <calculateHeaderSize@plt>
mov    %eax,-0x44c(%rbp)
mov    -0x424(%rbp),%eax
sub    -0x44c(%rbp),%eax
mov    %eax,-0x428(%rbp)
mov    -0x428(%rbp),%eax
cmp    -0x450(%rbp),%eax
jl     145f <doprocessing+0x28f>
jmp    1508 <doprocessing+0x338>
mov    -0x424(%rbp),%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    148d <doprocessing+0x2bd>
lea    0xbd6(%rip),%rdi
call   10c0 <perror@plt>
jmp    1508 <doprocessing+0x338>
mov    -0x424(%rbp),%eax
mov    %eax,-0x42c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    -0x424(%rbp),%edx
call   1080 <memcpy@plt>
cmp    $0x0,%rax
jne    14ca <doprocessing+0x2fa>
lea    0xbdd(%rip),%rdi
call   10c0 <perror@plt>
jmp    1508 <doprocessing+0x338>
jmp    1503 <doprocessing+0x333>
cmpl   $0x0,-0x424(%rbp)
jne    14fe <doprocessing+0x32e>
mov    0x2afd(%rip),%rax
mov    (%rax),%edi
lea    0xbdf(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
jmp    1508 <doprocessing+0x338>
jmp    1503 <doprocessing+0x333>
jmp    120c <doprocessing+0x3c>
mov    -0x10(%rbp),%rax
movslq -0x42c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpq   $0x0,-0x10(%rbp)
je     1533 <doprocessing+0x363>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     154f <doprocessing+0x37f>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doprocessing>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %edi,%ebp
xor    %r15d,%r15d
lea    0x20(%rsp),%rbx
xor    %r12d,%r12d
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %eax,%eax
jg     122b <doprocessing+0x5b>
jne    1200 <doprocessing+0x30>
jmp    136f <doprocessing+0x19f>
mov    %eax,%r14d
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
lea    0xdb7(%rip),%rsi
call   10f0 <strstr@plt>
test   %rax,%rax
je     12cc <doprocessing+0xfc>
mov    %r15,(%rsp)
mov    %r13,%r15
mov    %rax,%rdi
lea    0xe5c(%rip),%rsi
lea    0x10(%rsp),%r12
mov    %r12,%rdx
call   10a0 <sscanf@plt>
mov    %r12,%rdi
call   10d0 <atoi@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
call   10e0 <calculateHeaderSize@plt>
mov    %r14d,%r12d
sub    %eax,%r12d
cmp    %r13d,%r12d
jge    1392 <doprocessing+0x1c2>
mov    %r14d,%edi
add    $0x1,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     13c3 <doprocessing+0x1f3>
mov    %rax,%r13
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1080 <memcpy@plt>
test   %rax,%rax
mov    %r13,%r15
je     13d7 <doprocessing+0x207>
mov    %r14d,%r13d
jmp    1200 <doprocessing+0x30>
mov    %r13d,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     13ee <doprocessing+0x21e>
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1080 <memcpy@plt>
test   %rax,%rax
je     1403 <doprocessing+0x233>
lea    (%r14,%r13,1),%esi
add    $0x1,%esi
mov    %r15,%rdi
call   10b0 <realloc@plt>
test   %rax,%rax
je     1413 <doprocessing+0x243>
mov    %rax,%r15
mov    %rax,%rdi
mov    0x8(%rsp),%rsi
mov    %r13d,%edx
call   1080 <memcpy@plt>
test   %rax,%rax
mov    %r15,(%rsp)
je     1432 <doprocessing+0x262>
movslq %r13d,%rax
add    %rax,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1080 <memcpy@plt>
test   %rax,%rax
je     143e <doprocessing+0x26e>
add    %r14d,%r13d
mov    %r13,%r15
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    %r14d,%r12d
jns    1392 <doprocessing+0x1c2>
mov    %r15,%r13
mov    (%rsp),%r15
jmp    1200 <doprocessing+0x30>
mov    %r15,(%rsp)
mov    %r13,%r15
mov    0x2c63(%rip),%rax
mov    (%rax),%edi
lea    0xd45(%rip),%rsi
call   1070 <fprintf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %ebx,%ebx
movslq %r15d,%rax
mov    (%rsp),%rdi
movb   $0x0,(%rdi,%rax,1)
call   1030 <free@plt>
test   %rbx,%rbx
je     13b1 <doprocessing+0x1e1>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc8f(%rip),%rdi
call   10c0 <perror@plt>
xor    %eax,%eax
mov    %rax,(%rsp)
jmp    1392 <doprocessing+0x1c2>
mov    %r15,(%rsp)
lea    0xcbb(%rip),%rdi
call   10c0 <perror@plt>
xor    %ebx,%ebx
mov    %r14d,%r15d
jmp    1394 <doprocessing+0x1c4>
mov    %r15,(%rsp)
mov    %r13,%r15
lea    0xc14(%rip),%rdi
call   10c0 <perror@plt>
jmp    1392 <doprocessing+0x1c2>
mov    %r15,(%rsp)
mov    %r13,%r15
lea    0xc23(%rip),%rdi
jmp    1448 <doprocessing+0x278>
mov    %r13,%r15
lea    0xc3c(%rip),%rdi
call   10c0 <perror@plt>
xor    %eax,%eax
mov    %rax,(%rsp)
mov    0x8(%rsp),%rbx
jmp    1394 <doprocessing+0x1c4>
mov    %r13,%r15
lea    0xc3c(%rip),%rdi
jmp    1448 <doprocessing+0x278>
mov    %r13,%r15
lea    0xc55(%rip),%rdi
call   10c0 <perror@plt>
mov    0x8(%rsp),%rbx
jmp    1394 <doprocessing+0x1c4>

LLVM IR (-O0):
@.str = [16 x i8] c"Content-Length:\00"
@.str.1 = [36 x i8] c"allocate memory to temp data buffer\00"
@.str.2 = [37 x i8] c"copy data buffer to temp data buffer\00"
@.str.3 = [31 x i8] c"allocate memory to data buffer\00"
@.str.4 = [37 x i8] c"copy temp data buffer to data buffer\00"
@.str.5 = [35 x i8] c"copy receive buffer to data buffer\00"
@.str.6 = [11 x i8] c"%*s%[^\0D]\0D\0A\00"
@stderr = global i32 0
@.str.7 = [57 x i8] c"Client is closing connection or the connection time out\0A\00"
define void @doprocessing(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [16 x i8]
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %2
store i8* null, i8** %3
store i8* null, i8** %4
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %13
13: ; preds = %1, %92, %136
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i8 signext 0, i32 1024)
%16 = load i32, i32* %2
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%18 = call i32 @recv(i32 %16, i8* %17, i32 1024, i32 0)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %127
21: ; preds = %13
store i8* null, i8** %10
store i32 0, i32* %11
store i32 0, i32* %12
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i8 signext 0, i32 16)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%25 = call i8* @strstr(i8* %24, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %25, i8** %10
%26 = load i8*, i8** %10
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %93
28: ; preds = %21
%29 = load i32, i32* %8
%30 = call i64 @malloc(i32 %29)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %4
%32 = load i8*, i8** %4
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %137
36: ; preds = %28
%37 = load i8*, i8** %4
%38 = load i8*, i8** %3
%39 = load i32, i32* %8
%40 = call i32* @memcpy(i8* %37, i8* %38, i32 %39)
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %137
44: ; preds = %36
%45 = load i8*, i8** %3
%46 = load i32, i32* %8
%47 = load i32, i32* %6
%48 = add nsw i32 %46, %47
%49 = add nsw i32 %48, 1
%50 = call i64 @realloc(i8* %45, i32 %49)
%51 = inttoptr i64 %50 to i8*
store i8* %51, i8** %3
%52 = load i8*, i8** %3
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %56
54: ; preds = %44
%55 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %137
56: ; preds = %44
%57 = load i8*, i8** %3
%58 = load i8*, i8** %4
%59 = load i32, i32* %8
%60 = call i32* @memcpy(i8* %57, i8* %58, i32 %59)
%61 = icmp eq i32* %60, null
br i1 %61, label %62, label %64
62: ; preds = %56
%63 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %137
64: ; preds = %56
%65 = load i8*, i8** %3
%66 = load i32, i32* %8
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%70 = load i32, i32* %6
%71 = call i32* @memcpy(i8* %68, i8* %69, i32 %70)
%72 = icmp eq i32* %71, null
br i1 %72, label %73, label %75
73: ; preds = %64
%74 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %137
75: ; preds = %64
%76 = load i32, i32* %6
%77 = load i32, i32* %8
%78 = add nsw i32 %77, %76
store i32 %78, i32* %8
%79 = load i8*, i8** %4
%80 = icmp ne i8* %79, null
br i1 %80, label %81, label %84
81: ; preds = %75
%82 = load i8*, i8** %4
%83 = call i32 @free(i8* %82)
store i8* null, i8** %4
br label %84
84: ; preds = %81, %75
%85 = load i32, i32* %6
%86 = load i32, i32* %7
%87 = add nsw i32 %86, %85
store i32 %87, i32* %7
%88 = load i32, i32* %7
%89 = load i32, i32* %12
%90 = icmp sge i32 %88, %89
br i1 %90, label %91, label %92
91: ; preds = %84
br label %137
92: ; preds = %84
br label %13
93: ; preds = %21
%94 = load i8*, i8** %10
%95 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%96 = call i32 @sscanf(i8* %94, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %95)
%97 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%98 = call i32 @atoi(i8* %97)
store i32 %98, i32* %12
%99 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%100 = call i32 @calculateHeaderSize(i8* %99)
store i32 %100, i32* %11
%101 = load i32, i32* %6
%102 = load i32, i32* %11
%103 = sub nsw i32 %101, %102
store i32 %103, i32* %7
%104 = load i32, i32* %7
%105 = load i32, i32* %12
%106 = icmp sge i32 %104, %105
br i1 %106, label %107, label %108
107: ; preds = %93
br label %137
108: ; preds = %93
%109 = load i32, i32* %6
%110 = add nsw i32 %109, 1
%111 = call i64 @malloc(i32 %110)
%112 = inttoptr i64 %111 to i8*
store i8* %112, i8** %3
%113 = load i8*, i8** %3
%114 = icmp eq i8* %113, null
br i1 %114, label %115, label %117
115: ; preds = %108
%116 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %137
117: ; preds = %108
%118 = load i32, i32* %6
store i32 %118, i32* %8
%119 = load i8*, i8** %3
%120 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%121 = load i32, i32* %6
%122 = call i32* @memcpy(i8* %119, i8* %120, i32 %121)
%123 = icmp eq i32* %122, null
br i1 %123, label %124, label %126
124: ; preds = %117
%125 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %137
126: ; preds = %117
br label %136
127: ; preds = %13
%128 = load i32, i32* %6
%129 = icmp eq i32 %128, 0
br i1 %129, label %130, label %135
130: ; preds = %127
%131 = load i32, i32* @stderr
%132 = call i32 @fprintf(i32 %131, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.7, i64 0, i64 0))
%133 = load i32, i32* %2
%134 = call i32 @close(i32 %133)
br label %137
135: ; preds = %127
br label %136
136: ; preds = %135, %126
br label %13
137: ; preds = %130, %124, %115, %107, %91, %73, %62, %54, %42, %34
%138 = load i8*, i8** %3
%139 = load i32, i32* %8
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds i8, i8* %138, i64 %140
store i8 0, i8* %141
%142 = load i8*, i8** %3
%143 = icmp ne i8* %142, null
br i1 %143, label %144, label %147
144: ; preds = %137
%145 = load i8*, i8** %3
%146 = call i32 @free(i8* %145)
store i8* null, i8** %3
br label %147
147: ; preds = %144, %137
%148 = load i8*, i8** %4
%149 = icmp ne i8* %148, null
br i1 %149, label %150, label %153
150: ; preds = %147
%151 = load i8*, i8** %4
%152 = call i32 @free(i8* %151)
store i8* null, i8** %4
br label %153
153: ; preds = %150, %147
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"Content-Length:\00"
@.str.1 = [36 x i8] c"allocate memory to temp data buffer\00"
@.str.2 = [37 x i8] c"copy data buffer to temp data buffer\00"
@.str.3 = [31 x i8] c"allocate memory to data buffer\00"
@.str.4 = [37 x i8] c"copy temp data buffer to data buffer\00"
@.str.5 = [35 x i8] c"copy receive buffer to data buffer\00"
@.str.6 = [11 x i8] c"%*s%[^\0D]\0D\0A\00"
@stderr = global i32 0
@.str.7 = [57 x i8] c"Client is closing connection or the connection time out\0A\00"
define void @doprocessing(i32 %0) {
%2 = alloca [1024 x i8]
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
br label %6
6: ; preds = %86, %1
%7 = phi i8* [ null, %1 ], [ %87, %86 ]
%8 = phi i32 [ 0, %1 ], [ %88, %86 ]
%9 = phi i32 [ 0, %1 ], [ %89, %86 ]
br label %10
10: ; preds = %6, %90
%11 = call i32 @memset(i8* %4, i8 signext 0, i32 1024)
%12 = call i32 @recv(i32 %0, i8* %4, i32 1024, i32 0)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %90
14: ; preds = %10
%15 = call i32 @memset(i8* %5, i8 signext 0, i32 16)
%16 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %59
18: ; preds = %14
%19 = call i64 @malloc(i32 %9)
%20 = inttoptr i64 %19 to i8*
%21 = icmp eq i64 %19, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %81
24: ; preds = %18
%25 = call i32* @memcpy(i8* %20, i8* %7, i32 %9)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = inttoptr i64 %19 to i8*
%29 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %81
30: ; preds = %24
%31 = add nsw i32 %12, %9
%32 = add nsw i32 %31, 1
%33 = call i64 @realloc(i8* %7, i32 %32)
%34 = inttoptr i64 %33 to i8*
%35 = icmp eq i64 %33, 0
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = inttoptr i64 %19 to i8*
%38 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %81
39: ; preds = %30
%40 = call i32* @memcpy(i8* %34, i8* %20, i32 %9)
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = inttoptr i64 %19 to i8*
%44 = inttoptr i64 %33 to i8*
%45 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %81
46: ; preds = %39
%47 = sext i32 %9 to i64
%48 = getelementptr inbounds i8, i8* %34, i64 %47
%49 = call i32* @memcpy(i8* %48, i8* %4, i32 %12)
%50 = icmp eq i32* %49, null
br i1 %50, label %51, label %55
51: ; preds = %46
%52 = inttoptr i64 %19 to i8*
%53 = inttoptr i64 %33 to i8*
%54 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %81
55: ; preds = %46
%56 = call i32 @free(i8* %20)
%57 = add nsw i32 %12, %8
%58 = icmp sgt i32 %57, -1
br i1 %58, label %79, label %85
59: ; preds = %14
%60 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%61 = call i32 @atoi(i8* %5)
%62 = call i32 @calculateHeaderSize(i8* %4)
%63 = sub nsw i32 %12, %62
%64 = icmp slt i32 %63, %61
br i1 %64, label %65, label %81
65: ; preds = %59
%66 = add nuw nsw i32 %12, 1
%67 = call i64 @malloc(i32 %66)
%68 = inttoptr i64 %67 to i8*
%69 = icmp eq i64 %67, 0
br i1 %69, label %70, label %72
70: ; preds = %65
%71 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %81
72: ; preds = %65
%73 = call i32* @memcpy(i8* %68, i8* %4, i32 %12)
%74 = icmp eq i32* %73, null
br i1 %74, label %76, label %75
75: ; preds = %72
br label %86
76: ; preds = %72
%77 = inttoptr i64 %67 to i8*
%78 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %81
79: ; preds = %55
%80 = inttoptr i64 %33 to i8*
br label %81
81: ; preds = %59, %79, %22, %27, %36, %42, %51, %70, %76
%82 = phi i8* [ %77, %76 ], [ null, %70 ], [ %53, %51 ], [ %44, %42 ], [ null, %36 ], [ %7, %27 ], [ %7, %22 ], [ %80, %79 ], [ %7, %59 ]
%83 = phi i8* [ null, %76 ], [ null, %70 ], [ %52, %51 ], [ %43, %42 ], [ %37, %36 ], [ %28, %27 ], [ null, %22 ], [ null, %79 ], [ null, %59 ]
%84 = phi i32 [ %12, %76 ], [ %9, %70 ], [ %9, %51 ], [ %9, %42 ], [ %9, %36 ], [ %9, %27 ], [ %9, %22 ], [ %31, %79 ], [ %9, %59 ]
br label %96
85: ; preds = %55
br label %86
86: ; preds = %85, %75
%87 = phi i8* [ %68, %75 ], [ %34, %85 ]
%88 = phi i32 [ %63, %75 ], [ %57, %85 ]
%89 = phi i32 [ %12, %75 ], [ %31, %85 ]
br label %6
90: ; preds = %10
%91 = icmp eq i32 %12, 0
br i1 %91, label %92, label %10
92: ; preds = %90
%93 = load i32, i32* @stderr
%94 = call i32 @fprintf(i32 %93, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.7, i64 0, i64 0))
%95 = call i32 @close(i32 %0)
br label %96
96: ; preds = %81, %92
%97 = phi i8* [ %7, %92 ], [ %82, %81 ]
%98 = phi i8* [ null, %92 ], [ %83, %81 ]
%99 = phi i32 [ %9, %92 ], [ %84, %81 ]
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds i8, i8* %97, i64 %100
store i8 0, i8* %101
%102 = call i32 @free(i8* %97)
%103 = icmp eq i8* %98, null
br i1 %103, label %106, label %104
104: ; preds = %96
%105 = call i32 @free(i8* %98)
br label %106
106: ; preds = %104, %96
ret void
}